所以,我对编码还很陌生,我正在尝试创建一个随机的、基于转弯的战斗系统。然而,我认为我在代码中犯了一个错误。这不是随机的,也不做最后的打击。我找不到错误。
if(command === "holmgang"){
if(args[0] === "help"){
msg.channel.send("Holmgang is a duel practiced by early medieval Scandinavians. It was a legally recognized way to settle disputes./Anyone offended could challenge the other party to holmgang regardless of their differences in social status. This could be a matter of honor, ownership or property, demand of restitution or debt, legal disagreement or intention to help a wife or relative or avenge a friend.")
}
else{
let user = msg.member.user
let enemy = msg.mentions.users.first()
if(enemy){
msg.channel.send("**You called your enemy forward for a holmgång!**")
setTimeout(function(){msg.channel.send("**Both of you will arrive on a small island nearby. Only one shall return.**")},5000);
var i;
var attacker;
var waiting;
var finisherattack = Math.floor(Math.random() * 5);
var finishing = 0
var attackmoves = []
for (i = 1; finishing<= 80 ; i++) {
finishing = Math.floor(Math.random() * 100);
var a = i*3
var b = a*1000
var time = b + 5000
if (i%2 == 0) {
attacker = user
waiting = enemy
}
else{
attacker = enemy
waiting = user
}
var randomattack = Math.floor(Math.random() * 5);
attackmoves = [attacker + " throws his spear to " + waiting + ", but misses.", attacker + " attacks " + waiting + " with his sword, but " + waiting + "uses his shield to block.", attacker + " swings his sword aiming at " + waiting + "s head. but " + waiting + "dodges.", attacker + " throws his spear to " + waiting + ", but " + waiting + " catches it with his shield.", attacker + " attacks " + waiting + " with his axe, but " + waiting + " blocks it with his shield"]
setTimeout(function(){msg.channel.send(attackmoves[randomattack])},time);
}
if(finishing > 80){
let winner = attacker
let loser = waiting
var finishingmoves = [winner + " throws his spear to " + loser + ", killing him.", winner + " chops " + loser + "s head off with his axe.",winner + " stabs " + loser + " with his sword, killing him.", winner + " kills " + loser + ", with his axe.",winner + " bashes his shield against " + loser + "s head. Then chops his head off with his sword."]
setTimeout(function(){msg.channel.send(finishingmoves[finisherattack])},time);
}
}输入:
.holmgang @EmoBey09预期产出:
@EmoBey09 swings his sword aiming at @Phoenixs head. but @Phoenix dodges.
@Phoenix throws his spear to @EmoBey09, but misses.
@EmoBey09 throws his spear to @Phoenix, but @Phoenix catches it with his shield.
@Phoenix attacks @EmoBey09 with his axe, but @EmoBey09 blocks it with his shield
@EmoBey09 chops @Phoenix's head off with his axe.实际产出:
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.
@Phoenix swings his sword aiming at @EmoBey09s head. but @EmoBey09 dodges.发布于 2020-08-08 16:41:09
不要使用var,对以后没有修改的变量使用const,对其他变量使用let。
https://stackoverflow.com/questions/63317354
复制相似问题