Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
feat: adapt game setting 'auto use item'
Browse files Browse the repository at this point in the history
With the new setting, items will be auto-used after exchange. So
in shop exchanged item menu scene, record item that may be disabled
by auto-used
  • Loading branch information
robo-dani authored and NateScarlet committed Jul 8, 2022
1 parent 8e1be58 commit 327b13f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
17 changes: 13 additions & 4 deletions auto_derby/scenes/single_mode/item_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def _recognize_menu(img: Image, min_y: int) -> Iterator[Tuple[Item, app.Rect]]:

class ItemMenuScene(Scene):
_item_min_y = 130
_supports_auto_use = False

def __init__(self) -> None:
super().__init__()
Expand Down Expand Up @@ -178,6 +179,7 @@ def use_items(self, ctx: Context, items: Sequence[Item]) -> None:
for i in items:
remains[i.id] += i.quantity or 1
selected: Sequence[Item] = []
has_selected: bool = False

def _select_visible_items() -> None:
for match, button_rect in _recognize_menu(
Expand All @@ -186,10 +188,16 @@ def _select_visible_items() -> None:
if match.id not in remains:
continue
if match.disabled:
app.log.text("skip disabled: %s" % match, level=app.WARN)
if self._supports_auto_use and match.can_be_auto_used():
# add remains[match.id] times matched item into selected
selected.extend((match,) * remains[match.id])
else:
app.log.text("skip disabled: %s" % match, level=app.WARN)
del remains[match.id]
continue
app.log.text("select: %s" % match)
nonlocal has_selected
has_selected = True
while remains[match.id]:
app.device.tap(button_rect)
remains[match.id] -= 1
Expand All @@ -208,9 +216,10 @@ def _select_visible_items() -> None:
self._scroll.complete()

if selected:
action.wait_tap_image(templates.SINGLE_MODE_SHOP_USE_CONFIRM_BUTTON)
action.wait_tap_image(templates.SINGLE_MODE_ITEM_USE_BUTTON)
self._after_use_confirm(ctx)
if has_selected:
action.wait_tap_image(templates.SINGLE_MODE_SHOP_USE_CONFIRM_BUTTON)
action.wait_tap_image(templates.SINGLE_MODE_ITEM_USE_BUTTON)
self._after_use_confirm(ctx)
for i in selected:
ctx.items.remove(i.id, 1)
ctx.item_history.append(ctx, i)
Expand Down
1 change: 1 addition & 0 deletions auto_derby/scenes/single_mode/shop_exchanged_item_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class ShopExchangedItemMenuScene(ItemMenuScene):
_item_min_y = 194
_supports_auto_use = True

@classmethod
def name(cls) -> Text:
Expand Down
10 changes: 10 additions & 0 deletions auto_derby/single_mode/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,15 @@ def should_use_directly(self, ctx: Context) -> bool:
return False
return True

def can_be_auto_used(self) -> bool:
"""auto used item by setting
※自動使用の対象となる育成グッズは、「基礎能力アップ」「トレーニングLvアップ」
の効果がある育成グッズです。 see https://dmg.umamusume.jp/news/detail?id=831
"""
es = self.effect_summary()
if es.training_levels:
return True
return (es.speed + es.stamina + es.power + es.guts + es.wisdom) > 0


g.item_class = Item

0 comments on commit 327b13f

Please sign in to comment.