本文整理汇总了Python中inventory.Inventory.swap_main_hand方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.swap_main_hand方法的具体用法?Python Inventory.swap_main_hand怎么用?Python Inventory.swap_main_hand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.swap_main_hand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import swap_main_hand [as 别名]
#.........这里部分代码省略.........
# SWAPPING
if decisions[0] == '1' or decisions[0] == '2':
items = self.inventory.get_pack()
if len(items) == 0:
self.messages.append("You have no items to swap between!")
return False
handChoice = 'Main Hand' if decisions[0] == '1' else 'Off-Hand'
self.swap_weapon_to = handChoice
# Print the weapons available to swap to
validSwap = False
while not validSwap:
self.messages.append('Which weapon do you want to place in your {}?'.format(handChoice))
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: