NextCord打架指挥组织和建议
我在NextCord中创建了一个非常基本的战斗命令。命令就是这样:
/fight [your character] [your weapon] [your enemy] [enemy's weapon]
每个角色和武器都被分配了自己的力量,速度和防御统计数据。并且统计数据都加起来以找到他们的最终统计数据。然后,它对敌人做同样的事情,并计算结果。
我想做的是使我的代码更有条理,并且命令更加复杂。例如,由于更快的速度,让总体统计数据的人有机会获胜。目前,我觉得很多输入都是手动的,所以制作新角色非常乏味。有人有任何建议吗? 另外,我计划为某些统计数据提供某些角色和武器负值。例如给武士刀负面的防御和爆发负强度。
我目前的战斗齿轮代码:
class fight(commands.Cog):
def __init__(self, client):
self.client = client
testServerID = 948362430256410685
@nextcord.slash_command(name = "fight", description = "does fight stuff idk", guild_ids=[testServerID])
async def fight(self, interaction: Interaction, char1, weapon1, char2, weapon2):
# Speed
sDre = 3
sHenry = 4
sSonic = 10
sNub = 3
sGod = 5
sPewdiepie = 6
# Strength
stDre = 3
stHenry = 6
stSonic = 5
stNub = 4
stGod = 5
sPewdiepie = 6
# Defense
dDre = 6
dHenry = 7
dSonic = 5
dNub = 5
dGod = 5
dPewdiepie = 6
# WeaponStats
# Speed
sKatana = 6
sKnife = 4
sSpork = 1
sNokia = 0
sDiamondSword = 6
# Strength
stKatana = 3
stKnife = 7
stSpork = 6
stNokia = 3
stDiamondSword = 4
# Defense
dKatana = 1
dKnife = 2
dSpork = 2
dNokia = 9
dDiamondSword = 2
# Char1
if char1 == 'Dre':
fighterstat = sDre+stDre+dDre
if char1 == 'Henry':
fighterstat = sHenry+stHenry+dHenry
if char1 == 'Sonic':
fighterstat = sSonic+stSonic+dSonic
if char1 == 'Nub':
fighterstat = sNub+stNub+dNub
if char1 == 'God':
fighterstat = sGod+stGod+dGod
if char1 == 'Pewdiepie':
fighterstat = sDre+stDre+dDre
# Weapon1
if weapon1 == 'Katana':
weaponstat = sKatana+stKatana+dKatana
if weapon1 == 'Knife':
weaponstat = sKnife+stKnife+dKnife
if weapon1 == 'Spork':
weaponstat = sSpork+stSpork+dSpork
if weapon1 == 'Nokia':
weaponstat = sNokia+stNokia+dNokia
if weapon1 == 'DiamondSword':
weaponstat = sDiamondSword+stDiamondSword+dDiamondSword
# Weapon2
if weapon2 == 'Katana':
eweaponstat = sKatana+stKatana+dKatana
if weapon2 == 'Knife':
eweaponstat = sKnife+stKnife+dKnife
if weapon2 == 'Spork':
eweaponstat = sSpork+stSpork+dSpork
if weapon2 == 'Nokia':
eweaponstat = sNokia+stNokia+dNokia
if weapon2 == 'DiamondSword':
eweaponstat = sDiamondSword+stDiamondSword+dDiamondSword
# Char1
if char2 == 'Dre':
efighterstat = sDre+stDre+dDre
if char2 == 'Henry':
efighterstat = sHenry+stHenry+dHenry
if char2 == 'Sonic':
efighterstat = sSonic+stSonic+dSonic
if char2 == 'Nub':
efighterstat = sNub+stNub+dNub
if char2 == 'God':
efighterstat = sGod+stGod+dGod
if char2 == 'Pewdiepie':
efighterstat = sDre+stDre+dDre
fFighter = fighterstat+weaponstat
fEnemy = efighterstat+eweaponstat
win = 'Your character has won the duel! Excellent choice'
lose = 'Your character has lost, try again'
tie = 'You both are equals, try different weapons'
if fFighter < fEnemy:
await interaction.response.send_message(lose)
if fFighter > fEnemy:
await interaction.response.send_message(win)
if fFighter == fEnemy:
await interaction.response.send_message(tie)
print(fFighter)
print(fFighter)
def setup(client):
client.add_cog(fight(client))
I created an extremely basic fight command in Nextcord. The command is like so:
/fight [your character] [your weapon] [your enemy] [enemy's weapon]
Each character and weapon is assigned their own strength, speed, and defense stats. And the stats are all added up to find their final stat. Then it does the same for the enemy and it calculates the outcome.
What I would like to do is make my code more organized, and the command more intricate. For example giving someone who has overall lower statistics a chance to win due to being faster. Currently I feel like a lot of the entering is manual so making new characters is very tedious. Does anyone have any suggestions?
Also, I am planning on giving certain characters and weapons negative values for certain stats. Such as giving the katana negative defense and spork negative strength.
My current code for the fight cog:
class fight(commands.Cog):
def __init__(self, client):
self.client = client
testServerID = 948362430256410685
@nextcord.slash_command(name = "fight", description = "does fight stuff idk", guild_ids=[testServerID])
async def fight(self, interaction: Interaction, char1, weapon1, char2, weapon2):
# Speed
sDre = 3
sHenry = 4
sSonic = 10
sNub = 3
sGod = 5
sPewdiepie = 6
# Strength
stDre = 3
stHenry = 6
stSonic = 5
stNub = 4
stGod = 5
sPewdiepie = 6
# Defense
dDre = 6
dHenry = 7
dSonic = 5
dNub = 5
dGod = 5
dPewdiepie = 6
# WeaponStats
# Speed
sKatana = 6
sKnife = 4
sSpork = 1
sNokia = 0
sDiamondSword = 6
# Strength
stKatana = 3
stKnife = 7
stSpork = 6
stNokia = 3
stDiamondSword = 4
# Defense
dKatana = 1
dKnife = 2
dSpork = 2
dNokia = 9
dDiamondSword = 2
# Char1
if char1 == 'Dre':
fighterstat = sDre+stDre+dDre
if char1 == 'Henry':
fighterstat = sHenry+stHenry+dHenry
if char1 == 'Sonic':
fighterstat = sSonic+stSonic+dSonic
if char1 == 'Nub':
fighterstat = sNub+stNub+dNub
if char1 == 'God':
fighterstat = sGod+stGod+dGod
if char1 == 'Pewdiepie':
fighterstat = sDre+stDre+dDre
# Weapon1
if weapon1 == 'Katana':
weaponstat = sKatana+stKatana+dKatana
if weapon1 == 'Knife':
weaponstat = sKnife+stKnife+dKnife
if weapon1 == 'Spork':
weaponstat = sSpork+stSpork+dSpork
if weapon1 == 'Nokia':
weaponstat = sNokia+stNokia+dNokia
if weapon1 == 'DiamondSword':
weaponstat = sDiamondSword+stDiamondSword+dDiamondSword
# Weapon2
if weapon2 == 'Katana':
eweaponstat = sKatana+stKatana+dKatana
if weapon2 == 'Knife':
eweaponstat = sKnife+stKnife+dKnife
if weapon2 == 'Spork':
eweaponstat = sSpork+stSpork+dSpork
if weapon2 == 'Nokia':
eweaponstat = sNokia+stNokia+dNokia
if weapon2 == 'DiamondSword':
eweaponstat = sDiamondSword+stDiamondSword+dDiamondSword
# Char1
if char2 == 'Dre':
efighterstat = sDre+stDre+dDre
if char2 == 'Henry':
efighterstat = sHenry+stHenry+dHenry
if char2 == 'Sonic':
efighterstat = sSonic+stSonic+dSonic
if char2 == 'Nub':
efighterstat = sNub+stNub+dNub
if char2 == 'God':
efighterstat = sGod+stGod+dGod
if char2 == 'Pewdiepie':
efighterstat = sDre+stDre+dDre
fFighter = fighterstat+weaponstat
fEnemy = efighterstat+eweaponstat
win = 'Your character has won the duel! Excellent choice'
lose = 'Your character has lost, try again'
tie = 'You both are equals, try different weapons'
if fFighter < fEnemy:
await interaction.response.send_message(lose)
if fFighter > fEnemy:
await interaction.response.send_message(win)
if fFighter == fEnemy:
await interaction.response.send_message(tie)
print(fFighter)
print(fFighter)
def setup(client):
client.add_cog(fight(client))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将数据保留在字典中
,则可以将其写入
,如果您需要更多字符,则只需在词典中添加值 - 而无需更改其余的代码。
您甚至可以从文件中读取数据。或者,您可以添加添加字符的Discord命令。
最终您可以按角色和武器进行分组
,然后可能会更简单
If you would keep data in dictionaries
then you could write it as
and if you would need more characters then you would have to only add values to dictionares - without changing rest of code.
You could even read data from file. Or you could add discord command which adds character.
EVentually you could group by character and weapon
and then it could be simpler