nyx

The first CODM discrod bot -- cath.exe Template
git clone https://codeberg.org/night0721/nyx
Log | Files | Refs | LICENSE

damage.js (3137B)


      1 const common = require("../../util/functions/common");
      2 let currGun = {},
      3   currStats = [],
      4   currAttachments = {},
      5   currDRM = {},
      6   totalEffects = [],
      7   interpretion = "",
      8   hasError = false;
      9 const errMsg = "*Generic placeholder error message*";
     10 
     11 module.exports = {
     12   name: "damage",
     13   description: "Check gun damage",
     14   usage: "(Gun)",
     15   category: "CODM",
     16   options: [
     17     {
     18       type: 3,
     19       name: "gun",
     20       description: "Gun name",
     21       required: true,
     22     },
     23   ],
     24   run: async (client, interaction, args) => {
     25     const repEmb = dmg(args[0].replace("\n", " "));
     26     if (hasError) {
     27       interaction.followUp({ embeds: [repEmb] });
     28     } else {
     29       interaction.followUp({ embeds: [repEmb] });
     30     }
     31   },
     32 };
     33 
     34 function dmg(inpmsg) {
     35   currGun = common.weaponIdentifier(inpmsg);
     36   if (typeof currGun == "string") {
     37     hasError = true;
     38     return currGun;
     39   }
     40   currDRM = currGun.drm[0];
     41   currStats = currGun.stats;
     42   currAttachments = common.attachmentsIdentifier(inpmsg, currGun);
     43   if (typeof currAttachments == "string") {
     44     hasError = true;
     45     return currAttachments;
     46   }
     47   if (currAttachments.length) {
     48     totalEffects = common.totaler(currAttachments);
     49     currDRM = currGun.drm[totalEffects[37]];
     50     currDRM.range = currDRM.range.map(
     51       x => (x * (totalEffects[13] + 100)) / 100
     52     );
     53     currStats = common.updateStatswithEffects(totalEffects, currStats);
     54   }
     55   const mn = [
     56       "Head",
     57       "Neck",
     58       "Upper Chest",
     59       "Lower Chest",
     60       "Shoulders",
     61       "Upper Arms",
     62       "Lower Arms",
     63       "Stomach",
     64       "Belly Button",
     65       "Crotch",
     66       "Thighs",
     67       "Calf Muscles",
     68       "Feet",
     69     ],
     70     m1 = currDRM.bodymultiplier,
     71     m2 = [...new Set(m1)], // [1.2, 1, 0.9]
     72     m3 = m1.map(x => m2.indexOf(x)), // [0, 1, 1, 1, 1, 1, 2, 2, 2]
     73     m4 = m2
     74       .map(x =>
     75         m3
     76           .map((y, i) => {
     77             if (x === m2[y]) {
     78               return mn[i];
     79             }
     80           })
     81           .filter(y => y)
     82       )
     83       .map(x =>
     84         x.length === m1.length
     85           ? ["All"]
     86           : x.length === m1.length - 1
     87           ? ["Others"]
     88           : x
     89       );
     90   interpretion = currGun.gunname + common.interpretioner(currAttachments);
     91   return {
     92     title: "**" + interpretion + "**",
     93     color: 4849497,
     94     fields: m4.map((x, i) => {
     95       return {
     96         name: x.join(", ") + ":",
     97         value: common.damageHandler(
     98           currDRM.damage,
     99           currDRM.range,
    100           m2[i],
    101           100,
    102           60000 / currStats[5],
    103           currStats[7],
    104           currStats[6],
    105           currStats[0]
    106         ),
    107       };
    108     }),
    109     footer: {
    110       text: "All the stats courtesy of Project Lighthouse",
    111       icon_url:
    112         "https://media.discordapp.net/attachments/735590814662656102/806960573753327657/cc.png?width=638&height=638",
    113     },
    114   };
    115 }
    116 // console.log(dmg("47 + mono"));
    117 /* console.log(dmg("47"));
    118 console.log(dmg("striker + choke"));
    119 console.log(dmg("striker + choke"));
    120 console.log(dmg("striker"));
    121 common.makeError();*/