fwWarzoneSvc.py (8265B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\fwWarzoneSvc.py 2 import logging 3 import random 4 from caching import Memoize 5 from carbon.common.script.sys.service import Service 6 from factionwarfare.maptags.client.mapTagDataProvider import MapTagDataProvider 7 from fwwarzone.heroNotifications import SystemFlipped, SystemChangedAdjacency, ObjectiveCompletedInSystem, BattlefieldWon, DungeonConquered, DungeonDefended 8 from locks import TempLock 9 from maptags.client.consumer import MapTagNonRefreshingConsumer 10 OCCUPATION_STATE_UNKNOWN = (None, None) 11 12 class FwWarzoneSvc(Service): 13 __guid__ = 'svc.fwWarzoneSvc' 14 __displayname__ = 'FW Warzone client service' 15 __startupdependencies__ = ['machoNet', 'heroNotification'] 16 __notifyevents__ = ['OnSessionChanged', 17 'OnWarzoneOccupationStateUpdated', 18 'OnFwObjectiveCompletedInSolarSystem', 19 'OnFwScoreboardWon', 20 'OnFacWarDungeonCompleted'] 21 _localOccupationSystemAndState = OCCUPATION_STATE_UNKNOWN 22 _currentBattlefields = set() 23 _mapTagDataProvider = None 24 25 def _OccupationStateLock(self): 26 return self.LockedService('OccupationState') 27 28 def OnSessionChanged(self, isremote, session, change): 29 if 'solarsystemid2' in change: 30 self._localOccupationSystemAndState = OCCUPATION_STATE_UNKNOWN 31 32 def GetMapTagProvider(self): 33 if self._mapTagDataProvider is None: 34 with TempLock('fwWarzoneSvc:GetMapTagProvider'): 35 if self._mapTagDataProvider is None: 36 mapTagConsumer = MapTagNonRefreshingConsumer() 37 self._mapTagDataProvider = MapTagDataProvider(mapTagConsumer) 38 return self._mapTagDataProvider 39 40 def GetLocalOccupationState(self): 41 if self._localOccupationSystemAndState[0] != session.solarsystemid2: 42 with self._OccupationStateLock(): 43 if self._localOccupationSystemAndState[0] != session.solarsystemid2: 44 self.LogInfo('GetLocalOccupationState - localOccupationState is unknown - asking the server') 45 solarsystemID, occupationState = sm.RemoteSvc('fwWarzoneSolarsystem').GetLocalOccupationState() 46 if solarsystemID != session.solarsystemid2: 47 solarsystemID, occupationState = sm.RemoteSvc('fwWarzoneSolarsystem').GetLocalOccupationState() 48 if solarsystemID == session.solarsystemid2: 49 self._localOccupationSystemAndState = (solarsystemID, occupationState) 50 else: 51 raise RuntimeError('fwWarzoneSvc.GetLocalOccupationState failed to get state from server despite retrying') 52 return self._localOccupationSystemAndState[1] 53 54 def GetOccupationState(self, solarsystemID): 55 if solarsystemID == session.solarsystemid2: 56 return self.GetLocalOccupationState() 57 occupationStatesBySolarsystemByWarzone = self.GetAllOccupationStates() 58 for occupationStatesBySolarsystem in occupationStatesBySolarsystemByWarzone.itervalues(): 59 if solarsystemID in occupationStatesBySolarsystem: 60 return occupationStatesBySolarsystem[solarsystemID] 61 62 def GetAllOccupationStates(self): 63 return sm.RemoteSvc('fwWarzoneSolarsystem').GetAllWarzonesOccupationStates() 64 65 def GetAllOccupationStatesUncached(self): 66 return sm.RemoteSvc('fwWarzoneSolarsystem').GetAllWarzonesOccupationStatesUncached() 67 68 def OnWarzoneOccupationStateUpdated(self, solarsystemID, newOccupationState): 69 self.LogInfo('fwWarzoneSvc.OnWarzoneOccupationStateUpdated', solarsystemID, newOccupationState) 70 with self._OccupationStateLock(): 71 if solarsystemID != session.solarsystemid2: 72 return 73 if self._localOccupationSystemAndState == (solarsystemID, newOccupationState): 74 return 75 oldOccupationState = self._localOccupationSystemAndState[1] 76 self._localOccupationSystemAndState = (solarsystemID, newOccupationState) 77 sm.ScatterEvent('OnWarzoneOccupationStateUpdated_Local') 78 if oldOccupationState: 79 if oldOccupationState.occupierID != newOccupationState.occupierID: 80 self.ShowFlipFanfare(solarsystemID, newOccupationState) 81 elif oldOccupationState.adjacencyState != newOccupationState.adjacencyState: 82 self.ShowChangedAdjacency(solarsystemID, newOccupationState) 83 84 def OnFwObjectiveCompletedInSolarSystem(self, solarSystemID, targetFactionID, objectiveMode): 85 86 def PlayVideo(parent, cancellation_token): 87 ObjectiveCompletedInSystem(parent, solarSystemID, targetFactionID, objectiveMode) 88 89 self.heroNotification.play(PlayVideo, 1) 90 91 def OnFwScoreboardWon(self, solarSystemID, scoreboardItemID, winnerFactionID): 92 93 def PlayVideo(parent, cancellation_token): 94 BattlefieldWon(parent, solarSystemID, winnerFactionID) 95 96 self.heroNotification.play(PlayVideo, 1) 97 98 def OnFacWarDungeonCompleted(self, wasConquered, factionID): 99 if wasConquered: 100 101 def PlayVideo(parent, cancellation_token): 102 DungeonConquered(parent, factionID) 103 104 else: 105 106 def PlayVideo(parent, cancellation_token): 107 DungeonDefended(parent, factionID) 108 109 self.heroNotification.play(PlayVideo, 1) 110 111 def IsWarzoneSolarSystem(self, solarsystemID): 112 if solarsystemID == session.solarsystemid2: 113 occupationState = self.GetLocalOccupationState() 114 return bool(occupationState) 115 occupationStatesBySolarsystemByWarzone = self.GetAllOccupationStates() 116 for occupationStatesBySolarsystem in occupationStatesBySolarsystemByWarzone.itervalues(): 117 if solarsystemID in occupationStatesBySolarsystem: 118 return True 119 120 return False 121 122 def GetSystemOccupier(self, solarSystemID): 123 occupationState = self.GetOccupationState(solarSystemID) 124 if occupationState is not None: 125 return occupationState.occupierID 126 127 def BattleFieldAdded(self, itemID, typeID, score): 128 if itemID not in self._currentBattlefields: 129 self._currentBattlefields.add(itemID) 130 sm.ScatterEvent('OnFwBattlefieldAdded', itemID, typeID, score) 131 132 def BattleFieldRemoved(self, itemID): 133 if itemID in self._currentBattlefields: 134 self._currentBattlefields.discard(itemID) 135 sm.ScatterEvent('OnFwBattlefieldUpdated') 136 137 def GetBattleFieldScoreboards(self): 138 return self._currentBattlefields 139 140 def GetBattlefieldInstances(self): 141 return sm.RemoteSvc('dungeonInstanceCacheMgr').GetFactionWarfareBattlefieldInstances() 142 143 def ShowFlipFanfare(self, solarSystemID, newOccupationState): 144 if solarSystemID != session.solarsystemid2: 145 return 146 147 def PlayVideo(parent, cancellation_token): 148 SystemFlipped(parent, solarSystemID, newOccupationState) 149 150 self.heroNotification.play(PlayVideo, 1) 151 152 def ShowChangedAdjacency(self, solarSystemID, newOccupationState): 153 if solarSystemID != session.solarsystemid2: 154 return 155 156 def PlayVideo(parent, cancellation_token): 157 SystemChangedAdjacency(parent, solarSystemID, newOccupationState) 158 159 self.heroNotification.play(PlayVideo, 0) 160 161 def GetWarzoneIdForFaction(self, factionID): 162 allWarzones = self.GetAllWarzones() 163 for zoneID, teams in allWarzones.iteritems(): 164 if factionID in teams: 165 return zoneID 166 167 return random.choice(allWarzones.keys()) 168 169 def GetFactionHQSystem(self, factionId): 170 factionIdToHQSystem = self.GetAllHQSystems() 171 if factionId in factionIdToHQSystem: 172 return factionIdToHQSystem[factionId] 173 174 def GetAdjacencyState(self, solarsystemID): 175 fwOccupationState = self.GetOccupationState(solarsystemID) 176 if fwOccupationState: 177 return fwOccupationState.adjacencyState 178 179 @Memoize 180 def GetAllWarzones(self): 181 return sm.RemoteSvc('fwWarzoneSolarsystem').GetAllWarzones() 182 183 @Memoize 184 def GetAllHQSystems(self): 185 return sm.RemoteSvc('fwWarzoneSolarsystem').GetHQSystemIDs()