shiro-calculator/index.js
koneko 3c29f98027
All checks were successful
Deploy bot / build-and-deploy (push) Successful in 14s
commit
2025-04-29 12:22:45 +02:00

368 lines
10 KiB
JavaScript

const {
Client,
Events,
GatewayIntentBits,
EmbedBuilder,
} = require("discord.js");
const token = process.env.TOKEN;
const prefix = process.env.PREFIX;
// Create a new client instance
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, (readyClient) => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
client.on(Events.MessageCreate, (message) => {
if (message.author.bot) return;
if (message.content.indexOf(prefix) !== 0) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command == "bonus") {
if (!args[0])
return message.channel.send(
"Not enough arguments, consult <<help."
);
// sum all args
try {
args.forEach((arg) => {
if (isNaN(parseInt(arg)))
return message.channel.send(
"Please provide atleast 1 number."
);
arg = parseInt(arg);
});
} catch (e) {
return message.channel.send("Please provide 1 number.");
}
let sum = 0;
args.forEach((arg) => {
if (arg > 2000) arg = 2000;
sum += parseInt(arg);
});
message.channel.send(
`Will reach ${sum}, ${Math.ceil(sum * 1.4)} with bonus.`
);
}
if (command == "ev") {
return message.channel.send("not implemented.");
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let ab1 = parseInt(args[0]);
let ab2 = parseInt(args[1]);
let ab1ratio = 1.063;
let ab2ratio = 0.937;
message.channel.send(
`Aiming for ${ab1 * ab1ratio} and ${ab2 * ab2ratio}`
);
}
if (command == "lt") {
return message.channel.send("not implemented.");
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let ab1 = parseInt(args[0]);
let ab2 = parseInt(args[1]);
let ab1ratio = 1.101;
let ab2ratio = 0.899;
message.channel.send(
`Aiming for ${ab1 * ab1ratio} and ${ab2 * ab2ratio}`
);
}
if (command == "cb") {
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let cb = parseInt(args[0]);
let ups = parseInt(args[1]);
let initialspeed = null;
if (args[2]) {
initialspeed = parseInt(args[2]);
initialspeed = 30000 - initialspeed;
let t = Math.ceil(initialspeed / 1200);
console.log(t);
ups = ups - t;
}
console.log(ups);
message.channel.send(`Should be ${cb + ups * 192}.`);
}
if (command == "ms") {
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let cb = parseInt(args[0]);
let ups = parseInt(args[1]);
let initialspeed = null;
if (args[2]) {
initialspeed = parseInt(args[2]);
initialspeed = 30000 - initialspeed;
let t = Math.ceil(initialspeed / 1200);
console.log(t);
ups = ups - t;
}
console.log(ups);
message.channel.send(`Should be ${cb + ups * 99}.`);
}
if (command == "res") {
for (let i = 0; i < args.length; i++) {
if (args[i] == "|") continue;
args[i] = parseInt(args[i]);
}
let type;
if (args[4] == "|") type = 4;
else if (args[3] == "|") type = 3;
else return message.channel.send("Please provide 3 or 4 resistances.");
let resistances = [
args[0],
args[1],
args[2],
type == 4 ? args[3] : null,
];
let mainStat = type == 4 ? args[5] : args[4];
let upgrades = type == 4 ? args[6] : args[5];
let substat = type == 4 ? args[7] : args[6];
upgrades = upgrades - 1;
if (!mainStat || !upgrades)
return message.channel.send("Please atleast 2 stats.");
if (!substat) substat = 0;
let resUpgrades = 0;
resistances.forEach((res) => {
if (res == null) return;
if (res > 29)
return message.channel.send(
"Please provide a number between 0 and 29. LMAO"
);
if (res < 29) {
if (res < 0) {
let underzero = Math.abs(res);
if (underzero < 13) {
resUpgrades += 23 + Math.abs(res);
} else {
if (underzero == 13 || underzero == 14) {
resUpgrades += 23 + 13;
}
if (underzero == 15 || underzero == 16) {
resUpgrades += 23 + 13 + 1;
}
if (underzero == 17 || underzero == 18) {
resUpgrades += 23 + 13 + 2;
}
if (
underzero == 19 ||
underzero == 20 ||
underzero == 22
) {
resUpgrades += 23 + 13 + 3;
}
if (underzero == 21 || underzero == 23) {
resUpgrades += 23 + 13 + 4;
}
if (underzero > 23) {
resUpgrades += 29 - underzero;
}
}
// from 1% to 23% takes 17-18 ups
// from 23% to 29% takes 6 ups
// from 1% to 29% takes 23 ups
// 23 + Math.abs(res)
console.log(
"gotta spend " +
(23 + Math.abs(res)) +
" upgrades to max res for negative"
);
} else {
//14 skips 15 to 16
//15 skips 16 to 17
//17 skips 18 to 19
//19 skips 20 to 21
//21 skips to 24
// list: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,23
// possible if 15,17,19,21,24
//amount of numbers: 18
// skipped 5 upgrades
//example 4
// 5,6,7,8,9,10,11,12,13,14,16,18,20,23
// count: 14
// to 29% + 6, result 20
if (res < 14) {
let am = 14 - res;
resUpgrades += am + 4 + 6;
console.log(
"gotta spend " +
(am + 4 + 6) +
" upgrades to max res for positive, am: " +
am
);
} else {
if (res == 14) {
resUpgrades += 4 + 6;
}
if (res == 15 || res == 16) {
resUpgrades += 3 + 6;
}
if (res == 17 || res == 18) {
resUpgrades += 2 + 6;
}
if (res == 19 || res == 20 || res == 22) {
resUpgrades += 1 + 6;
}
if (res == 21 || res == 23) {
resUpgrades += 6;
}
if (res > 23) {
resUpgrades += 29 - res;
}
console.log(
"gotta spend " +
resUpgrades +
" upgrades to max res for positive, res: " +
res
);
}
}
}
});
upgrades -= resUpgrades;
mainStat += upgrades;
let over = 0;
if (mainStat > 999) {
let over = mainStat - 999;
mainStat -= over;
substat += over;
}
message.channel.send(
`With ${resUpgrades} upgrades spent in resistances, your piece will reach ${
mainStat + substat
}, or ${Math.ceil(mainStat * 1.4 + substat * 1.4)} with set bonus!`
);
}
if (command == "cat") {
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let boost = parseInt(args[0]);
let levels = parseInt(args[1]);
let extraboost = Math.floor(levels / 3 - 3);
let players = Math.floor(levels / 29) + 1;
if (players > 4) players = 4;
message.channel.send(
`Should be atleast ${
boost + extraboost
}. Will boost atleast ${players} players.`
);
}
if (command == "bident") {
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let damage = parseInt(args[0]);
let ups = parseInt(args[1]);
let initialcharge = null;
let initialspeed = null;
if (args[2]) {
initialspeed = parseInt(args[2]);
initialspeed = 30000 - initialspeed;
let t = Math.ceil(initialspeed / 1200);
console.log(t);
ups = ups - t;
}
if (args[3]) {
initialcharge = parseInt(args[3]);
initialcharge = 128 - initialcharge;
let t = Math.ceil(initialcharge / 4);
console.log(t);
ups = ups - t;
}
message.channel.send(`Should be ${damage + ups * 144}.`);
}
if (command == "cdrag") {
if (!args[0] || !args[1] || !args[2])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let damage = parseInt(args[0]);
let upgrades = parseInt(args[1]);
let additional = parseInt(args[2]);
if (additional < 3) upgrades = upgrades - (3 - additional);
message.channel.send(
`Should be ${
damage + upgrades * 112
} damage with maxed additional projectiles.`
);
}
if (command == "owl") {
if (!args[0])
return message.channel.send(
"Not enough arguments, consult <<help."
);
let ingPercent = parseFloat(args[0]);
return message.channel.send(
`Should be approximately ${
Math.round(ingPercent * 0.8777066594 * 100) / 100
}%.`
);
}
if (command == "help") {
let embed = new EmbedBuilder();
embed.setTitle("Commands");
if (prefix == "?")
embed.setDescription("**development build, subject to change**");
embed.addFields(
{
name: "res",
value: ":shield: Calculates how much upgrades you need to max your resistances. (<<res <res> <res> <res> [res] | [hero stat] [levels] [second hero stat])",
},
{
name: "bonus",
value: ":star: Sums and calculates bonus for numbers. (<<bonus <number> <number> [inf optional extra numbers])",
},
{
name: "cat",
value: ":cat: Calculates boost for cat. (<<cat <boost> <levels>)",
},
{
name: "cdrag",
value: ":dragon: Calculate damage for crystaline dragon taking into account upgrades and additional projectiles. (<<cdrag <base> <ups> <extra projectiles>)",
},
{
name: "cb",
value: ":crossed_swords: Calculate calamity blade damage taking in to account speed. (<<cb <damage> <ups> [proj speed])",
},
{
name: "bident",
value: ":trident: Calculate bident damage taking in to account speed and charge speed. (<<bident <damage> <ups> [proj speed] [charge speed])",
},
{
name: "ms",
value: ":tada: Calculate moon staff damage taking in to account speed (<<ms <elemental damage> <ups> [proj speed])",
},
{
name: "help",
value: ":scroll: Shows this message. (bot is a tbot replacement for this server :P)",
}
);
embed.setColor(0x00ff00);
message.channel.send({ embeds: [embed] });
}
});
// Log in to Discord with your client's token
client.login(token);