【发布时间】:2021-03-25 03:17:25
【问题描述】:
我正在尝试在 Discord 用户输入中搜索附加到属性(攻击次数、攻击技能、强度、韧性、保存)的整数,然后通过一些计算运行这些参数。
目前该函数使用命令中args的顺序:
!赔率 5 3 4 5 3
这行得通,但我想要这样的东西:
!赔率: 5 sk: 3 st: 4 t: 5 sv: 3
机器人会在用户输入中以任意顺序搜索附加到这些属性的值,并使用这些整数进行计算。
此外,如果属性不存在,机器人将不会将它们包含在输出中(或分配默认值),并通过添加不附加整数的附加单短语属性(例如 fnp或 res) 然后它会添加另一个标准计算和输出。
这是我目前所拥有的:
const { Message } = require('discord.js')
module.exports = {
name: 'odds',
aliases: ['stats', 'probability'],
usage: '[#attacks (1 = auto hit)] [skill] [strength] [toughness] [save (7 = no save)]',
description: 'What are the odds?',
execute(message, args) {
let attack = args[0]
let skill;
if (args[1]>=7) skill = 7;
else skill = args[1];
let strength = args[2]
let toughness = args[3]
let save;
if (args[4]<=6) save = args[4];
else save = 7;
let hits = parseFloat((attack*((7-skill)/6)).toFixed(2))
let hitSixes = parseFloat((attack*(1/6)).toFixed(2))
let woundFactor;
if (strength>=(2*toughness)) woundFactor = 2;
else
if (strength>toughness) woundFactor = 3;
else
if (strength==toughness) woundFactor = 4;
else
if (toughness>=(2*strength)) woundFactor = 6;
else
if (strength<toughness) woundFactor = 5;
let wounds = parseFloat((hits*((7-woundFactor)/6)).toFixed(2))
let woundSixes = parseFloat((hits*(1/6)).toFixed(2))
let unsavedWounds = parseFloat(((wounds-(wounds*((7-save)/6))).toFixed(2)))
message.channel.send(`On average you will make:\n${hits} successful hits (with ${hitSixes} sixes)\n${wounds} successful wounds (with ${woundSixes} sixes)\nGiving a total of ${unsavedWounds} unsaved wounds.`)
}}
非常感谢任何和所有帮助!
【问题讨论】:
标签: javascript arguments discord discord.js