Rag*_*rok 1 javascript node.js npm discord.js
我的“问题”更多的是我想要添加的功能,我使用了本指南: https: //anidiots.guide/coding-guides/sqlite-based-points-system 我对代码做了一些更改,主要是给你一个随机数量的 XP,我正在寻找编辑升级所需的 XP 数量。
现在它是一个静态数量,升级需要 5000。我正在尝试让它在每次升级时额外增加 5000 升级所需的金额。
目前,它的工作原理如下:
1 级到 2 级 = 总共需要 5000 XP
2 级到 3 级 = 总共需要 10000 XP
目前,升级所需的金额始终为每级之间 5000。
这就是我希望它工作的方式:
1 级到 2 级 = 总共需要 5000 XP
2 级到 3 级 = 总共需要 15000 XP
2级需要5000,3级需要10000,以此类推(每次升级需要的数量增加5000)
我花了 2 个小时的大部分时间尝试不同的事情,主要是查看完全超出我能力范围的代码。我相信这样做会起作用,但我不知道这是否正确
if (score.level == '1') {
nextLevel = 5000
}
if (score.level == '2' {
nextLevel = 10000
}
Run Code Online (Sandbox Code Playgroud)
我非常怀疑这是正确的,否则我的消息事件会很长,因为我计划有 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);
}
Run Code Online (Sandbox Code Playgroud)
代码按原样工作正常,符合预期,但按原样不太好,因为从 30 级到 31 级没有奖励,因为从 1 级到 2 级需要获得相同数量的 XP
Here's a little formula which should do the trick (if I understand your problem correctly):
const nxtLvl = 5000 * (Math.pow(2, score.level) - 1);
Run Code Online (Sandbox Code Playgroud)
This gives the following xp requirements to level up:
1->2: 5000
2->3: 15000
3->4: 35000
4->5: 75000
5->6: 155000
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16181 次 |
| 最近记录: |