contentProviderAgents.py (7737B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\agencyNew\contentProviders\contentProviderAgents.py 2 from collections import defaultdict 3 import blue 4 import telemetry 5 from eve.client.script.ui.shared.agencyNew import agencyConst, agencyFilters 6 from eve.client.script.ui.shared.agencyNew.agencyConst import AGENT_STANDARDDIVISIONIDS, MAX_CONTENT_PIECES_MAX 7 from eve.client.script.ui.shared.agencyNew.agencyUtil import GetRoundRobinMix, GetUnlockedAgents 8 from eve.client.script.ui.shared.agencyNew.contentPieces.agentContentPiece import AgentContentPiece 9 from eve.client.script.ui.shared.agencyNew.contentProviders.baseContentProvider import BaseContentProvider 10 from eve.client.script.ui.station.agents import agentUtil 11 from eve.client.script.ui.station.agents.agentUtil import GetAgentDerivedStandingsSortedList 12 from eve.common.lib.appConst import corpDivisionHeraldry 13 14 class ContentProviderAgents(BaseContentProvider): 15 __notifyevents__ = BaseContentProvider.__notifyevents__ + ['OnNPCStandingChange', 'OnAgentMissionChanged', 'OnHeraldryAvailabilityChanged'] 16 contentType = agencyConst.CONTENTTYPE_AGENTS 17 18 def __init__(self): 19 super(ContentProviderAgents, self).__init__() 20 self.newAgents = [] 21 self._isHeraldryAvailable = None 22 23 @telemetry.ZONE_METHOD 24 def _ConstructContentPieces(self): 25 allAgents = self._GetAllAgents() 26 contentPieces = [ self.ConstructContentPiece(agent) for agent in allAgents ] 27 self.ExtendContentPieces(contentPieces) 28 29 @telemetry.ZONE_METHOD 30 def CheckInactiveAgentCriteria(self, agent): 31 if not self.CheckInactiveAgentGenericCriteria(agent): 32 return False 33 return self.CheckAgentsUserSelectedFilterCriteria(agent) 34 35 @telemetry.ZONE_METHOD 36 def CheckAgentsUserSelectedFilterCriteria(self, agent): 37 return self.CheckFactionAndCorpFilterCriteria(agent) and self.CheckAgentLevelFilterCriteria(agent) and self.CheckShowOnlyAvailableCriteria(agent) and self.CheckDivisionFilterCriteria(agent) and self.CheckSecurityStatusFilterCriteria(agent.solarsystemID) 38 39 def CheckShowOnlyAvailableCriteria(self, agent): 40 if not agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_AGENTIGNORESTANDINGSREQUIREMENT): 41 return self.CheckIsStandingSufficient(agent) 42 return True 43 44 @telemetry.ZONE_METHOD 45 def CheckInactiveAgentGenericCriteria(self, agent): 46 return self._CheckDivisionEnabled(agent) and self.CheckDivisionValidCriteria(agent) and self.CheckAgentTypeIDCriteria(agent) and self.CheckDistanceCriteria(solarSystemID=agent.solarsystemID) 47 48 def CheckFactionAndCorpFilterCriteria(self, agent): 49 factionID = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_AGENTFACTION) 50 if factionID == agencyConst.FILTERVALUE_ANY: 51 return True 52 else: 53 return agent.factionID == factionID and self.CheckCorpCriteria(agent) 54 55 def CheckCorpCriteria(self, agent): 56 corpID = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_AGENTCORP) 57 if corpID == agencyConst.FILTERVALUE_ANY: 58 return True 59 else: 60 return agent.corporationID == corpID 61 62 def _CheckDivisionEnabled(self, agent): 63 return agent.divisionID != corpDivisionHeraldry or self.IsHeraldryAvailable() 64 65 def CheckDivisionValidCriteria(self, agent): 66 return agent.divisionID in AGENT_STANDARDDIVISIONIDS 67 68 def CheckAgentTypeIDCriteria(self, agent): 69 return True 70 71 def CheckDivisionFilterCriteria(self, agent): 72 return True 73 74 def IsHeraldryAvailable(self): 75 if self._isHeraldryAvailable is None: 76 self._isHeraldryAvailable = sm.GetService('agents').IsHeraldryAvailable() 77 return self._isHeraldryAvailable 78 79 def OnHeraldryAvailabilityChanged(self): 80 self._isHeraldryAvailable = None 81 agencyFilters.ResetFilter(self.contentGroup, agencyConst.FILTERTYPE_AGENTDIVISION) 82 83 @telemetry.ZONE_METHOD 84 def _GetAllAgents(self): 85 agentBuckets = self.GetAgentsByBuckets() 86 agentMix = GetRoundRobinMix(agentBuckets, numMax=MAX_CONTENT_PIECES_MAX) 87 return list(agentMix) 88 89 @telemetry.ZONE_METHOD 90 def GetAgentsByBuckets(self): 91 agents = self._GetAgentsWithinJumpRange() 92 buckets = defaultdict(list) 93 for agent in agents: 94 blue.pyos.BeNice() 95 if self.CheckInactiveAgentCriteria(agent): 96 bucketKey = self._GetBucketKey(agent) 97 buckets[bucketKey].append(agent) 98 99 return self._GetAgentsByBucket(buckets) 100 101 def _GetAgentsWithinJumpRange(self): 102 solarSystemIDs = self.GetAllSolarSystemIDsWithinJumpRange(shouldIncludeAvoided=True) 103 agentsBySolarSystemID = sm.GetService('agents').GetAgentsBySolarSystemID() 104 ret = [] 105 for solarSystemID in solarSystemIDs: 106 ret.extend(agentsBySolarSystemID.get(solarSystemID, [])) 107 108 return ret 109 110 @telemetry.ZONE_METHOD 111 def _GetAgentsByBucket(self, buckets): 112 agentsByBuckets = [ iter(sorted(buckets[key], key=self._GetAgentSortKey, reverse=True)) for key in sorted(buckets.keys(), key=self._GetBucketSortKey) ] 113 return agentsByBuckets 114 115 def _GetBucketSortKey(self, sortKey): 116 divisionID, isHighSec = sortKey 117 if divisionID in AGENT_STANDARDDIVISIONIDS: 118 divisionIndex = AGENT_STANDARDDIVISIONIDS.index(divisionID) 119 else: 120 divisionIndex = divisionID 121 return (-isHighSec, divisionIndex) 122 123 @telemetry.ZONE_METHOD 124 def _GetBucketKey(self, agent): 125 isHighSec = self.IsInHighSec(agent.solarsystemID) 126 divisionID = agent.divisionID 127 key = (divisionID, isHighSec) 128 return key 129 130 @telemetry.ZONE_METHOD 131 def _GetAgentSortKey(self, agent): 132 numJumps = self.GetNumJumpsToSystem(agent.solarsystemID) 133 if numJumps is None: 134 numJumps = 1000 135 return (agent.level, -numJumps, GetAgentDerivedStandingsSortedList(agent.agentID)) 136 137 @telemetry.ZONE_METHOD 138 def CheckAgentLevelFilterCriteria(self, agent): 139 level = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_AGENTLEVEL) 140 if level == agencyConst.FILTERVALUE_ANY: 141 return True 142 elif level == agencyConst.AGENTLEVEL_HIGHESTAVAILABLE: 143 return self.CheckIsStandingSufficient(agent) 144 else: 145 return level == agent.level 146 147 @telemetry.ZONE_METHOD 148 def CheckIsStandingSufficient(self, agent): 149 return agentUtil.IsAgentStandingSufficientToUse(agent) 150 151 def ConstructContentPiece(self, agent): 152 cls = self._GetContentPieceClass() 153 isNewAgent = self.IsAgentNew(agent) 154 contentPiece = cls(solarSystemID=agent.solarsystemID, itemID=agent.agentID, locationID=agent.stationID, typeID=agent.agentTypeID, ownerID=agent.corporationID, agent=agent, isNew=isNewAgent) 155 return contentPiece 156 157 def _GetContentPieceClass(self): 158 return AgentContentPiece 159 160 def OnNPCStandingChange(self, fromID, newStandingsValue, oldStandingsValue): 161 unlockedAgents = GetUnlockedAgents(fromID, newStandingsValue, oldStandingsValue) 162 if unlockedAgents: 163 self.newAgents.extend([ agent.agentID for agent in unlockedAgents ]) 164 165 def IsAgentNew(self, agent): 166 return agent.agentID in self.newAgents 167 168 def ClearNewContent(self, contentPiece): 169 agentID = contentPiece.agent.agentID 170 if agentID in self.newAgents: 171 self.newAgents.remove(agentID) 172 173 def OnAgentMissionChanged(self, missionState, agentID): 174 self.InvalidateContentPieces()