abyssal_service.py (8876B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\abyss\client\abyssal_service.py 2 import codecs 3 import evetypes 4 import gametime 5 import localization 6 import logging 7 import random 8 import uthread2 9 from abyss.const import DEV_NAMES 10 from carbon.common.lib.const import SEC 11 from carbon.common.script.sys.service import CoreService 12 from eve.client.script.ui.inflight.shipHud.action_indication.hud_action_indication_controller import HudActionIndicationController, IndicationData 13 from eve.client.script.ui.shared.abyss.keyActivationWindow import KeyActivationWindow 14 from eve.client.script.ui.shared.abyss.AbyssJumpWindow import AbyssActivationWindow 15 from eve.common.script.sys.idCheckers import IsAbyssalSpaceSystem 16 from fsdBuiltData.common.graphicIDs import GetGraphicFile 17 from pvpFilaments.common.constants import DEFAULT_PVP_CONTENT_DURATION 18 from threadutils.scheduler import SimTimeScheduler 19 from objectives.client.objective_chain import ObjectiveChain 20 from objectives.common.objective_context import ObjectivesContext 21 MAX_CRIMEWATCH_TIMER_RETRIES = 30 22 logger = logging.getLogger(__name__) 23 EXPIRATION_INDICATION_DURATION = 8.0 24 ABYSSAL_COLLAPSE_NOTIFICATION_TIMERS_SECONDS = [300, 120, 30] 25 ABYSS_OBJECTIVE_CHAIN_ID = 95 26 27 class AbyssalService(CoreService): 28 __guid__ = 'svc.abyss' 29 __displayname__ = 'Abyssal Client Service' 30 __notifyevents__ = ['OnAbyssalLocationEntered', 31 'OnAddExpiryDurationForAbyssalContent', 32 'OnAbyssalContentFinished', 33 'OnAddExpiryDurationForAbyssalPvpContent', 34 'OnSessionChanged'] 35 __dependencies__ = ['michelle', 'sceneManager'] 36 37 def __init__(self): 38 CoreService.__init__(self) 39 self.nebula_graphic_id = None 40 self.active_content_id = None 41 self._expiry_notification_scheduler = SimTimeScheduler(name='abyss_expiry_notification') 42 self._expiry_notification_scheduler.start() 43 self.abyssal_fleet_disabled = None 44 self.current_difficulty_tier = 0 45 self.current_room_id = 0 46 self._context = None 47 self.objective_chain = None 48 49 def deploy_entrance_gate(self, item_id, game_mode_id): 50 abyssal_manager = sm.RemoteSvc('abyssalMgr') 51 abyssal_manager.AbyssalEntranceDeployment(item_id, game_mode_id) 52 53 def activate_entrance_gate(self, item_id): 54 abyssal_manager = sm.RemoteSvc('abyssalMgr') 55 abyssal_manager.AbyssalEntranceGateActivation(item_id) 56 57 def open_key_activation_window(self, key_item): 58 KeyActivationWindow.Open(item=key_item) 59 60 def open_abyss_jump_window(self, gateID): 61 AbyssActivationWindow.Open(item=gateID) 62 63 def _GetContext(self): 64 if self._context is None: 65 self._context = ObjectivesContext() 66 self._context.subscribe_to_message('on_objective_tasks_changed', self.on_objective_task_changed) 67 return self._context 68 69 def OnAbyssalLocationEntered(self, client_data): 70 context = self._GetContext() 71 logger.debug('OnAbyssalLocationEntered nebula client_data=%s', client_data) 72 self.active_content_id = client_data.get('content_id', None) 73 self.nebula_graphic_id = client_data.get('nebula_graphic_id', None) 74 try: 75 self.sceneManager.ReplaceNebulaFromResPath(self.get_nebula_res_path()) 76 except AttributeError: 77 logger.info('Tried replacing nebula, but could not access the scene') 78 79 self.current_difficulty_tier = client_data.get('difficulty_tier') 80 self.current_room_id = client_data.get('location_id') 81 context.set_values(rooms_completed=self.current_room_id - 1) 82 if not self.objective_chain: 83 self._start_objective_chain() 84 else: 85 context.send_message('stop_objective', 'destroy_lootable') 86 uthread2.sleep(2) 87 context.send_message('start_objective', 'destroy_lootable') 88 89 def on_objective_task_changed(self, key, value, objective, objective_id, task_id, reason): 90 if task_id == 'destroy_npcs' and reason == 'on_complete': 91 context = self._GetContext() 92 rooms_completed = context.get_value('rooms_completed') or 0 93 if rooms_completed + 1 >= context.get_value('num_rooms'): 94 context.update_value('rooms_completed', rooms_completed + 1) 95 96 def _start_objective_chain(self): 97 if self.objective_chain: 98 return 99 context = self._GetContext() 100 self.objective_chain = ObjectiveChain(content_id=ABYSS_OBJECTIVE_CHAIN_ID, context=context) 101 self.objective_chain.start() 102 sm.GetService('infoPanel').UpdateAbyssPanel() 103 104 def get_current_difficulty_tier(self): 105 return self.current_difficulty_tier 106 107 def get_current_room_id(self): 108 return self.current_room_id 109 110 def get_nebula_graphic_id(self): 111 return self.nebula_graphic_id 112 113 def get_nebula_res_path(self): 114 if self.nebula_graphic_id: 115 logger.debug('returning nebula respath for graphic id %s', self.nebula_graphic_id) 116 return GetGraphicFile(self.nebula_graphic_id) 117 118 def OnAddExpiryDurationForAbyssalContent(self, end_time): 119 self._add_expiry_messages_to_event_scheduler(end_time) 120 self._set_abyssal_timer(end_time) 121 122 def OnAddExpiryDurationForAbyssalPvpContent(self, end_time): 123 self._add_expiry_messages_to_event_scheduler(end_time) 124 self._set_abyssal_pvp_timer(end_time) 125 126 def _set_abyssal_timer(self, end_time): 127 info_panel_service = sm.GetService('infoPanel') 128 self._set_crimewatch_timer(info_panel_service, end_time, 'SetAbyssalTimer') 129 130 def _set_abyssal_pvp_timer(self, end_time): 131 info_panel_service = sm.GetService('infoPanel') 132 self._set_crimewatch_timer(info_panel_service, end_time, 'SetAbyssalPvpTimer') 133 134 def _set_crimewatch_timer(self, info_panel_service, end_time, set_timer_function_name): 135 start_time = end_time - DEFAULT_PVP_CONTENT_DURATION 136 context = self._GetContext() 137 context.update_value('timer', {'end_time': end_time, 138 'start_time': start_time}) 139 remaining_tries = MAX_CRIMEWATCH_TIMER_RETRIES 140 while info_panel_service.combatTimerContainer is None and remaining_tries > 0: 141 uthread2.sleep(1.0) 142 remaining_tries -= 1 143 144 if info_panel_service.combatTimerContainer: 145 set_timer_function = getattr(info_panel_service.combatTimerContainer, set_timer_function_name) 146 set_timer_function(end_time) 147 148 def _add_expiry_messages_to_event_scheduler(self, end_time): 149 logger.debug('adding expiry messages to event scheduler') 150 self._expiry_notification_scheduler.clear_all_events() 151 space_manager = sm.GetService('space') 152 for notification_time_seconds in ABYSSAL_COLLAPSE_NOTIFICATION_TIMERS_SECONDS: 153 message_time = gametime.GetSecondsUntilSimTime(end_time - notification_time_seconds * SEC) * SEC 154 self._expiry_notification_scheduler.enter_relative_event(message_time, 0, self._display_expiry_message, (space_manager, notification_time_seconds)) 155 156 def _display_expiry_message(self, space_manager, notification_time_seconds): 157 HudActionIndicationController.get_instance().set_temporary_indication(IndicationData(localization.GetByLabel('UI/Abyss/AbyssalCollapseWarningHeader'), localization.GetByLabel('UI/Abyss/AbyssalCollapseWarningSubject', time=notification_time_seconds)), duration=EXPIRATION_INDICATION_DURATION) 158 159 def OnAbyssalContentFinished(self, content_id, timer_type): 160 if not self.is_active_content(content_id): 161 return 162 self._expiry_notification_scheduler.clear_all_events() 163 self._context = None 164 165 def get_mangled_system_name(self, solar_system_id, char_id): 166 state = random.getstate() 167 random.seed(solar_system_id + char_id) 168 name = random.choice(DEV_NAMES) 169 random.setstate(state) 170 return codecs.encode(name, 'rot_13') 171 172 def is_active_content(self, content_id): 173 return self.active_content_id == content_id 174 175 def OnSessionChanged(self, isremote, session, change): 176 if 'solarsystemid2' not in change: 177 return 178 from_solar_system_id, to_solar_system_id = change['solarsystemid2'] 179 if self._is_logging_in_to_abyssal_system(from_solar_system_id, to_solar_system_id): 180 abyssal_manager = sm.RemoteSvc('abyssalMgr') 181 abyssal_manager.ClientIsReady() 182 if not IsAbyssalSpaceSystem(to_solar_system_id): 183 if self.objective_chain: 184 self.objective_chain.stop() 185 self.objective_chain = None 186 sm.GetService('infoPanel').UpdateAbyssPanel() 187 188 def _is_logging_in_to_abyssal_system(self, from_solar_system_id, to_solar_system_id): 189 return from_solar_system_id is None and IsAbyssalSpaceSystem(to_solar_system_id)