Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
events added
Browse files Browse the repository at this point in the history
  • Loading branch information
tmarenko committed Jul 24, 2021
1 parent a984969 commit c097f26
Show file tree
Hide file tree
Showing 5 changed files with 716 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/game/missions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
FriendsAndEnemies, WeatheringTheStorm, Blindsided, DarkAdvent, IncreasingDarkness, RoadToMonastery, \
MysteriousAmbush, MonasteryInTrouble, PowerOfTheDark, StingOfTheScorpion, SelfDefenseProtocol, LegacyOfBlood, \
PlayingHero, GoldenGods
from .events import EventWorldBoss, WorldEvent
from .giant_boss_raid import GiantBossRaid
from .legendary_battle import LegendaryBattle
from .squad_battle import SquadBattle
Expand Down
217 changes: 217 additions & 0 deletions lib/game/missions/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
from lib.game.battle_bot import ManualBattleBot
from lib.game.missions.missions import Missions
from lib.game.missions.world_boss import WorldBoss
from lib.functions import wait_until, r_sleep, is_strings_similar
import lib.logger as logging

logger = logging.get_logger(__name__)


class EventMissions(Missions):
"""Class for working with Event missions."""

def __init__(self, game):
"""Class initialization.
:param game.Game game: instance of the game.
"""
super().__init__(game, "")

def find_event_ui_by_name(self, name):
"""Find UI element of Event by it's name.
:param name: name of event.
:return: UI element of event in Event List.
"""
self._drag_event_list_to_the_bottom()
for ui_index in range(1, 5):
event_ui = self.game.ui[f"EVENT_BUTTON_1_{ui_index}"]
event_text = self.emulator.get_screen_text(event_ui)
logger.debug(f"Found text inside event list: {event_text}")
if is_strings_similar(event_text, name):
return event_ui
self._drag_event_list_to_the_top()
for ui_index in range(1, 5):
event_ui = self.game.ui[f"EVENT_BUTTON_2_{ui_index}"]
event_text = self.emulator.get_screen_text(event_ui)
logger.debug(f"Found text inside event list: {event_text}")
if is_strings_similar(event_text, name):
return event_ui

def _drag_event_list_to_the_top(self):
"""Drag Event List to the top."""
logger.debug("Dragging Event list to the top.")
self.emulator.drag(self.ui['EVENT_LIST_DRAG_FROM'].button,
self.ui['EVENT_LIST_DRAG_TO'].button)
r_sleep(1)

def _drag_event_list_to_the_bottom(self):
"""Drag Event List to the bottom."""
logger.debug("Dragging Event list to the bottom.")
self.emulator.drag(self.ui['EVENT_LIST_DRAG_TO'].button,
self.ui['EVENT_LIST_DRAG_FROM'].button)
r_sleep(1)


class EventWorldBoss(EventMissions, WorldBoss):
"""Class for working with Event World Boss."""

EVENT_NAME = "Event World Boss\nEVENT"

def __init__(self, game):
"""Class initialization.
:param game.Game game: instance of the game.
"""
super(EventMissions, self).__init__(game)
self._stages = 5

@property
def battle_over_conditions(self):
def allies():
return self.emulator.is_ui_element_on_screen(self.ui['EVENT_WORLD_BOSS_ALLIES'])

def cannot_enter():
if self.emulator.is_ui_element_on_screen(self.ui['EVENT_WORLD_BOSS_LIMIT_REACHED']):
logger.debug("Reached limit of missions.")
self._stages = 0
self.emulator.click_button(self.ui['EVENT_WORLD_BOSS_LIMIT_REACHED'])
return True

return [allies, cannot_enter]

def open_event_world_boss(self):
"""Open Event World Boss from Event List."""
self.game.go_to_main_menu()
event_ui = self.find_event_ui_by_name(self.EVENT_NAME)
if not event_ui:
logger.info("Can't find Event World Boss, probably event isn't on right now.")
return
self.emulator.click_button(event_ui.button)
return wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['EVENT_WORLD_BOSS_LABEL'])

def complete_event_world_boss(self):
"""Complete all available stages in Event World Boss."""
self.open_event_world_boss()
if not self.emulator.is_ui_element_on_screen(self.ui['EVENT_WORLD_BOSS_ENTER']):
logger.info("No available Event World Boss battles.")
return self.game.go_to_main_menu()
self.emulator.click_button(self.ui['EVENT_WORLD_BOSS_ENTER'].button)
while self._stages > 0:
if not self._start_world_boss_battle():
logger.error("Failed to start battle. Returning to main menu.")
return self.game.go_to_main_menu()
self._stages -= 1
if self._stages > 0:
self.press_repeat_button()
else:
self.press_home_button(home_button="EVENT_WORLD_BOSS_HOME_BUTTON")
logger.info("No more stages.")

def press_repeat_button(self, repeat_button_ui='EVENT_WORLD_BOSS_REPEAT_BUTTON', start_button_ui='WB_SET_TEAM'):
"""Press repeat button of the mission."""
logger.debug(f"Clicking REPEAT button with UI Element: {repeat_button_ui}.")
self.emulator.click_button(self.ui[repeat_button_ui].button)
while not self.emulator.is_ui_element_on_screen(ui_element=self.ui[start_button_ui]):
if self.emulator.is_ui_element_on_screen(self.ui['EVENT_WORLD_BOSS_LIMIT_REACHED']):
logger.debug("Reached limit of missions.")
self._stages = 0
self.emulator.click_button(self.ui['EVENT_WORLD_BOSS_LIMIT_REACHED'])
return True
self.close_after_mission_notifications(timeout=1)
return True

def _start_world_boss_battle(self, check_inventory=True):
"""Start World Boss battle."""
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3, ui_element=self.ui['WB_SET_TEAM']):
self._deploy_characters()
self.emulator.click_button(self.ui['WB_SET_TEAM'].button)
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['WB_UNAVAILABLE_CHARACTER']):
logger.warning("Stopping battle because your team has unavailable characters.")
self.emulator.click_button(self.ui['WB_UNAVAILABLE_CHARACTER'].button)
return False
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['WB_LOW_VALOR_OR_ATTACK']):
self.emulator.click_button(self.ui['WB_LOW_VALOR_OR_ATTACK'].button)
# Second notification about ATK is similar
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['WB_LOW_VALOR_OR_ATTACK']):
self.emulator.click_button(self.ui['WB_LOW_VALOR_OR_ATTACK'].button)
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3, ui_element=self.ui['WB_START_BUTTON']):
self._deploy_allies()
self.emulator.click_button(self.ui['WB_START_BUTTON'].button)
if check_inventory and wait_until(self.emulator.is_ui_element_on_screen, timeout=2,
ui_element=self.ui['INVENTORY_FULL']):
logger.warning("Stopping battle because inventory is full.")
self.emulator.click_button(self.ui['INVENTORY_FULL'].button)
self.stages *= 0
return False
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['WB_NOT_FULL_ALLY_TEAM']):
self.emulator.click_button(self.ui['WB_NOT_FULL_ALLY_TEAM'].button)
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['WB_EXCLUDE_CHARACTERS_FROM_ALLIES']):
self.emulator.click_button(self.ui['WB_EXCLUDE_CHARACTERS_FROM_ALLIES'].button)
ManualBattleBot(self.game, self.battle_over_conditions).fight(move_around=True)
return True
logger.warning("Failed to locate START button.")
return False
logger.warning("Failed to set team.")


class WorldEvent(EventMissions):
"""Class for working with World Event."""

EVENT_NAME = "WORLD EVENT\nAvailable Now"

@property
def battle_over_conditions(self):
def total_score():
if self.emulator.is_ui_element_on_screen(self.ui['EVENT_WORLD_BATTLE_TOTAL_SCORE']):
self.emulator.click_button(self.ui['EVENT_WORLD_BATTLE_TOTAL_SCORE'].button)
return True

return [total_score]

def open_world_event(self):
"""Open World Event in Event List."""
self.game.go_to_main_menu()
event_ui = self.find_event_ui_by_name(self.EVENT_NAME)
if not event_ui:
logger.info("Can't find World Event, probably event isn't on right now.")
return
self.emulator.click_button(event_ui.button)
return wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['EVENT_WORLD_LABEL'])

def _get_ready_to_battle(self):
"""Getting ready to participate in World Event."""
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['EVENT_WORLD_BATTLE_READY_BUTTON']):
logger.debug("Getting ready to battle.")
self.emulator.click_button(self.ui['EVENT_WORLD_BATTLE_READY_BUTTON'].button)
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['EVENT_WORLD_SELECT_BATTLE_READY']):
logger.debug("Selecting battle system.")
self.emulator.click_button(self.ui['EVENT_WORLD_SELECT_BATTLE_READY'].button)
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['EVENT_WORLD_SELECT_BATTLE_READY_OK']):
logger.debug("System selected.")
self.emulator.click_button(self.ui['EVENT_WORLD_SELECT_BATTLE_READY_OK'].button)

def complete_world_event(self):
"""Complete available stage in World Event."""
self.open_world_event()
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['EVENT_WORLD_LOBBY_READY_BUTTON']):
logger.debug("Entering into team selection lobby.")
self.emulator.click_button(self.ui['EVENT_WORLD_LOBBY_READY_BUTTON'].button)
self._get_ready_to_battle()
if wait_until(self.emulator.is_ui_element_on_screen, timeout=3,
ui_element=self.ui['EVENT_WORLD_BATTLE_START_BUTTON']):
self.emulator.click_button(self.ui['EVENT_WORLD_BATTLE_START_BUTTON'].button)
ManualBattleBot(self.game, self.battle_over_conditions).fight(move_around=True)
self.emulator.click_button(self.ui['EVENT_WORLD_BATTLE_TOTAL_SCORE'].button)
self.game.go_to_main_menu()
2 changes: 1 addition & 1 deletion lib/game/missions/world_boss.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def start_missions(self, mode=MODE.ULTIMATE, difficulty=0, boss=BOSS.TODAYS_BOSS
def _start_world_boss_battle(self, check_inventory=True):
"""Start World Boss battle.
:param: deploy characters or not.
:param: check_inventory check for full inventory or not.
"""
self.emulator.click_button(self.ui['WB_READY_BUTTON'].button)
self.close_mission_notifications()
Expand Down
38 changes: 37 additions & 1 deletion lib/gui/widgets/queue_item_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def clear_parameters(self):
parameters.pop("all_stages") # Remove `all_stages` kwarg anyway
if "action" in parameters.keys():
parameters.pop("action")
if "event" in parameters.keys():
parameters.pop("event")
return parameters

def get_executor(self):
Expand Down Expand Up @@ -66,6 +68,8 @@ def name(self):
if hour_offset:
additional_text += f"[-{hour_offset} hour(s)]"
return f"[Action] {self.mode_name.title()} {additional_text}"
if self.parameters.get("event"):
return f"[Event] {self.mode_name.title()} {additional_text}"
farm_bios = self.parameters.get("farm_shifter_bios")
battle = self.parameters.get("battle")
mission_mode = self.parameters.get("mode")
Expand Down Expand Up @@ -158,6 +162,9 @@ def __init__(self, game):
daily_rewards = _DailyRewards(game)
collect_free_energy = _CollectFreeEnergy(game)
collect_energy_via_points = _CollectEnergyViaAssemblePoints(game)
event_world_boss = _EventWorldBoss(game)
world_event = _WorldEvent(game)
self.events = [event_world_boss, world_event]
self.actions = [restart_game, daily_trivia, daily_rewards, comic_cards, custom_gear, friends_send_all,
friends_acquire_all, alliance_check_in, collect_free_energy, collect_energy_via_points,
wait_boost_points, wait_max_energy, wait_daily_reset, reset_world_boss,
Expand All @@ -171,14 +178,15 @@ def __init__(self, game):
friends_and_enemies, weathering_the_storm, blindsided, dark_advent, increasing_darkness,
road_to_monastery, mysterious_ambush, monastery_in_trouble, power_of_the_dark, giant_boss_raid,
sting_of_the_scorpion, self_defense_protocol, legacy_of_blood, playing_hero, golden_gods,
*self.actions]
*self.actions, *self.events]
self.mode_names = [mode.mode_name for mode in self.modes]
self.queue_item = None
self.current_mode = None
self.editor_button_box.accepted.connect(self.render_queue_item)

menu_dict = {
"[ACTIONS]": self.actions,
"[EVENTS]": self.events,
"EPIC QUESTS": {
"DARK REIGN": [playing_hero, golden_gods, sting_of_the_scorpion, self_defense_protocol,
legacy_of_blood],
Expand Down Expand Up @@ -516,6 +524,20 @@ def action(*args, **kwargs):
return action, {**self.render_execution_params(), "action": True}


class Event(Action):
"""Class for working with in-game mission events."""

def render_executable(self):
"""Render function and settings for event."""
event_executable = self.action_executable # Only function without class reference (GUI cannot be pickled)

@reset_emulator_and_logger(game=self.game)
def event(*args, **kwargs):
return event_executable(*args, **kwargs)

return event, {**self.render_execution_params(), "event": True}


class _RestartGame(Action):

def __init__(self, game):
Expand Down Expand Up @@ -1346,3 +1368,17 @@ def __init__(self, game):
self.mode_settings.append(GameMode.ModeSetting(setting_type=GameMode.ModeSetting.MultiCheckbox,
setting_key="world_boss",
values_dict=self.world_bosses))


class _EventWorldBoss(Event):

def __init__(self, game):
self.event_world_boss = missions.EventWorldBoss(game)
super().__init__(game, "EVENT WORLD BOSS", self.event_world_boss.complete_event_world_boss)


class _WorldEvent(Event):

def __init__(self, game):
self.event_world_boss = missions.WorldEvent(game)
super().__init__(game, "WORLD EVENT", self.event_world_boss.complete_world_event)
Loading

0 comments on commit c097f26

Please sign in to comment.