agentUtil.py (12727B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\station\agents\agentUtil.py 2 import blue 3 import telemetry 4 from carbonui.util.color import Color 5 from eve.client.script.ui.station.agents.agentConst import MISSIONSTATELABELS, COLOR_ACCEPTED, COLOR_OFFERED, COLOR_EXPIRED 6 from eve.common.lib import appConst 7 from localization import GetByLabel 8 from npcs.npccorporations import get_corporation_faction_id 9 import eveformat.client 10 STORYLINE_AGENTS = (appConst.agentTypeGenericStorylineMissionAgent, appConst.agentTypeStorylineMissionAgent) 11 NORMAL_AGENTS = (appConst.agentTypeResearchAgent, 12 appConst.agentTypeBasicAgent, 13 appConst.agentTypeEventMissionAgent, 14 appConst.agentTypeHeraldry) 15 AGENTS_IN_CORP_SHOW_INFO = (appConst.agentTypeResearchAgent, 16 appConst.agentTypeBasicAgent, 17 appConst.agentTypeFactionalWarfareAgent, 18 appConst.agentTypeHeraldry) 19 20 def IsAgentAvailable(agentID): 21 if sm.GetService('journal').IsMissionActiveWithAgent(agentID): 22 return True 23 agent = sm.GetService('agents').GetAgentByID(agentID) 24 if not agent: 25 return False 26 if agent.agentTypeID in NORMAL_AGENTS: 27 return IsAgentStandingSufficientToUse(agent) 28 if agent.agentTypeID == appConst.agentTypeCareerAgent: 29 return IsAgentStandingSufficientToUse(agent) and not sm.GetService('agents').IsCareerAgentCompleted(agentID) 30 if agent.agentTypeID == appConst.agentTypeFactionalWarfareAgent: 31 isLimitedToFacWar = False 32 facWarSvc = sm.StartService('facwar') 33 if agent.agentTypeID == appConst.agentTypeFactionalWarfareAgent and facWarSvc.GetCorporationWarFactionID(agent.corporationID) != session.warfactionid: 34 isLimitedToFacWar = True 35 standingIsSufficient = IsAgentStandingSufficientToUse(agent) 36 return not isLimitedToFacWar and standingIsSufficient 37 if agent.agentTypeID == appConst.agentTypeEpicArcAgent: 38 standingIsSufficient = IsAgentStandingSufficientToUse(agent) 39 epicArcStatusSvc = sm.RemoteSvc('epicArcStatus') 40 return standingIsSufficient and epicArcStatusSvc.AgentHasEpicMissionsForCharacter(agent.agentID) 41 if agent.agentTypeID == appConst.agentTypeAura: 42 return False 43 44 45 def GetAgentUnavailableReason(agentID): 46 if sm.GetService('journal').IsMissionActiveWithAgent(agentID): 47 return None 48 agent = sm.GetService('agents').GetAgentByID(agentID) 49 if agent.agentTypeID in NORMAL_AGENTS: 50 if not IsAgentStandingSufficientToUse(agent): 51 return _GetInsufficientStandingsHint(agent) 52 elif agent.agentTypeID == appConst.agentTypeCareerAgent: 53 if sm.GetService('agents').IsCareerAgentCompleted(agentID): 54 return GetByLabel('UI/Agents/CareerAgentCompleted') 55 if not IsAgentStandingSufficientToUse(agent): 56 return _GetInsufficientStandingsHint(agent) 57 elif agent.agentTypeID == appConst.agentTypeFactionalWarfareAgent: 58 facWarSvc = sm.GetService('facwar') 59 if facWarSvc.GetCorporationWarFactionID(agent.corporationID) != session.warfactionid: 60 return GetByLabel('UI/Agents/UnavailableRequiresFacWarfare', agent=agentID) 61 elif agent.agentTypeID == appConst.agentTypeEpicArcAgent: 62 epicArcStatusSvc = sm.RemoteSvc('epicArcStatus') 63 if not epicArcStatusSvc.AgentHasEpicMissionsForCharacter(agent.agentID): 64 return GetByLabel('UI/Agents/UnavailableRequiresReference', agent=agentID) 65 if not IsAgentStandingSufficientToUse(agent): 66 return _GetInsufficientStandingsHint(agent) 67 elif agent.agentTypeID in (appConst.agentTypeStorylineMissionAgent, appConst.agentTypeGenericStorylineMissionAgent): 68 return GetByLabel('UI/Agents/UnavailableRequiresReference', agent=agentID) 69 70 71 def GetAgentStartConversationHint(agentID): 72 unavailableReason = GetAgentUnavailableReason(agentID) 73 if unavailableReason: 74 return unavailableReason 75 else: 76 return GetByLabel('UI/Chat/StartConversationAgent') 77 78 79 def _GetInsufficientStandingsHint(agent): 80 requiredStanding = GetAgentStandingThreshold(agent.level) 81 return GetByLabel('UI/Agents/UnavailableInsufficientStandings', agent=agent.agentID, requiredStanding=requiredStanding, minStanding=-2.0) 82 83 84 def IsAgentStandingSufficientToUse(agent): 85 standingSvc = sm.GetService('standing') 86 return standingSvc.CanUseAgent(agent.factionID, agent.corporationID, agent.agentID, agent.level, agent.agentTypeID) 87 88 89 def GetAgentStandingThreshold(level): 90 if level == 1: 91 return -10.0 92 if level == 2: 93 return 1.0 94 if level == 3: 95 return 3.0 96 if level == 4: 97 return 5.0 98 if level == 5: 99 return 7.0 100 101 102 def GetAgentDerivedStanding(agentID): 103 standings = _GetAgentDerivedStandingsList(agentID) 104 if standings[-1][0] <= -2.0: 105 return standings[-1] 106 else: 107 return standings[0] 108 109 110 def _GetAgentDerivedStandingsList(agentID): 111 standingSvc = sm.GetService('standing') 112 agentInfo = sm.GetService('agents').GetAgentByID(agentID) 113 standings = [(standingSvc.GetStandingWithSkillBonus(agentInfo.factionID, session.charid), agentInfo.factionID), (standingSvc.GetStandingWithSkillBonus(agentInfo.corporationID, session.charid), agentInfo.corporationID), (standingSvc.GetStandingWithSkillBonus(agentInfo.agentID, session.charid), agentInfo.agentID)] 114 return sorted(standings, reverse=True) 115 116 117 def GetNPCCorpDerivedStanding(corpID): 118 standingSvc = sm.GetService('standing') 119 factionID = get_corporation_faction_id(corpID) 120 standings = [(standingSvc.GetStandingWithSkillBonus(factionID, session.charid), factionID), (standingSvc.GetStandingWithSkillBonus(corpID, session.charid), corpID)] 121 standings.sort() 122 return standings[-1] 123 124 125 @telemetry.ZONE_METHOD 126 def GetAgentDerivedStandingsSortedList(agentID): 127 standingList = _GetAgentDerivedStandingsList(agentID) 128 return [ standing for standing, _ in standingList ] 129 130 131 def GetAgentLocationText(solarSystemID): 132 return eveformat.solar_system_with_security_and_jumps(solarSystemID) 133 134 135 def GetMissionExpirationAndStateText(missionState, expirationTime): 136 if missionState in (appConst.agentMissionStateAllocated, appConst.agentMissionStateOffered): 137 stateText = '<color=0xFFFFFF00>' + MISSIONSTATELABELS[missionState] + '<color=0xffffffff>' 138 if expirationTime > blue.os.GetWallclockTime() + appConst.WEEK + appConst.MIN: 139 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/OfferExpiresAt', expirationTime=expirationTime) 140 elif expirationTime > blue.os.GetWallclockTime() + appConst.DAY: 141 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/OfferExpiresAtExact', expirationTime=expirationTime) 142 else: 143 if expirationTime: 144 expirationTime -= blue.os.GetWallclockTime() 145 expirationTime = int(expirationTime / appConst.MIN) * appConst.MIN 146 if expirationTime == 0: 147 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/OfferDoesNotExpire') 148 elif not expirationTime: 149 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/OfferUndefinedExpiration') 150 elif expirationTime > 0: 151 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/OfferExpiresIn', expirationTime=expirationTime) 152 else: 153 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/OfferExpired') 154 stateText = '<color=0xffeb3700>' + GetByLabel('UI/Journal/JournalWindow/Agents/StateOfferExpired') + '<color=0xffffffff>' 155 elif missionState in (appConst.agentMissionStateAccepted, appConst.agentMissionStateFailed): 156 if missionState == appConst.agentMissionStateAccepted: 157 stateText = '<color=0xff00FF00>' + MISSIONSTATELABELS[missionState] + '<color=0xffffffff>' 158 else: 159 stateText = '<color=0xffeb3700>' + MISSIONSTATELABELS[missionState] + '<color=0xffffffff>' 160 if expirationTime > blue.os.GetWallclockTime() + appConst.WEEK + appConst.MIN: 161 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/MissionExpiresAt', expirationTime=expirationTime) 162 elif expirationTime > blue.os.GetWallclockTime() + appConst.DAY: 163 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/MissionExpiresAtExact', expirationTime=expirationTime) 164 else: 165 if expirationTime: 166 expirationTime -= blue.os.GetWallclockTime() 167 expirationTime = int(expirationTime / appConst.MIN) * appConst.MIN 168 if expirationTime == 0: 169 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/MissionDoesNotExpire') 170 elif not expirationTime: 171 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/MissionUndefinedExpiration') 172 elif expirationTime > 0: 173 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/MissionExpiresIn', expirationTime=expirationTime) 174 else: 175 expirationText = GetByLabel('UI/Journal/JournalWindow/Agents/MissionExpired') 176 stateText = '<color=0xffeb3700>' + GetByLabel('UI/Journal/JournalWindow/Agents/StateMissionExpired') + '<color=0xffffffff>' 177 else: 178 stateText = expirationText = '' 179 return (stateText, expirationText) 180 181 182 def GetMissionExpirationText(missionState, expirationTime, short = False): 183 if missionState in (appConst.agentMissionStateAllocated, appConst.agentMissionStateOffered): 184 if expirationTime: 185 expirationTime -= blue.os.GetWallclockTime() 186 if expirationTime == 0: 187 return GetByLabel('UI/Journal/JournalWindow/Agents/OfferDoesNotExpire') 188 elif not expirationTime: 189 return GetByLabel('UI/Journal/JournalWindow/Agents/OfferUndefinedExpiration') 190 elif expirationTime > 0: 191 if short: 192 return GetByLabel('UI/Agency/ExpiresIn', remaining=expirationTime) 193 return GetByLabel('UI/Journal/JournalWindow/Agents/OfferExpiresIn', expirationTime=expirationTime) 194 else: 195 return GetByLabel('UI/Journal/JournalWindow/Agents/OfferExpired') 196 elif missionState in (appConst.agentMissionStateAccepted, appConst.agentMissionStateFailed): 197 if expirationTime: 198 expirationTime -= blue.os.GetWallclockTime() 199 if expirationTime == 0: 200 return GetByLabel('UI/Journal/JournalWindow/Agents/MissionDoesNotExpire') 201 elif not expirationTime: 202 return GetByLabel('UI/Journal/JournalWindow/Agents/MissionUndefinedExpiration') 203 elif expirationTime > 0: 204 if short: 205 return GetByLabel('UI/Agency/ExpiresIn', remaining=expirationTime) 206 return GetByLabel('UI/Journal/JournalWindow/Agents/MissionExpiresIn', expirationTime=expirationTime) 207 else: 208 return GetByLabel('UI/Journal/JournalWindow/Agents/MissionExpired') 209 else: 210 return '' 211 212 213 def GetMissionStateText(missionState, expirationTime): 214 if missionState in (appConst.agentMissionStateAllocated, appConst.agentMissionStateOffered): 215 if expirationTime < 0: 216 return GetByLabel('UI/Journal/JournalWindow/Agents/StateOfferExpired') 217 else: 218 return MISSIONSTATELABELS[missionState] 219 elif missionState in (appConst.agentMissionStateAccepted, appConst.agentMissionStateFailed): 220 if expirationTime < 0: 221 GetByLabel('UI/Journal/JournalWindow/Agents/StateMissionExpired') 222 else: 223 return MISSIONSTATELABELS[missionState] 224 else: 225 return '' 226 227 228 def GetMissionStateColor(missionState, expirationTime): 229 if missionState in (appConst.agentMissionStateAllocated, appConst.agentMissionStateOffered): 230 if expirationTime < 0: 231 return COLOR_EXPIRED 232 else: 233 return COLOR_OFFERED 234 elif missionState in (appConst.agentMissionStateAccepted, appConst.agentMissionStateFailed): 235 if expirationTime < 0: 236 return COLOR_EXPIRED 237 else: 238 return COLOR_ACCEPTED 239 else: 240 return Color.WHITE 241 242 243 def GetAgentTypeNamePath(agentTypeID): 244 if agentTypeID == appConst.agentTypeBasicAgent: 245 return 'UI/Agents/MissionTypes/StandardAgent' 246 if agentTypeID == appConst.agentTypeCareerAgent: 247 return 'UI/Agency/ContentGroups/ContentGroupCareerAgents' 248 if agentTypeID == appConst.agentTypeFactionalWarfareAgent: 249 return 'UI/Agents/FactionalWarfare' 250 if agentTypeID == appConst.agentTypeStorylineMissionAgent: 251 return 'UI/Agents/MissionTypes/Storyline' 252 if agentTypeID == appConst.agentTypeEpicArcAgent: 253 return 'UI/Agents/MissionTypes/EpicArc'