Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Gear Code based fast equipment exchange for GemsFarming #3491

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/cn/equipment/EMPTY_SHIP_R.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_CLEAR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_CONFIRM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_ENTER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_ENTRANCE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_EQUIP_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_EQUIP_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_EQUIP_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_EQUIP_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_EQUIP_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_EQUIP_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_EXPORT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_PAGE_CHECK.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cn/equipment/EQUIPMENT_CODE_TEXTBOX.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EMPTY_SHIP_R.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_CLEAR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_CONFIRM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_ENTER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_ENTRANCE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_EQUIP_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_EQUIP_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_EQUIP_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_EQUIP_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_EQUIP_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_EQUIP_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/en/equipment/EQUIPMENT_CODE_EXPORT.png
Binary file added assets/en/equipment/EQUIPMENT_CODE_PAGE_CHECK.png
Binary file added assets/en/equipment/EQUIPMENT_CODE_TEXTBOX.png
Binary file added assets/jp/equipment/EMPTY_SHIP_R.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_CLEAR.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_CONFIRM.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_ENTER.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_ENTRANCE.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_EQUIP_0.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_EQUIP_1.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_EQUIP_2.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_EQUIP_3.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_EQUIP_4.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_EQUIP_5.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_EXPORT.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_PAGE_CHECK.png
Binary file added assets/jp/equipment/EQUIPMENT_CODE_TEXTBOX.png
Binary file added assets/tw/equipment/EMPTY_SHIP_R.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_CLEAR.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_CONFIRM.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_ENTER.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_ENTRANCE.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_EQUIP_0.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_EQUIP_1.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_EQUIP_2.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_EQUIP_3.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_EQUIP_4.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_EQUIP_5.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_EXPORT.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_PAGE_CHECK.png
Binary file added assets/tw/equipment/EQUIPMENT_CODE_TEXTBOX.png
1 change: 1 addition & 0 deletions config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
"CommonCV": "any",
"ChangeVanguard": "ship",
"CommonDD": "any",
"EquipmentCode": "DD: null\nbogue: null\nhermes: null\nlangley: null\nranger: null",
"CommissionLimit": true
},
"Campaign": {
Expand Down
72 changes: 51 additions & 21 deletions module/campaign/gems_farming.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from module.campaign.run import CampaignRun
from module.combat.assets import BATTLE_PREPARATION
from module.equipment.assets import *
from module.equipment.equipment_code import EquipmentCodeHandler
from module.equipment.fleet_equipment import FleetEquipment
from module.exception import CampaignEnd, ScriptError
from module.handler.assets import AUTO_SEARCH_MAP_OPTION_OFF
Expand Down Expand Up @@ -67,7 +68,46 @@ def handle_combat_low_emotion(self):
raise CampaignEnd('Emotion withdraw')


class GemsFarming(CampaignRun, FleetEquipment, Dock):
class GemsEquipmentHandler(EquipmentCodeHandler):
def __init__(self, config, device=None, task=None):
super().__init__(config=config,
device=device,
task=task,
key="GemsFarming.GemsFarming.EquipmentCode",
ships=['DD', 'bogue', 'hermes', 'langley', 'ranger'])

def current_ship(self, skip_first_screenshot=True):
"""
Reuse templates in module.retire.assets,
which needs different rescaling to match each current flagship.

Pages:
in: gear_code
"""
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()

# End
if not self.appear(EMPTY_SHIP_R):
break
else:
logger.info('Waiting ship icon loading.')

if TEMPLATE_BOGUE.match(self.device.image, scaling=1.46): # image has rotation
return 'bogue'
if TEMPLATE_HERMES.match(self.device.image, scaling=124/89):
return 'hermes'
if TEMPLATE_RANGER.match(self.device.image, scaling=4/3):
return 'ranger'
if TEMPLATE_LANGLEY.match(self.device.image, scaling=25/21):
return 'langley'
return 'DD'


class GemsFarming(CampaignRun, Dock, FleetEquipment, GemsEquipmentHandler):

def load_campaign(self, name, folder='campaign_main'):
super().load_campaign(name, folder)
Expand Down Expand Up @@ -104,65 +144,55 @@ def fleet_to_attack(self):

def flagship_change(self):
"""
Change flagship and flagship's equipment
If config.GemsFarming_CommonCV == 'any', only change auxiliary equipment
Change flagship and flagship's equipment using gear code

Returns:
bool: True if flagship changed.
"""

if self.config.GemsFarming_CommonCV == 'any':
index_list = range(3, 5)
else:
index_list = range(0, 5)
logger.hr('Change flagship', level=1)
logger.attr('ChangeFlagship', self.config.GemsFarming_ChangeFlagship)
self.fleet_enter(self.fleet_to_attack)
if self.change_flagship_equip:
logger.hr('Record flagship equipment', level=2)
logger.hr('Unmount flagship equipments', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER_FLAGSHIP)
self.ship_equipment_record_image(index_list=index_list)
self.ship_equipment_take_off()
self.clear_all_equip()
self.fleet_back()

logger.hr('Change flagship', level=2)
success = self.flagship_change_execute()

if self.change_flagship_equip:
logger.hr('Equip flagship equipment', level=2)
logger.hr('Mount flagship equipments', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER_FLAGSHIP)
self.ship_equipment_take_off()
self.ship_equipment_take_on_image(index_list=index_list)
self.apply_equip_code()
self.fleet_back()

return success

def vanguard_change(self):
"""
Change vanguard and vanguard's equipment
Change vanguard and vanguard's equipment using gear code

Returns:
bool: True if vanguard changed
"""

logger.hr('Change vanguard', level=1)
logger.attr('ChangeVanguard', self.config.GemsFarming_ChangeVanguard)
self.fleet_enter(self.fleet_to_attack)
if self.change_vanguard_equip:
logger.hr('Record vanguard equipment', level=2)
logger.hr('Unmount vanguard equipments', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER)
self.ship_equipment_record_image()
self.ship_equipment_take_off()
self.clear_all_equip()
self.fleet_back()

logger.hr('Change vanguard', level=2)
success = self.vanguard_change_execute()

if self.change_vanguard_equip:
logger.hr('Equip vanguard equipment', level=2)
logger.hr('Mount vanguard equipments', level=2)
self.fleet_enter_ship(FLEET_DETAIL_ENTER)
self.ship_equipment_take_off()
self.ship_equipment_take_on_image()
self.apply_equip_code()
self.fleet_back()

return success
Expand Down
5 changes: 5 additions & 0 deletions module/config/argument/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,11 @@
"z20_or_z21"
]
},
"EquipmentCode": {
"type": "textarea",
"value": "DD: null\nbogue: null\nhermes: null\nlangley: null\nranger: null",
"mode": "yaml"
},
"CommissionLimit": {
"type": "checkbox",
"value": true
Expand Down
9 changes: 9 additions & 0 deletions module/config/argument/argument.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ GemsFarming:
CommonDD:
value: any
option: [ any, favourite, aulick_or_foote , cassin_or_downes, z20_or_z21 ]
EquipmentCode:
type: textarea
mode: yaml
value: |-
DD: null
bogue: null
hermes: null
langley: null
ranger: null
CommissionLimit: true

# ==================== Event ====================
Expand Down
1 change: 1 addition & 0 deletions module/config/config_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class GeneratedConfig:
GemsFarming_CommonCV = 'any' # any, langley, bogue, ranger, hermes
GemsFarming_ChangeVanguard = 'ship' # disabled, ship, ship_equip
GemsFarming_CommonDD = 'any' # any, favourite, aulick_or_foote, cassin_or_downes, z20_or_z21
GemsFarming_EquipmentCode = 'DD: null\nbogue: null\nhermes: null\nlangley: null\nranger: null'
GemsFarming_CommissionLimit = True

# Group `EventGeneral`
Expand Down
4 changes: 4 additions & 0 deletions module/config/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,10 @@
"cassin_or_downes": "Cassin or Downes",
"z20_or_z21": "Z20 or Z21"
},
"EquipmentCode": {
"name": "Gear Code",
"help": "Only works when 'Change Ship + Gears' is chosen.\nWhen substituting down CV/CVL/DD, if corresponding gear code is not provided, alas will export it\nWhen substituting up corresponding CV/CVL/DD, if corresponding gear code is not provided, alas will use exported gear code from previous ship; otherwise alas will use gear code in the config\nBluestacks users need to enable virtual keyboard first.\nSee https://support.bluestacks.com/hc/en-us/articles/360061968892-How-to-use-a-virtual-on-screen-keyboard-on-BlueStacks-5"
},
"CommissionLimit": {
"name": "Prevent Too Many Urgent Commissions",
"help": "When running 7x24, prevent having a lot of urgent commissions and not being able to complete daily commissions. It is recommended to select only short-terms and high-yields in the commission filter"
Expand Down
4 changes: 4 additions & 0 deletions module/config/i18n/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,10 @@
"cassin_or_downes": "GemsFarming.CommonDD.cassin_or_downes",
"z20_or_z21": "GemsFarming.CommonDD.z20_or_z21"
},
"EquipmentCode": {
"name": "GemsFarming.EquipmentCode.name",
"help": "GemsFarming.EquipmentCode.help"
},
"CommissionLimit": {
"name": "GemsFarming.CommissionLimit.name",
"help": "GemsFarming.CommissionLimit.help"
Expand Down
4 changes: 4 additions & 0 deletions module/config/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,10 @@
"cassin_or_downes": "卡辛或唐斯",
"z20_or_z21": "Z20或Z21"
},
"EquipmentCode": {
"name": "装备码",
"help": "仅当选择“更换舰船 + 装备”时生效。\n在换下舰船时,若设置里当前舰船装备码为null则会导出;在换上舰船时,若设置里当前舰船装备码为null则会使用上一艘舰船导出的装备码,否则使用设置里的装备码\n蓝叠模拟器用户需要先开启虚拟键盘,详见https://support.bluestacks.com/hc/zh-tw/articles/360061968892-%E5%A6%82%E4%BD%95%E5%9C%A8-BlueStacks-5-%E4%B8%8A%E4%BD%BF%E7%94%A8%E5%B0%8F%E9%8D%B5%E7%9B%A4-%E8%99%9B%E6%93%AC%E9%8D%B5%E7%9B%A4"
},
"CommissionLimit": {
"name": "防止紧急委托数量过多",
"help": "在7x24运行时防止紧急委托数量过多做不完每日委托,建议在委托过滤器仅选择短时长高收益委托"
Expand Down
4 changes: 4 additions & 0 deletions module/config/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,10 @@
"cassin_or_downes": "卡辛或唐斯",
"z20_or_z21": "Z20或Z21"
},
"EquipmentCode": {
"name": "裝備碼",
"help": "僅當選擇「更換艦船 + 裝備」時生效。\n在換下艦船時,若設定裏當前艦船裝備碼為null則會導出;在換上艦船時,若設置裏當前艦船裝備碼為null則會使用上一艘艦船導出的裝備碼,否則使用設定裏的裝備碼\n藍疊模擬器用戶需要先開啟虛擬鍵盤,詳見https://support.bluestacks.com/hc/zh-tw/articles/360061968892-%E5%A6%82%E4%BD%95%E5%9C%A8-BlueStacks-5-%E4%B8%8A%E4%BD%BF%E7%94%A8%E5%B0%8F%E9%8D%B5%E7%9B%A4-%E8%99%9B%E6%93%AC%E9%8D%B5%E7%9B%A4"
},
"CommissionLimit": {
"name": "防止緊急委託數量過多",
"help": "在7x24運行時防止緊急委託數量過多做不完每日委託,建議在委託過濾器僅選擇短時長高收益委託"
Expand Down
3 changes: 2 additions & 1 deletion module/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from module.config.utils import get_server_next_update
from module.device.app_control import AppControl
from module.device.control import Control
from module.device.input import Input
from module.device.screenshot import Screenshot
from module.exception import (EmulatorNotRunningError, GameNotRunningError, GameStuckError, GameTooManyClickError,
RequestHumanTakeover)
Expand Down Expand Up @@ -61,7 +62,7 @@ def format_(file, line, func):
logger.info('Function calls:' + ''.join(func_list))


class Device(Screenshot, Control, AppControl):
class Device(Screenshot, Control, AppControl, Input):
_screen_size_checked = False
detect_record = set()
click_record = collections.deque(maxlen=15)
Expand Down
19 changes: 19 additions & 0 deletions module/device/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from module.device.method.uiautomator_2 import Uiautomator2
from module.logger import logger


class Input(Uiautomator2):
def ime_shown(self) -> bool:
_, shown = self.u2_current_ime()
return shown

def text_input_and_confirm(self, text: str, clear: bool=False):
for fail_count in range(3):
try:
self.u2_send_keys(text=text, clear=clear)
self.u2_send_action(6)
break
except EnvironmentError as e:
if fail_count >= 2:
raise e
logger.exception(str(e) + f'Retrying {fail_count + 1}/3')
23 changes: 23 additions & 0 deletions module/device/method/uiautomator_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,26 @@ def u2_shell_background(self, cmdline, timeout=10) -> ShellBackgroundResponse:
description=resp.get('description', '')
)
return resp

def u2_set_fastinput_ime(self, enable: bool):
self.u2.set_fastinput_ime(enable)

def u2_current_ime(self):
return self.u2.current_ime()

def u2_send_keys(self, text: str, clear: bool=False):
self.u2.send_keys(text=text, clear=clear)

# Ref: https://uiautomator2.readthedocs.io/en/latest/api.html#uiautomator2.Session.send_action
def u2_send_action(self, code):
self.u2.send_action(code=code)

def u2_clear_text(self):
self.u2.clear_text()

@property
def clipboard(self):
return self.u2.clipboard

def set_clipboard(self, text, label=None):
return self.u2.set_clipboard(text=text, label=label)
Loading