Improve inv selections

This commit is contained in:
2020-10-17 12:41:41 -06:00
parent 0bbe516818
commit 69b0c057d6
2 changed files with 11 additions and 5 deletions
+6 -2
View File
@@ -355,6 +355,7 @@ class Game:
for i in self.g.inv.values():
if i.present:
inv_list.append('{}:{} x {}'.format(items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count))
inv_list.sort()
result = '\n'.join(inv_list)
print(result or 'Empty')
@@ -502,7 +503,7 @@ class Game:
self.pick(slot)
def has_item(self, items):
# select the first match from items of inv
# test if any from items is in inv
for slot, item in self.g.inv.items():
if item.item_id in items:
return True
@@ -511,7 +512,10 @@ class Game:
def select_item(self, items):
# select the first match from items of inv
for slot, item in self.g.inv.items():
# uses smallest stack of that match
inv_items = list(self.g.inv.items())
inv_items.sort(key=lambda x: x[1].item_count or 0)
for slot, item in inv_items:
if item.item_id in items:
self.g.game.choose_slot(slot)
return True