NextCord打架指挥组织和建议

发布于 2025-01-20 07:31:34 字数 3904 浏览 0 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2025-01-27 07:31:34

如果您将数据保留在字典中

class Fight(commands.Cog):
    
    testServerID = 948362430256410685

    char_speed = {           
        'Dre': 3,
        'Henry': 4,
        'Sonic': 10,
        'Nub': 3,
        'God': 5,
        'Pewdiepie': 6,
    }        

    char_strength = {
        'Dre': 3,
        'Henry': 6,
        'Sonic': 5,
        'Nub': 4,
        'God': 5,
        'Pewdiepie': 6,
    }

    char_defense = {
        'Dre': 6,
        'Henry': 7,
        'Sonic': 5,
        'Nub': 5,
        'God': 5,
        'Pewdiepie': 6,
    }

    # ... other ...

,则可以将其写入

@nextcord.slash_command(name="fight", description="does fight stuff idk", guild_ids=[testServerID])
async def fight(self, interaction: Interaction, char1, weapon1, char2, weapon2):

    if (char1 in self.char_speed) and (char1 in self.char_strength) and (char1 in self.char_defense): 
        fighterstat = self.char_speed[char1] + self.char_strange[char1] + self.char_defense[char1]
    else:
        print('Unknow char1:', char1)

    # ... other ...

,如果您需要更多字符,则只需在词典中添加值 - 而无需更改其余的代码。

您甚至可以从文件中读取数据。或者,您可以添加添加字符的Discord命令。


最终您可以按角色和武器进行分组

class Fight(commands.Cog):
    
    testServerID = 948362430256410685
    
    character = {
        'Dre':   {'speed': 3,  'strength': 3, 'defense': 6},
        'Henry': {'speed': 4,  'strength': 6, 'defense': 7},
        'Sonic': {'speed': 10, 'strength': 5, 'defense': 5},
        'Nub':   {'speed': 3,  'strength': 4, 'defense': 5},
        'God':   {'speed': 5,  'strength': 5, 'defense': 5},
        'Pewdiepie': {'speed': 6, 'strength': 6, 'defense': 6},
    }        

    weapon = {
        'Katana': {'speed': 6,  'strength': 3, 'defense': 1},
        # ... code ...
    }

,然后可能会更简单

@nextcord.slash_command(name="fight", description="does fight stuff idk", guild_ids=[testServerID])
async def fight(self, interaction: Interaction, char1, weapon1, char2, weapon2):

    if char1 in self.character:
        data = self.character[char1]
        fighterstat = data['speed'] + data['strange'] + data['defense']
    else:
        print('Unknow char1:', char1)


    # ... other ...

If you would keep data in dictionaries

class Fight(commands.Cog):
    
    testServerID = 948362430256410685

    char_speed = {           
        'Dre': 3,
        'Henry': 4,
        'Sonic': 10,
        'Nub': 3,
        'God': 5,
        'Pewdiepie': 6,
    }        

    char_strength = {
        'Dre': 3,
        'Henry': 6,
        'Sonic': 5,
        'Nub': 4,
        'God': 5,
        'Pewdiepie': 6,
    }

    char_defense = {
        'Dre': 6,
        'Henry': 7,
        'Sonic': 5,
        'Nub': 5,
        'God': 5,
        'Pewdiepie': 6,
    }

    # ... other ...

then you could write it as

@nextcord.slash_command(name="fight", description="does fight stuff idk", guild_ids=[testServerID])
async def fight(self, interaction: Interaction, char1, weapon1, char2, weapon2):

    if (char1 in self.char_speed) and (char1 in self.char_strength) and (char1 in self.char_defense): 
        fighterstat = self.char_speed[char1] + self.char_strange[char1] + self.char_defense[char1]
    else:
        print('Unknow char1:', char1)

    # ... other ...

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

class Fight(commands.Cog):
    
    testServerID = 948362430256410685
    
    character = {
        'Dre':   {'speed': 3,  'strength': 3, 'defense': 6},
        'Henry': {'speed': 4,  'strength': 6, 'defense': 7},
        'Sonic': {'speed': 10, 'strength': 5, 'defense': 5},
        'Nub':   {'speed': 3,  'strength': 4, 'defense': 5},
        'God':   {'speed': 5,  'strength': 5, 'defense': 5},
        'Pewdiepie': {'speed': 6, 'strength': 6, 'defense': 6},
    }        

    weapon = {
        'Katana': {'speed': 6,  'strength': 3, 'defense': 1},
        # ... code ...
    }

and then it could be simpler

@nextcord.slash_command(name="fight", description="does fight stuff idk", guild_ids=[testServerID])
async def fight(self, interaction: Interaction, char1, weapon1, char2, weapon2):

    if char1 in self.character:
        data = self.character[char1]
        fighterstat = data['speed'] + data['strange'] + data['defense']
    else:
        print('Unknow char1:', char1)


    # ... other ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文