【发布时间】:2019-10-13 01:42:20
【问题描述】:
我的“问题”更多是我希望添加的功能,我使用了本指南: https://anidiots.guide/coding-guides/sqlite-based-points-system 我稍微修改了代码,主要是给你随机数量的 XP,我正在寻找编辑需要多少 XP 才能升级。
现在它是一个静态数量,升级需要 5000。我正在尝试让它在每次升级时将升级所需的数量增加 5000。
目前,它的工作方式如下:
1 到 2 级 = 总共需要 5000 经验
2 到 3 级 = 总共需要 10000 经验
目前,每级之间升级所需的数量总是5000。
这就是我希望它的工作方式:
1 到 2 级 = 总共需要 5000 经验
2 到 3 级 = 总共需要 15000 经验
5000 到 2 级,10000 到 3 级,依此类推(每次升级所需的数量增加 5000)
我花了 2 个小时的大部分时间尝试不同的东西,主要是查看完全超出我的深度的代码。 我相信做这样的事情会奏效,但我不知道它是否正确
if (score.level == '1') {
nextLevel = 5000
}
if (score.level == '2' {
nextLevel = 10000
}
我非常怀疑这是否正确,否则我的消息事件会很长,因为我计划有 100 个级别
代码全文:
let score;
if (message.guild) {
score = bot.getScore.get(message.author.id, message.guild.id);
if (!score) {
score = {
id: `${message.guild.id}-${message.author.id}`,
user: message.author.id,
guild: message.guild.id,
points: 0,
level: 1,
};
}
const xpAdd = Math.floor(Math.random() * 10) + 50;
const curxp = score.points;
const curlvl = score.level;
const nxtLvl = score.level * 5000;
score.points = curxp + xpAdd;
if (nxtLvl <= score.points) {
score.level = curlvl + 1;
const lvlup = new MessageEmbed()
.setAuthor(
`Congrats ${message.author.username}`,
message.author.displayAvatarURL()
)
.setTitle('You have leveled up!')
.setThumbnail('https://i.imgur.com/lXeBiMs.png')
.setColor(color)
.addField('New Level', curlvl + 1);
message.channel.send(lvlup).then(msg => {
msg.delete({
timeout: 10000,
});
});
}
bot.setScore.run(score);
}
代码按原样运行良好且符合预期,但原样不是很好,因为从 30-31 级升级没有任何奖励,因为从 1-2 级获得所需的 XP 数量相同
【问题讨论】:
-
这会起作用,但这是一种非常硬编码的方法......
标签: javascript node.js npm discord.js