Add: choose curio

This commit is contained in:
Hengyu 2023-08-12 15:15:25 +08:00
parent 14bf3c81b4
commit 039eca2de9
12 changed files with 512 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

View File

@ -331,6 +331,17 @@ class KeywordExtract:
self.write_keywords(keyword_class='RogueResonance', output_file='./tasks/rogue/keywords/resonance.py',
text_convert=blessing_name, extra_attrs=extra_attrs)
def iter_rogue_miracles(self):
miracles = read_file(os.path.join(TextMap.DATA_FOLDER, 'ExcelOutput', 'RogueMiracle.json'))
visited = set()
for data in miracles.values():
hash_ = deep_get(data, keys='MiracleName.Hash')
_, name = self.find_keyword(hash_, lang='cn')
if name in visited:
continue
visited.add(name)
yield hash_
def generate(self):
self.load_keywords(['模拟宇宙', '拟造花萼(金)', '拟造花萼(赤)', '凝滞虚影', '侵蚀隧洞', '历战余响', '忘却之庭'])
self.write_keywords(keyword_class='DungeonNav', output_file='./tasks/dungeon/keywords/nav.py')
@ -361,6 +372,8 @@ class KeywordExtract:
self.write_keywords(keyword_class='ItemTab', text_convert=lambda name: name.replace(' ', ''),
output_file='./tasks/item/keywords/tab.py')
self.generate_rogue_buff()
self.load_keywords(list(self.iter_rogue_miracles()))
self.write_keywords(keyword_class='RogueCurio', output_file='./tasks/rogue/keywords/curio.py')
if __name__ == '__main__':

View File

@ -0,0 +1,25 @@
from module.base.button import Button, ButtonWrapper
# This file was auto-generated, do not modify it manually. To generate:
# ``` python -m dev_tools.button_extract ```
CURIO_ENFORCE = ButtonWrapper(
name='CURIO_ENFORCE',
share=Button(
file='./assets/share/rogue/curio/CURIO_ENFORCE.png',
area=(465, 114, 815, 545),
search=(445, 94, 835, 565),
color=(80, 66, 61),
button=(465, 114, 815, 545),
),
)
OCR_ROGUE_CURIO = ButtonWrapper(
name='OCR_ROGUE_CURIO',
share=Button(
file='./assets/share/rogue/curio/OCR_ROGUE_CURIO.png',
area=(87, 128, 1203, 187),
search=(67, 108, 1223, 207),
color=(18, 19, 20),
button=(87, 128, 1203, 187),
),
)

View File

@ -23,10 +23,10 @@ PAGE_CHOOSE_BUFF = ButtonWrapper(
button=(1105, 95, 1154, 113),
),
)
PAGE_CHOOSE_MIRACLE = ButtonWrapper(
name='PAGE_CHOOSE_MIRACLE',
PAGE_CHOOSE_CURIO = ButtonWrapper(
name='PAGE_CHOOSE_CURIO',
share=Button(
file='./assets/share/rogue/ui/PAGE_CHOOSE_MIRACLE.png',
file='./assets/share/rogue/ui/PAGE_CHOOSE_CURIO.png',
area=(988, 17, 1028, 57),
search=(968, 0, 1048, 77),
color=(40, 39, 34),

View File

@ -31,7 +31,7 @@ pattern += blessing_regex
BLESSING_FILTER_ATTR += (BLESSING_ATTR_NAME,)
FILETER_REGEX = re.compile(pattern)
BLESSING_FILTER_PRESET = ("reset", "same_path", "random")
BLESSING_FILTER_PRESET = ("reset", "random")
BLESSING_FILTER = MultiLangFilter(FILETER_REGEX, BLESSING_FILTER_ATTR, BLESSING_FILTER_PRESET)
# resonance
@ -273,16 +273,6 @@ class RogueBlessingSelector(RogueBlessingUI):
return
else:
continue
if option.lower() == 'same_path':
chosen = False
for blessing in self.blessings:
if blessing.matched_keyword.path_id == self.path.id:
self.ui_select_blessing(blessing)
chosen = True
if chosen:
return
else:
continue
if option.lower() == 'random':
choose = np.random.choice(self.blessings)
self.ui_select_blessing(choose)

81
tasks/rogue/curio.py Normal file
View File

@ -0,0 +1,81 @@
import re
import numpy as np
from module.base.timer import Timer
from module.base.utils import get_color
from module.logger import logger
from module.ocr.ocr import Ocr, OcrResultButton
from tasks.rogue.assets.assets_rogue_curio import *
from tasks.rogue.assets.assets_rogue_ui import CONFIRM
from tasks.rogue.keywords import RogueCurio
from tasks.rogue.ui import RogueUI
class RogueCurioOcr(Ocr):
def after_process(self, result):
result = super().after_process(result)
if self.lang == 'ch':
replace_pattern_dict = {
"降维般子": "降维骰子"
}
for pattern, replace in replace_pattern_dict.items():
result = re.sub(pattern, replace, result)
return result
class RogueCurioUI(RogueUI):
def curio_recognition(self):
ocr = RogueCurioOcr(OCR_ROGUE_CURIO)
results = ocr.matched_ocr(self.device.image, RogueCurio)
expect_num = 3
if len(results) != expect_num:
logger.warning(f"The OCR result does not match the curio count. "
f"Expect {expect_num}, but recognized {len(results)} only.")
self.ocr_curios = results
return results
def ui_select_curio(self, curio: OcrResultButton | None, skip_first_screenshot=True, enforce=True):
def is_curio_selected():
return np.mean(get_color(self.device.image, tuple(curio.area))) > 70
def is_select_curio_complete():
"""
Case 1: back to main page
"""
return self.is_in_main()
interval = Timer(1)
# start -> selected
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if is_curio_selected():
if enforce:
logger.info("Curio selected (enforce)")
else:
logger.info(f"Curio {curio} selected")
break
if interval.reached():
if enforce:
self.device.click(CURIO_ENFORCE)
else:
self.device.click(curio)
interval.reset()
skip_first_screenshot = True
# selected -> confirm
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if is_select_curio_complete():
break
if interval.reached():
self.device.click(CONFIRM)
interval.reset()

View File

@ -1,5 +1,6 @@
import tasks.rogue.keywords.blessing as KEYWORDS_ROGUE_BLESSING
import tasks.rogue.keywords.curio as KEYWORDS_ROGUE_CURIO
import tasks.rogue.keywords.path as KEYWORDS_ROGUE_PATH
import tasks.rogue.keywords.resonance as KEYWORDS_ROGUE_RESONANCE
from tasks.rogue.keywords.classes import RogueBlessing, RoguePath, RogueResonance
from tasks.rogue.keywords.classes import RogueBlessing, RoguePath, RogueResonance, RogueCurio

View File

@ -42,3 +42,8 @@ class RogueResonance(Keyword):
def resonance_name(self):
return [self.__getattribute__(f"{server}_parsed")
for server in UI_LANGUAGES if hasattr(self, f"{server}_parsed")]
@dataclass(repr=False)
class RogueCurio(Keyword):
instances: ClassVar = {}

View File

@ -0,0 +1,381 @@
from .classes import RogueCurio
# This file was auto-generated, do not modify it manually. To generate:
# ``` python -m dev_tools.keyword_extract ```
Dimension_Reduction_Dice = RogueCurio(
id=1,
name='Dimension_Reduction_Dice',
cn='降维骰子',
cht='降維骰子',
en='Dimension Reduction Dice',
jp='次元削減ダイス',
)
Chaos_Trametes = RogueCurio(
id=2,
name='Chaos_Trametes',
cn='混沌云芝',
cht='混沌雲芝',
en='Chaos Trametes',
jp='混沌の雲芝',
)
Warping_Compound_Eye = RogueCurio(
id=3,
name='Warping_Compound_Eye',
cn='跃迁复眼',
cht='躍遷複眼',
en='Warping Compound Eye',
jp='跳躍複眼',
)
Fruit_of_the_Alien_Tree = RogueCurio(
id=4,
name='Fruit_of_the_Alien_Tree',
cn='异木果实',
cht='異木果實',
en='Fruit of the Alien Tree',
jp='異木の果実',
)
Casket_of_Inaccuracy = RogueCurio(
id=5,
name='Casket_of_Inaccuracy',
cn='测不准匣',
cht='測不準匣',
en='Casket of Inaccuracy',
jp='不確定の匣',
)
Ambergris_Cheese = RogueCurio(
id=6,
name='Ambergris_Cheese',
cn='香涎干酪',
cht='香涎乾酪',
en='Ambergris Cheese',
jp='香涎チーズ',
)
Fortune_Glue = RogueCurio(
id=7,
name='Fortune_Glue',
cn='福灵胶',
cht='福靈膠',
en='Fortune Glue',
jp='幸福クリーム',
)
The_Parchment_That_Always_Eats = RogueCurio(
id=8,
name='The_Parchment_That_Always_Eats',
cn='永不停嘴的羊皮卷',
cht='永不停嘴的羊皮卷',
en='The Parchment That Always Eats',
jp='おしゃべり羊皮紙',
)
Broken_Cuckoo_Clock = RogueCurio(
id=9,
name='Broken_Cuckoo_Clock',
cn='破碎咕咕钟',
cht='破碎咕咕鐘',
en='Broken Cuckoo Clock',
jp='壊れた鳩時計',
)
Mechanical_Cuckoo_Clock = RogueCurio(
id=10,
name='Mechanical_Cuckoo_Clock',
cn='机械咕咕钟',
cht='機械咕咕鐘',
en='Mechanical Cuckoo Clock',
jp='機械式鳩時計',
)
The_Doctor_Robe = RogueCurio(
id=11,
name='The_Doctor_Robe',
cn='博士之袍',
cht='博士之袍',
en="The Doctor's Robe",
jp='博士のローブ',
)
Society_Ticket = RogueCurio(
id=12,
name='Society_Ticket',
cn='俱乐部券',
cht='俱樂部券',
en='Society Ticket',
jp='クラブチケット',
)
Faith_Bond = RogueCurio(
id=13,
name='Faith_Bond',
cn='信仰债券',
cht='信仰債券',
en='Faith Bond',
jp='信仰債券',
)
Robe_of_The_Beauty = RogueCurio(
id=14,
name='Robe_of_The_Beauty',
cn='纯美之袍',
cht='純美之袍',
en='Robe of The Beauty',
jp='純美のローブ',
)
Gold_Coin_of_Discord = RogueCurio(
id=15,
name='Gold_Coin_of_Discord',
cn='分裂金币',
cht='分裂金幣',
en='Gold Coin of Discord',
jp='分裂金貨',
)
Useless_Typewriter = RogueCurio(
id=16,
name='Useless_Typewriter',
cn='无效文字打印机',
cht='無效文字印表機',
en='Useless Typewriter',
jp='無効文字タイプライター',
)
Void_Wick_Trimmer = RogueCurio(
id=17,
name='Void_Wick_Trimmer',
cn='空无烛剪',
cht='空無燭剪',
en='Void Wick Trimmer',
jp='空無の芯切り',
)
Omniscient_Capsule = RogueCurio(
id=18,
name='Omniscient_Capsule',
cn='万识囊',
cht='萬識囊',
en='Omniscient Capsule',
jp='全知袋',
)
Record_from_Beyond_the_Sky = RogueCurio(
id=19,
name='Record_from_Beyond_the_Sky',
cn='天外重声大碟',
cht='天外合唱專輯',
en='Record from Beyond the Sky',
jp='天外聖歌隊のレコード',
)
Entropic_Die = RogueCurio(
id=20,
name='Entropic_Die',
cn='万象无常骰',
cht='萬象無常骰',
en='Entropic Die',
jp='万象無常のサイコロ',
)
Shining_Trapezohedron_Die = RogueCurio(
id=21,
name='Shining_Trapezohedron_Die',
cn='闪耀的偏方三八面骰',
cht='閃耀的偏方三八面骰',
en='Shining Trapezohedron Die',
jp='輝くトラペゾヘドロンサイコロ',
)
Sealing_Wax_of_Preservation = RogueCurio(
id=22,
name='Sealing_Wax_of_Preservation',
cn='存护火漆',
cht='存護火漆',
en='Sealing Wax of Preservation',
jp='存護の封蝋',
)
Sealing_Wax_of_Elation = RogueCurio(
id=23,
name='Sealing_Wax_of_Elation',
cn='欢愉火漆',
cht='歡愉火漆',
en='Sealing Wax of Elation',
jp='愉悦の封蝋',
)
Sealing_Wax_of_The_Hunt = RogueCurio(
id=24,
name='Sealing_Wax_of_The_Hunt',
cn='巡猎火漆',
cht='巡獵火漆',
en='Sealing Wax of The Hunt',
jp='巡狩の封蝋',
)
Sealing_Wax_of_Destruction = RogueCurio(
id=25,
name='Sealing_Wax_of_Destruction',
cn='毁灭火漆',
cht='毀滅火漆',
en='Sealing Wax of Destruction',
jp='壊滅の封蝋',
)
Sealing_Wax_of_Remembrance = RogueCurio(
id=26,
name='Sealing_Wax_of_Remembrance',
cn='记忆火漆',
cht='記憶火漆',
en='Sealing Wax of Remembrance',
jp='記憶の封蝋',
)
Sealing_Wax_of_Nihility = RogueCurio(
id=27,
name='Sealing_Wax_of_Nihility',
cn='虚无火漆',
cht='虛無火漆',
en='Sealing Wax of Nihility',
jp='虚無の封蝋',
)
Sealing_Wax_of_Abundance = RogueCurio(
id=28,
name='Sealing_Wax_of_Abundance',
cn='丰饶火漆',
cht='豐饒火漆',
en='Sealing Wax of Abundance',
jp='豊穣の封蝋',
)
Corrupted_Code = RogueCurio(
id=29,
name='Corrupted_Code',
cn='乱七八糟的代码',
cht='亂七八糟的程式碼',
en='Corrupted Code',
jp='ぐちゃぐちゃなコード',
)
Odd_Code = RogueCurio(
id=30,
name='Odd_Code',
cn='有点蹊跷的代码',
cht='有點蹊蹺的程式碼',
en='Odd Code',
jp='少し怪しげなコード',
)
Normal_Code = RogueCurio(
id=31,
name='Normal_Code',
cn='中规中矩的代码',
cht='中規中矩的程式碼',
en='Normal Code',
jp='杓子定規なコード',
)
Elegant_Code = RogueCurio(
id=32,
name='Elegant_Code',
cn='精确优雅的代码',
cht='精確優雅的程式碼',
en='Elegant Code',
jp='正確で完璧なコード',
)
Mysterious_Code = RogueCurio(
id=33,
name='Mysterious_Code',
cn='没有注释的代码',
cht='沒有註解的程式碼',
en='Mysterious Code',
jp='注釈がないコード',
)
Infinitely_Recursive_Code = RogueCurio(
id=34,
name='Infinitely_Recursive_Code',
cn='无限递归的代码',
cht='無限遞迴的程式碼',
en='Infinitely Recursive Code',
jp='無限再帰するコード',
)
Shattered_Star_Bait = RogueCurio(
id=35,
name='Shattered_Star_Bait',
cn='碎星芳饵',
cht='碎星芳餌',
en='Shattered Star Bait',
jp='砕けた星の釣り餌',
)
Obliteration_Wick_Trimmer = RogueCurio(
id=36,
name='Obliteration_Wick_Trimmer',
cn='湮灭烛剪',
cht='湮滅燭剪',
en='Obliteration Wick Trimmer',
jp='湮滅の芯切り',
)
Insect_Web = RogueCurio(
id=37,
name='Insect_Web',
cn='虫网',
cht='蟲網',
en='Insect Web',
jp='虫網',
)
Angel_type_I_O_U_Dispenser = RogueCurio(
id=38,
name='Angel_type_I_O_U_Dispenser',
cn='天使型谢债发行机',
cht='天使型謝債發行機',
en='Angel-type I.O.U. Dispenser',
jp='天使型謝債発行機',
)
Laurel_Crown_of_Planar_Shifts = RogueCurio(
id=39,
name='Laurel_Crown_of_Planar_Shifts',
cn='换境桂冠',
cht='換境桂冠',
en='Laurel Crown of Planar Shifts',
jp='換境桂冠',
)
Space_Time_Prism = RogueCurio(
id=40,
name='Space_Time_Prism',
cn='时空棱镜',
cht='時空稜鏡',
en='Space-Time Prism',
jp='時空のプリズム',
)
Galactic_Big_Lotto = RogueCurio(
id=41,
name='Galactic_Big_Lotto',
cn='银河大乐透',
cht='銀河大樂透',
en='Galactic Big Lotto',
jp='銀河ビッグロッタリー',
)
Divination_Cuckoo_Clock = RogueCurio(
id=42,
name='Divination_Cuckoo_Clock',
cn='卜筮咕咕钟',
cht='卜筮咕咕鐘',
en='Divination Cuckoo Clock',
jp='占い鳩時計',
)
Black_Forest_Cuckoo_Clock = RogueCurio(
id=43,
name='Black_Forest_Cuckoo_Clock',
cn='黑森林咕咕钟',
cht='黑森林咕咕鐘',
en='Black Forest Cuckoo Clock',
jp='黒森鳩時計',
)
Perpetual_Motion_Cuckoo_Clock = RogueCurio(
id=44,
name='Perpetual_Motion_Cuckoo_Clock',
cn='永动咕咕钟',
cht='永動咕咕鐘',
en='Perpetual Motion Cuckoo Clock',
jp='永久鳩時計',
)
Punklorde_Mentality = RogueCurio(
id=45,
name='Punklorde_Mentality',
cn='朋克洛德精神',
cht='龐克洛德精神',
en='Punklorde Mentality',
jp='パンクロードの精神',
)
Beacon_Coloring_Paste = RogueCurio(
id=46,
name='Beacon_Coloring_Paste',
cn='信标着色剂',
cht='信標著色劑',
en='Beacon Coloring Paste',
jp='ビーコン着色剤',
)
IPC_Cuckoo_Clock = RogueCurio(
id=47,
name='IPC_Cuckoo_Clock',
cn='公司咕咕钟',
cht='公司咕咕鐘',
en='IPC Cuckoo Clock',
jp='カンパニー鳩時計',
)

View File

@ -14,4 +14,4 @@ class RogueUI(UI):
return self.image_color_count(PAGE_CHOOSE_BUFF, (245, 245, 245), count=200)
def is_page_choose_curio(self):
return self.appear(PAGE_CHOOSE_MIRACLE)
return self.appear(PAGE_CHOOSE_CURIO)