comments in common.js [DONOTPULL]
This commit is contained in:
parent
0baa253d2c
commit
4f3feb9504
1 changed files with 44 additions and 46 deletions
|
@ -4,6 +4,7 @@ const nmDt = require("../Data/aliases.json");
|
||||||
const weaponActualName = nmDt.weaponActualName;
|
const weaponActualName = nmDt.weaponActualName;
|
||||||
const weaponAlliasName = nmDt.weaponAlliasName;
|
const weaponAlliasName = nmDt.weaponAlliasName;
|
||||||
Object.defineProperty(String.prototype, "Simplify", {
|
Object.defineProperty(String.prototype, "Simplify", {
|
||||||
|
// Function to remove all characters except 0-9 and a-z
|
||||||
value: function Simplify() {
|
value: function Simplify() {
|
||||||
return this.toLowerCase().replace(/[^0-9a-z]/g, "");
|
return this.toLowerCase().replace(/[^0-9a-z]/g, "");
|
||||||
},
|
},
|
||||||
|
@ -12,33 +13,30 @@ Object.defineProperty(String.prototype, "Simplify", {
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(Number.prototype, "IsPositive", {
|
Object.defineProperty(Number.prototype, "IsPositive", {
|
||||||
|
// Function to check the number is positive or not
|
||||||
value: function IsPositive() {
|
value: function IsPositive() {
|
||||||
if (this > 0) {
|
if (this > 0) return true;
|
||||||
return true;
|
else return false;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
writable: true,
|
writable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(Number.prototype, "IsNegative", {
|
Object.defineProperty(Number.prototype, "IsNegative", {
|
||||||
|
// Function to check the number is negative or not
|
||||||
value: function IsNegative() {
|
value: function IsNegative() {
|
||||||
if (this < 0) {
|
if (this < 0) return true;
|
||||||
return true;
|
else return false;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
writable: true,
|
writable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(Number.prototype, "ToBool", {
|
Object.defineProperty(Number.prototype, "ToBool", {
|
||||||
|
// Function to check the number is one or not
|
||||||
value: function ToBool() {
|
value: function ToBool() {
|
||||||
if (this == 1) {
|
if (this == 1) return true;
|
||||||
return true;
|
else return false;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
writable: true,
|
writable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
@ -49,15 +47,19 @@ Object.defineProperty(Number.prototype, "PlusHL", {
|
||||||
if (this.toString()[0] == "-") {
|
if (this.toString()[0] == "-") {
|
||||||
return parseFloat(this.toFixed(2)).toString();
|
return parseFloat(this.toFixed(2)).toString();
|
||||||
}
|
}
|
||||||
return "+" + parseFloat(this.toFixed(2)).toString();
|
return `+${parseFloat(this.toFixed(2)).toString()}`;
|
||||||
},
|
},
|
||||||
writable: true,
|
writable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Function to fix the input statement */
|
||||||
function inpFixer(inpmsg) {
|
function inpFixer(inpmsg) {
|
||||||
const parts = partExtracter(inpmsg);
|
const parts = partExtracter(inpmsg);
|
||||||
|
// parts will be an array
|
||||||
|
//eg: ["fennec", "akimbo, mono"]
|
||||||
nmDt.attachmentAlliasName[0].map((x, i) =>
|
nmDt.attachmentAlliasName[0].map((x, i) =>
|
||||||
|
// x is the content of each index, i is the number of each index
|
||||||
x.map(y => {
|
x.map(y => {
|
||||||
if (parts[0].startsWith(y + " ") || parts[0].endsWith(" " + y)) {
|
if (parts[0].startsWith(y + " ") || parts[0].endsWith(" " + y)) {
|
||||||
inpmsg =
|
inpmsg =
|
||||||
|
@ -67,22 +69,28 @@ function inpFixer(inpmsg) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
// so it fking only fix akimbo and stopping power wtf
|
||||||
return inpmsg;
|
return inpmsg;
|
||||||
}
|
}
|
||||||
|
// Function to extract the attachments from the input statement
|
||||||
function partExtracter(inpmsg) {
|
function partExtracter(inpmsg) {
|
||||||
if (inpmsg.includes(" + ")) {
|
if (inpmsg.includes(" + ")) {
|
||||||
|
// If the input statement has multiple attachments joined by "+", split them and output them as an array of strings [0] is the weapon name, [1] is the attachments
|
||||||
|
// Eg: "M4A1 + Silencer + Flashlight" -> ["M4A1", "Silencer + Flashlight"]
|
||||||
const out = inpmsg
|
const out = inpmsg
|
||||||
.split(" + ")
|
.split(" + ")
|
||||||
.map(x => x.split("+"))
|
.map(x => x.split("+"))
|
||||||
.flat();
|
.flat();
|
||||||
return [out.shift(), out.join(", ")];
|
return [out.shift(), out.join(", ")];
|
||||||
}
|
}
|
||||||
|
// If there is only one attachment, output it as an array of strings [0] is the weapon name, [1] is the attachment
|
||||||
|
// Eg: "M4A1 with Flashlight" -> ["M4A1", "Flashlight"]
|
||||||
return inpmsg.split(" with ");
|
return inpmsg.split(" with ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasAttachments(inpmsg) {
|
function hasAttachments(inpmsg) {
|
||||||
inpmsg = inpFixer(inpmsg);
|
inpmsg = inpFixer(inpmsg);
|
||||||
|
// If
|
||||||
if (
|
if (
|
||||||
inpmsg.split(" with ").filter(x => x.Simplify()).length > 1 ||
|
inpmsg.split(" with ").filter(x => x.Simplify()).length > 1 ||
|
||||||
inpmsg.split(" + ").filter(x => x.Simplify()).length > 1
|
inpmsg.split(" + ").filter(x => x.Simplify()).length > 1
|
||||||
|
@ -100,8 +108,8 @@ function weaponIdentifier(inpmsg) {
|
||||||
const inpWeaponName = isolator(inpmsg)[0];
|
const inpWeaponName = isolator(inpmsg)[0];
|
||||||
if (inpWeaponName.length < 2) {
|
if (inpWeaponName.length < 2) {
|
||||||
return inpmsg.trim().length
|
return inpmsg.trim().length
|
||||||
? "The name `" + inpmsg.trim() + "` is too short."
|
? `The name ${inpmsg.trim()} is too short.`
|
||||||
: "Empty weapon name";
|
: "There isn't any weapon name.";
|
||||||
}
|
}
|
||||||
let probableWeapons = [];
|
let probableWeapons = [];
|
||||||
for (let i = 0; i < data.cguns.length; i++) {
|
for (let i = 0; i < data.cguns.length; i++) {
|
||||||
|
@ -136,17 +144,14 @@ function weaponIdentifier(inpmsg) {
|
||||||
return JSON.parse(JSON.stringify(data.cguns[probableWeapons[0]]));
|
return JSON.parse(JSON.stringify(data.cguns[probableWeapons[0]]));
|
||||||
}
|
}
|
||||||
if (probableWeapons.length > 1) {
|
if (probableWeapons.length > 1) {
|
||||||
return (
|
return `Did you mean ${probableWeapons
|
||||||
"Did you mean `" +
|
|
||||||
probableWeapons
|
|
||||||
.map(x => data.cguns[x].gunname)
|
.map(x => data.cguns[x].gunname)
|
||||||
.reduce((out, x, i) =>
|
.reduce((out, x, i) =>
|
||||||
[out, x].join(i === probableWeapons.length - 1 ? "` or `" : "`, `")
|
[out, x].join(i === probableWeapons.length - 1 ? "` or `" : "`, `")
|
||||||
) +
|
)}
|
||||||
"`?"
|
?`;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return "Couldn't identify the weapon: `" + '"' + inpWeaponName + '"`';
|
return `Couldn't identify the weapon: "${inpWeaponName}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachmentsIdentifier(inpmsg, attachmentsData, inpStats) {
|
function attachmentsIdentifier(inpmsg, attachmentsData, inpStats) {
|
||||||
|
@ -163,12 +168,10 @@ function attachmentsIdentifier(inpmsg, attachmentsData, inpStats) {
|
||||||
errors = [],
|
errors = [],
|
||||||
unidentifined = [];
|
unidentifined = [];
|
||||||
|
|
||||||
if (inputAttachmentsNames.length == 00) {
|
if (inputAttachmentsNames.length == 0)
|
||||||
errorMsgs += "\nAttachments are missing!\n";
|
errorMsgs += "\nAttachments are missing!\n";
|
||||||
}
|
|
||||||
if (inputAttachmentsNames.length >= 10) {
|
if (inputAttachmentsNames.length >= 10) return "Cocaineeeeee";
|
||||||
return "Cocaineeeeee";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can directly use args[] to return, no need for isolator, partExtractor, inpFixer
|
// Can directly use args[] to return, no need for isolator, partExtractor, inpFixer
|
||||||
const splitAttachmentsDataName = [],
|
const splitAttachmentsDataName = [],
|
||||||
|
@ -346,15 +349,11 @@ function attachmentsIdentifier(inpmsg, attachmentsData, inpStats) {
|
||||||
[out, x].join(i === a.length - 1 ? " and " : ", ")
|
[out, x].join(i === a.length - 1 ? " and " : ", ")
|
||||||
)
|
)
|
||||||
: "";
|
: "";
|
||||||
errorMsgs += errors.length
|
errorMsgs += errors.length ? `\nDid you mean ${errors.join(";\n")}?\n` : "";
|
||||||
? "\nDid you mean " + errors.join(";\n") + "?\n"
|
|
||||||
: "";
|
|
||||||
errorMsgs += unidentifined.length
|
errorMsgs += unidentifined.length
|
||||||
? "\nCouldn't identify the attachment" +
|
? `\nCouldn't identify the attachment(${
|
||||||
(unidentifined.length === 1 ? "" : "s") +
|
unidentifined.length === 1 ? "" : "s"
|
||||||
': `"' +
|
}): \`"${unidentifined.join('"`, `"')}"\`\n`
|
||||||
unidentifined.join('"`, `"') +
|
|
||||||
'"`\n'
|
|
||||||
: "";
|
: "";
|
||||||
errorMsgs +=
|
errorMsgs +=
|
||||||
outAttachments.length > 5 ? "\nCan't equip more than 5 attachments!\n" : "";
|
outAttachments.length > 5 ? "\nCan't equip more than 5 attachments!\n" : "";
|
||||||
|
@ -703,7 +702,7 @@ function attachmentHandler(currEffects, currStats) {
|
||||||
} else if (currEffects[44] == -1) {
|
} else if (currEffects[44] == -1) {
|
||||||
atr.push("Lower Penetraion Damage");
|
atr.push("Lower Penetraion Damage");
|
||||||
}
|
}
|
||||||
posGood2(45, "Round" + (currEffects[45] - 1 ? "s" : "") + " in Reserve");
|
posGood2(45, `Round ${currEffects[45] - 1 ? "s" : ""} in Reserve`);
|
||||||
|
|
||||||
function posGood1(i, ext) {
|
function posGood1(i, ext) {
|
||||||
if (currEffects[i].IsPositive()) {
|
if (currEffects[i].IsPositive()) {
|
||||||
|
@ -742,26 +741,26 @@ function attachmentHandler(currEffects, currStats) {
|
||||||
atr.push(ext);
|
atr.push(ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Return the attributes when there is and use algorithms to join them
|
||||||
return [
|
return [
|
||||||
pos.length
|
pos.length
|
||||||
? {
|
? {
|
||||||
name: "**Positives:**",
|
name: "**Positives:**",
|
||||||
value: "```ini\n[" + pos.join("]\n[") + "]\n```",
|
value: `\`\`\`ini\n[${pos.join("]\n[")}]\n\`\`\``,
|
||||||
inline: true,
|
inline: true,
|
||||||
}
|
}
|
||||||
: 0,
|
: 0,
|
||||||
neg.length
|
neg.length
|
||||||
? {
|
? {
|
||||||
name: "**Negatives:**",
|
name: "**Negatives:**",
|
||||||
value: "```css\n[" + neg.join("]\n[") + "]\n```",
|
value: `\`\`\`css\n[${neg.join("]\n[")}]\n\`\`\``,
|
||||||
inline: true,
|
inline: true,
|
||||||
}
|
}
|
||||||
: 0,
|
: 0,
|
||||||
atr.length
|
atr.length
|
||||||
? {
|
? {
|
||||||
name: "**Attributes:**",
|
name: "**Attributes:**",
|
||||||
value: "```fix\n[" + atr.join("]\n[") + "]\n```",
|
value: `\`\`\`fix\n[${atr.join("]\n[")}]\n\`\`\``,
|
||||||
}
|
}
|
||||||
: 0,
|
: 0,
|
||||||
].filter(x => x);
|
].filter(x => x);
|
||||||
|
@ -784,8 +783,7 @@ function totaler(inpAttachments) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeError() {
|
function makeError() {
|
||||||
let m;
|
undefined.split("L");
|
||||||
m.split("L");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue