当前位置: 首页>>代码示例>>Python>>正文


Python Inventory.use_misc方法代码示例

本文整理汇总了Python中inventory.Inventory.use_misc方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.use_misc方法的具体用法?Python Inventory.use_misc怎么用?Python Inventory.use_misc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inventory.Inventory的用法示例。


在下文中一共展示了Inventory.use_misc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Game

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import use_misc [as 别名]

#.........这里部分代码省略.........
                itemIndexOffset = 1
                if self.inventory.get_main_hand():
                    itemIndexOffset += 1
                if self.inventory.get_offhand():
                    itemIndexOffset += 1
                for i in range(len(items)):
                    item = items[i]
                    keyPress = 'Press {} to swap to '.format(i + itemIndexOffset)
                    weaponMssg = '{0} (Type: {1}, Strength: {2}, Durability: {3})'.format(item['name'], item['type'], item['strength'], item['durability'])
                    self.messages.append(keyPress + weaponMssg)
                self.printScreen()
                
                try:
                    itemChoice = self.user.__move__(self.getDataForAI('SWAP'))
                    itemChoice = int(itemChoice[0]) - itemIndexOffset
                    self.messages = []    
                    if not self.inventory.is_valid_item_index(itemChoice):
                        self.messages.append('Invalid command!')
                        return False
                    elif (handChoice == 'Main Hand' and self.inventory.swap_main_hand(itemChoice)) or \
                            (handChoice == 'Off-Hand' and self.inventory.swap_offhand(itemChoice)):
                        self.messages.append('Successfully swapped weapon to {}!'.format(handChoice))
                        validSwap = True
                    else:
                        self.messages.append('You cannot place a {} in your {}!'.format(items[itemChoice]['name'], handChoice))
                        return False
                except ValueError:
                    self.messages.append("Invalid input!")
            if not USE_AI: time.sleep(2)
        
        # ATTACKING
        elif decisions[0] == 'f':
            self.playerStance = "OFFENSIVE"
            result = self.inventory.use_misc("Fireballs")
            if result:
                playerDamage = ITEM_STRENGTHS["Fireballs"]
                self.messages.append("You blast the {0} for {1} damage!".format(self.current_enemy.name, playerDamage))
                self.current_enemy.damage(playerDamage)
            else:
                self.messages.append("You wave your hands around, but nothing happens.")
            return True

        elif decisions[0] == 'x':
            self.playerStance = "OFFENSIVE"
            # are we attacking with a ranged weapon?
            ranged_items = self.inventory.get_equipped_ranged()
            if ranged_items:
                # deal the damage
                playerAction = "shoot"

            # for non-ranged weapons
            else:
                # deal the damage
                playerAction = "hit"

            if self.rangedEncounter and not self.inventory.get_equipped_ranged():
                # Melee weapon is equipped during ranged encounter, therefore cannot do damage
                return True
            playerDamage = self.inventory.get_damage()
            if (self.rangedEncounter):
                playerDamage *= RANGE_COMBAT_FACTOR
                
            # deal the damage and update
            totalDamage = max(1, # Force player to do minimum 1 damage
                              int(playerDamage * (float(self.inventory.next_attack) / 3)))
            self.current_enemy.damage(totalDamage)
开发者ID:gaohongl,项目名称:183siege-reach,代码行数:70,代码来源:game.py


注:本文中的inventory.Inventory.use_misc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。