2025-11-11 20:14:13 +08:00
|
|
|
from module.base.button import Button, ButtonGrid
|
2024-06-05 23:20:28 +08:00
|
|
|
from module.base.utils import *
|
|
|
|
|
from module.handler.assets import AUTO_SEARCH_MENU_EXIT
|
2025-11-23 22:00:52 +08:00
|
|
|
from module.statistics.assets import *
|
2024-06-05 23:20:28 +08:00
|
|
|
from module.statistics.get_items import ITEM_GROUP, GetItemsStatistics
|
|
|
|
|
from module.statistics.item import Item
|
|
|
|
|
from module.statistics.utils import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BonusItem(Item):
|
|
|
|
|
def predict_valid(self):
|
2025-12-04 19:23:50 +08:00
|
|
|
image = rgb2gray(self.image)
|
|
|
|
|
width, height = image_size(image)
|
|
|
|
|
wm, hm = width // 2, height // 2
|
|
|
|
|
row_center = image[hm: hm + 5, :]
|
|
|
|
|
info_bar = image[64: 69, :]
|
|
|
|
|
column_center = image[:, wm: wm + 5]
|
|
|
|
|
return all(np.mean(img > 160) > 0.1 for img in [image, row_center, info_bar, column_center])
|
2024-06-05 23:20:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CampaignBonusStatistics(GetItemsStatistics):
|
2025-11-11 20:14:13 +08:00
|
|
|
bonus_button: Button = CAMPAIGN_BONUS
|
|
|
|
|
|
2025-12-03 13:46:26 +08:00
|
|
|
def appear_on(self, image, similarity=0.85):
|
|
|
|
|
if CAMPAIGN_BONUS_STRATEGY_CHECK.match(image, offset=(200, 500), similarity=similarity):
|
2025-11-23 22:00:52 +08:00
|
|
|
return False
|
2025-12-03 13:46:26 +08:00
|
|
|
if AUTO_SEARCH_MENU_EXIT.match(image, offset=(200, 20), similarity=similarity) \
|
|
|
|
|
and (CAMPAIGN_BONUS.match(image, offset=(200, 500), similarity=similarity) \
|
|
|
|
|
and CAMPAIGN_BONUS_SINGLE.match(image, offset=(200, 500), similarity=similarity)):
|
2024-06-05 23:20:28 +08:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def _stats_get_items_load(self, image):
|
|
|
|
|
ITEM_GROUP.item_class = BonusItem
|
|
|
|
|
ITEM_GROUP.similarity = 0.85
|
|
|
|
|
ITEM_GROUP.amount_area = (35, 51, 63, 63)
|
2025-11-11 20:14:13 +08:00
|
|
|
origin = area_offset(self.bonus_button.button, offset=(-7, 34))[:2]
|
2024-06-05 23:20:28 +08:00
|
|
|
grids = ButtonGrid(origin=origin, button_shape=(64, 64), grid_shape=(7, 2), delta=(72 + 2 / 3, 75))
|
|
|
|
|
|
|
|
|
|
reward_bottom = AUTO_SEARCH_MENU_EXIT.button[1]
|
|
|
|
|
grids.buttons = [button for button in grids.buttons if button.area[3] < reward_bottom]
|
|
|
|
|
ITEM_GROUP.grids = grids
|
|
|
|
|
|
|
|
|
|
def stats_get_items(self, image, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Args:
|
|
|
|
|
image (np.ndarray):
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
list[Item]:
|
|
|
|
|
"""
|
|
|
|
|
result = super().stats_get_items(image, **kwargs)
|
|
|
|
|
valid = False
|
2025-04-25 20:41:40 +08:00
|
|
|
valid_coin = False
|
2024-06-05 23:20:28 +08:00
|
|
|
for item in result:
|
|
|
|
|
if item.name == 'Coin':
|
|
|
|
|
valid = True
|
2025-11-18 02:10:59 +08:00
|
|
|
if item.amount > 80:
|
2025-04-25 20:41:40 +08:00
|
|
|
valid_coin = True
|
|
|
|
|
if valid and valid_coin:
|
2024-06-05 23:20:28 +08:00
|
|
|
return [self.revise_item(item) for item in result]
|
2025-04-25 20:41:40 +08:00
|
|
|
elif valid:
|
|
|
|
|
raise ImageError('Campaign bonus image have too low coins, dropped')
|
2024-06-05 23:20:28 +08:00
|
|
|
else:
|
|
|
|
|
raise ImageError('Campaign bonus image does not have coins, dropped')
|
|
|
|
|
|
|
|
|
|
def revise_item(self, item):
|
|
|
|
|
"""
|
|
|
|
|
Args:
|
|
|
|
|
item (Item):
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Item:
|
|
|
|
|
"""
|
|
|
|
|
# Campaign bonus drop 9 to 30+ chips, but sometimes 10 is detected as 1.
|
|
|
|
|
if item.name == 'Chip' and 0 < item.amount < 4:
|
|
|
|
|
item.amount *= 10
|
|
|
|
|
|
2025-04-25 20:41:40 +08:00
|
|
|
if 'ship' in item.name:
|
|
|
|
|
if 3 < item.amount < 10:
|
|
|
|
|
item.amount = 1
|
|
|
|
|
elif item.amount >= 10:
|
|
|
|
|
if 0 <= item.amount % 10 <= 3:
|
|
|
|
|
item.amount %= 10
|
|
|
|
|
else:
|
|
|
|
|
item.amount //= 10
|
|
|
|
|
|
2024-06-05 23:20:28 +08:00
|
|
|
return item
|