Skip to content

Commit

Permalink
fix(nurturing): should update context on formal race
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Jun 6, 2021
1 parent f69c0ce commit 7dbcc23
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
17 changes: 11 additions & 6 deletions auto_derby/jobs/nurturing.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ def _update_context_by_status_menu(ctx: Context):
action.wait_click_image(templates.CLOSE_BUTTON)


def _update_context_by_command_scene(ctx: Context):
ctx.update_by_command_scene(template.screenshot(max_age=0))
if not ctx.fan_count:
_update_context_by_class_menu(ctx)
if ctx.turf == ctx.STATUS_NONE or ctx.date[1:] == (4, 1):
_update_context_by_status_menu(ctx)


def nurturing():
ctx = Context()

Expand All @@ -393,6 +401,8 @@ def nurturing():
elif name == templates.NURTURING_FINISH_BUTTON:
break
elif name == templates.NURTURING_FORMAL_RACE_BANNER:
_update_context_by_command_scene(ctx)
ctx.next_turn()
x, y = pos
y += 60
action.click((x, y))
Expand All @@ -403,12 +413,7 @@ def nurturing():
_handle_race(ctx)
elif name == templates.NURTURING_COMMAND_TRAINING:
time.sleep(0.2) # wait animation
ctx.update_by_command_scene(template.screenshot(max_age=0))
if not ctx.fan_count:
_update_context_by_class_menu(ctx)
if ctx.turf == ctx.STATUS_NONE or ctx.date[1:] == (4, 1):
_update_context_by_status_menu(ctx)

_update_context_by_command_scene(ctx)
ctx.next_turn()
LOGGER.info("update context: %s", ctx)
if action.click_image(templates.NURTURING_SCHEDULED_RACE_OPENING_BANNER):
Expand Down
19 changes: 12 additions & 7 deletions auto_derby/single_mode/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import PIL.ImageOps
from PIL.Image import fromarray as image_from_array

from .. import ocr, imagetools
from .. import ocr, imagetools, templates, template

import os

Expand Down Expand Up @@ -259,13 +259,18 @@ def next_turn(self) -> None:
self._extra_turn_count = 0

def update_by_command_scene(self, screenshot: Image) -> None:
vitality_bbox = (148, 106, 327, 108)
speed_bbox = (45, 553, 90, 572)
stamina_bbox = (125, 553, 162, 572)
power_bbox = (192, 553, 234, 572)
guts_bbox = (264, 553, 308, 572)
wisdom_bbox = (337, 553, 381, 572)
date_bbox = (10, 27, 140, 43)
vitality_bbox = (148, 106, 327, 108)

_, detail_button_pos = next(template.match(
screenshot, templates.NURTURING_CHARACTER_STATUS_MENU_BUTTON),
)
base_y = detail_button_pos[1] + 71
speed_bbox = (45, base_y, 90, base_y + 19)
stamina_bbox = (125, base_y, 162, base_y + 19)
power_bbox = (192, base_y, 234, base_y + 19)
guts_bbox = (264, base_y, 308, base_y + 19)
wisdom_bbox = (337, base_y, 381, base_y + 19)

self.date = _ocr_date(screenshot.crop(date_bbox))

Expand Down
15 changes: 15 additions & 0 deletions auto_derby/single_mode/context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ def test_update_by_command_scene_3():
assert ctx.mood == ctx.MOOD_VERY_GOOD, ctx.mood


def test_update_by_command_scene_4():
img = PIL.Image.open(
_TEST_DATA_PATH / "command_scene_4.png").convert("RGB")
ctx = Context()
ctx.update_by_command_scene(img)
assert ctx.date == (2, 4, 1), ctx.date
assert ctx.vitality == 0.9441340782122905, ctx.vitality
assert ctx.speed == 357, ctx.speed
assert ctx.stamina == 279, ctx.stamina
assert ctx.power == 275, ctx.power
assert ctx.guts == 216, ctx.guts
assert ctx.wisdom == 250, ctx.wisdom
assert ctx.mood == ctx.MOOD_VERY_GOOD, ctx.mood


def test_update_by_command_scene_issue7():
img = PIL.Image.open(
_TEST_DATA_PATH / "command_scene_issue7.png").convert("RGB")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion ocr_labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,5 +436,11 @@
"f81f7c3f1e3c1e3cfc1ff80ff81f3c3e1e3c1e3c1e3cfc3ff80fe00300000000": "8",
"f81ff83f3c3c1e781e787e7cfc7ff87f00780078003cf83ff00fe00300000000": "9",
"10003806fc06fe06fe067e067c067c06fe06ffc63ee638ee38fe387e383e101c": "",
"000018423ce77ee73eff1eff1cff1cffdc7fdcfffc7f7c3e187b00f100e10000": ""
"000018423ce77ee73eff1eff1cff1cffdc7fdcfffc7f7c3e187b00f100e10000": "",
"801fc03fe07fe078f07070707070707070707070f070f071e07fe03fc01f000f": "0",
"c07fe07ff0f900f00078007c003fc00fe003f001f001f87ff8fff07f00000000": "2",
"0000e00ff03f783c3878387038f8f8fff0ffe0ff00780078603cf03fe00f8003": "9",
"007f80ff80ffc0f380f100f000f8007e003f801f80078003c07fc0ffc0ff0000": "2",
"0000fc3ffe3f7e001e001e00ff1fff3f3ffc00f800f800f81ffcff7ffc3ff80f": "5",
"c001fc0ffe1f3f3f1e3e083e001fc01ff007f8017c003f003f00ff3fff3fff3f": "2"
}

0 comments on commit 7dbcc23

Please sign in to comment.