|
|
@@ -1,9 +1,10 @@
|
|
|
# This Python file uses the following encoding: utf-8
|
|
|
|
|
|
import time
|
|
|
-
|
|
|
+import random
|
|
|
+from datetime import datetime
|
|
|
+from module.base.utils import point2str
|
|
|
from module.exception import TaskEnd
|
|
|
-from tasks.Component.GeneralBattle.assets import GeneralBattleAssets
|
|
|
from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
|
|
|
from tasks.Component.GeneralBattle.general_battle import GeneralBattle
|
|
|
from tasks.GameUi.game_ui import GameUi
|
|
|
@@ -19,39 +20,55 @@ default_index = [0, 1, 2, 3, 4, 5, 6, 7]
|
|
|
area_map = (
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_1_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_1_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_1,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_1_FINISHED
|
|
|
},
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_2_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_2_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_2,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_2_FINISHED
|
|
|
},
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_3_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_3_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_3,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_3_FINISHED
|
|
|
},
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_4_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_4_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_4,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_4_FINISHED
|
|
|
},
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_5_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_5_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_5,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_5_FINISHED
|
|
|
},
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_6_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_6_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_6,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_6_FINISHED
|
|
|
},
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_7_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_7_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_7,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_7_FINISHED
|
|
|
},
|
|
|
{
|
|
|
"fail_sign": (DevRyouToppaAssets.I_AREA_8_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_8_IS_FAILURE),
|
|
|
- "rule_click": None
|
|
|
+ "rule_click": DevRyouToppaAssets.C_AREA_8,
|
|
|
+ "finished_sign": DevRyouToppaAssets.I_AREA_8_FINISHED
|
|
|
}
|
|
|
)
|
|
|
|
|
|
|
|
|
+def random_delay(min_value: float = 2.0, max_value: float = 10.0, decimal: int = 1):
|
|
|
+ """
|
|
|
+ 生成一个指定范围内的随机小数
|
|
|
+ """
|
|
|
+ random_float_in_range = random.uniform(min_value, max_value)
|
|
|
+ return (round(random_float_in_range, decimal))
|
|
|
+
|
|
|
+
|
|
|
class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
|
|
|
medal_grid: ImageGrid = None
|
|
|
area_index: list = []
|
|
|
@@ -61,53 +78,82 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
|
|
|
执行
|
|
|
:return:
|
|
|
"""
|
|
|
- # options = self.config.dev_ryou_toppa
|
|
|
+
|
|
|
+ options = self.config.dev_ryou_toppa
|
|
|
self.ui_get_current_page()
|
|
|
self.ui_goto(page_kekkai_toppa)
|
|
|
|
|
|
# 判断阴阳寮是否攻破
|
|
|
while True:
|
|
|
self.screenshot()
|
|
|
- if self.appear(RyouToppaAssets.I_RYOU_REWARD_90, threshold=0.8, interval=1):
|
|
|
+ if self.appear(RyouToppaAssets.I_RYOU_REWARD_90, threshold=0.8):
|
|
|
self.exit()
|
|
|
- if self.appear(RyouToppaAssets.I_RYOU_REWARD, threshold=0.8, interval=1):
|
|
|
+ if self.appear(RyouToppaAssets.I_RYOU_REWARD, threshold=0.8):
|
|
|
break
|
|
|
|
|
|
if not self.area_index:
|
|
|
self.area_index.extend(default_index)
|
|
|
|
|
|
- # 判断突破区域
|
|
|
+ index = self.get_available_area()
|
|
|
+
|
|
|
+ # 开始突破
|
|
|
+ while True:
|
|
|
+ win = self.attack_area(index)
|
|
|
+ delay = random_delay()
|
|
|
+ time.sleep(delay)
|
|
|
+ if not win:
|
|
|
+ try:
|
|
|
+ idx = self.area_index.index(index)
|
|
|
+ index = self.area_index[idx + 1]
|
|
|
+ except IndexError:
|
|
|
+ self.flush_area_cache()
|
|
|
+ index = self.get_available_area()
|
|
|
+
|
|
|
+ def get_available_area(self):
|
|
|
+ """
|
|
|
+ 判断突破区域(忽略失败的目标)
|
|
|
+ :return: index
|
|
|
+ """
|
|
|
while True:
|
|
|
try:
|
|
|
- idx = self.area_index[0]
|
|
|
- if self.check_area(idx):
|
|
|
- break
|
|
|
+ index = self.area_index[0]
|
|
|
+ if self.check_area(index):
|
|
|
+ return index
|
|
|
self.area_index.pop(0)
|
|
|
except IndexError:
|
|
|
# 如果当前页面所有结界都攻破失败,则刷新结界列表。
|
|
|
- # TO-DO: 需要鼠标中键滑动接口(随机滑动,步长为2)
|
|
|
self.flush_area_cache()
|
|
|
|
|
|
- # 开始突破
|
|
|
- while True:
|
|
|
- result = self.attack_area(idx)
|
|
|
-
|
|
|
def check_area(self, index: int):
|
|
|
"""
|
|
|
检查该区域是否攻略失败
|
|
|
:return:
|
|
|
"""
|
|
|
f1, f2 = area_map[index].get("fail_sign")
|
|
|
+ f3 = area_map[index].get("finished_sign")
|
|
|
self.screenshot()
|
|
|
+ # 如果该区域已经被攻破则退出
|
|
|
+ # Ps: 这时候能打过的都打过了,没有能攻打的结界了
|
|
|
+ if self.appear(f3):
|
|
|
+ self.exit()
|
|
|
+
|
|
|
+ # 如果该区域攻略失败返回 False
|
|
|
if self.appear(f1, threshold=0.8) or self.appear(f2, threshold=0.8):
|
|
|
- logger.info('Area [%s] is futile attack, skip.' % index + 1)
|
|
|
+ logger.info('Area [%s] is futile attack, skip.' % str(index + 1))
|
|
|
return False
|
|
|
return True
|
|
|
|
|
|
def attack_area(self, index: int):
|
|
|
+ """
|
|
|
+ 检查该区域是否攻略失败
|
|
|
+ :return: 战斗成功(True) 或 战斗失败(False)
|
|
|
+ """
|
|
|
+ while True:
|
|
|
+ if self.has_ticket():
|
|
|
+ break
|
|
|
+ time.sleep(60)
|
|
|
self.screenshot()
|
|
|
- # TO-DO: 需要更改过程标识
|
|
|
- if not self.appear(RyouToppaAssets.I_RYOU_TOPPA, threshold=0.8):
|
|
|
+ if not self.appear(self.I_TOPPA_RECORD, threshold=0.8):
|
|
|
raise Exception("Current page is not RyouToppa.")
|
|
|
rcl = area_map[index].get("rule_click")
|
|
|
|
|
|
@@ -123,13 +169,19 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
|
|
|
while True:
|
|
|
self.screenshot()
|
|
|
# 如果进入战斗
|
|
|
- if self.appear():
|
|
|
- logger.info("Start attach area [%s]" % index + 1)
|
|
|
+ if self.appear(self.I_EXIT, threshold=0.8):
|
|
|
+ logger.info("Start attach area [%s]" % str(index + 1))
|
|
|
break
|
|
|
- # 如果该结界已经被攻打过(未刷新)则返回攻打失败
|
|
|
- if self.ocr_appear():
|
|
|
- return False
|
|
|
- if self.appear_then_click(RealmRaidAssets.I_FIRE, threshold=0.8, interval=1.5):
|
|
|
+ if self.appear_then_click(RealmRaidAssets.I_FIRE, threshold=0.8):
|
|
|
+ time.sleep(1.5)
|
|
|
+ self.screenshot()
|
|
|
+ self.appear_then_click(RealmRaidAssets.I_FIRE, threshold=0.8)
|
|
|
+ time.sleep(1.5)
|
|
|
+ self.screenshot()
|
|
|
+ # 点击两次点击后如果还出现进攻按钮则判断该区域已被攻打过
|
|
|
+ # 不使用 ocr 的原因是怕不好识别导致重复点击被检测
|
|
|
+ if self.appear(RealmRaidAssets.I_FIRE):
|
|
|
+ return False
|
|
|
continue
|
|
|
|
|
|
# 等待战斗结束
|
|
|
@@ -137,8 +189,18 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
|
|
|
return self.battle_wait(random_click_swipt_enable=True)
|
|
|
|
|
|
def flush_area_cache(self):
|
|
|
+ time.sleep(2)
|
|
|
self.area_index.extend(default_index)
|
|
|
- pass
|
|
|
+ duration = 0.352
|
|
|
+ count = random.randint(1, 3)
|
|
|
+ for i in range(count):
|
|
|
+ safe_pos_x = random.randint(540, 1000)
|
|
|
+ safe_pos_y = random.randint(320, 540)
|
|
|
+ p1 = (safe_pos_x, safe_pos_y)
|
|
|
+ p2 = (safe_pos_x, safe_pos_y - 101)
|
|
|
+ logger.info('Swipe %s -> %s, %s ' % (point2str(*p1), point2str(*p2), duration))
|
|
|
+ self.device.swipe_adb(p1, p2, duration=duration)
|
|
|
+ time.sleep(2)
|
|
|
|
|
|
def exit(self, status: int = 0):
|
|
|
if status == 0:
|
|
|
@@ -172,12 +234,28 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
|
|
|
self.ui_click_until_disappear(self.I_FALSE)
|
|
|
return False
|
|
|
|
|
|
+ def has_ticket(self) -> bool:
|
|
|
+ """
|
|
|
+ 如果没有票了,那么就返回False
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ # 21点后无限进攻机会
|
|
|
+ if datetime.now().hour >= 21:
|
|
|
+ return True
|
|
|
+ self.wait_until_appear(self.I_TOPPA_RECORD)
|
|
|
+ self.screenshot()
|
|
|
+ cu, res, total = self.O_NUMBER.ocr(self.device.image)
|
|
|
+ if cu == 0 and cu + res == total:
|
|
|
+ logger.warning(f'Execute round failed, no ticket')
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
from module.config.config import Config
|
|
|
from module.device.device import Device
|
|
|
|
|
|
- config = Config('oas1')
|
|
|
+ config = Config('oas2')
|
|
|
device = Device(config)
|
|
|
t = ScriptTask(config, device)
|
|
|
t.run()
|