consider.py (6871B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\parklife\consider.py 2 import dogma.data 3 import uthread 4 import carbonui.const as uiconst 5 import telemetry 6 import inventorycommon.typeHelpers 7 from carbon.common.script.sys.service import Service 8 from eve.client.script.ui.util import uix 9 from eve.common.lib import appConst as const 10 import localization 11 from carbonui.control.message import QuickMessage 12 from eve.common.script.sys import idCheckers 13 from eve.common.script.util.systemExclusions import IsStarterSystem 14 from eveuniverse.security import is_zero_sec_solar_system 15 from npcs.client.entitystandings import is_npc_hostile, is_npc_hostile_towards_player 16 from player_messaging.client.ui_message import prompt_player_fsd_dialog 17 18 class ConsiderSvc(Service): 19 __guid__ = 'svc.consider' 20 __exportedcalls__ = {'ConfirmTakeIllicitGoods': []} 21 __notifyevents__ = ['ProcessSessionChange', 22 'DoBallRemove', 23 'DoBallClear', 24 'DoBallsRemove'] 25 __dependencies__ = ['michelle', 'crimewatchSvc'] 26 27 def Run(self, *etc): 28 Service.Run(self, *etc) 29 self.confirmationCache = {} 30 self.pendingConfirmations = {} 31 self.containerTakeRights = {} 32 33 def ProcessSessionChange(self, isRemote, session, change): 34 if 'solarsystemid' in change: 35 self.confirmationCache.clear() 36 self.pendingConfirmations.clear() 37 self.containerTakeRights.clear() 38 39 @telemetry.ZONE_METHOD 40 def DoBallsRemove(self, pythonBalls, isRelease): 41 for ball, slimItem, terminal in pythonBalls: 42 self.DoBallRemove(ball, slimItem, terminal) 43 44 def DoBallRemove(self, ball, slimItem, terminal): 45 if ball: 46 itemID = ball.id 47 elif slimItem: 48 itemID = slimItem.itemID 49 else: 50 return 51 if itemID in self.confirmationCache: 52 self.LogInfo('DoBallRemove::consider removing item', itemID) 53 del self.confirmationCache[itemID] 54 55 def DoBallClear(self, solitem): 56 self.confirmationCache.clear() 57 58 def ShowNPCAtttackConfirmationWindowIfAppropriate(self, requiredSafetyLevel, targetID): 59 item = self.michelle.GetItem(targetID) 60 if item and idCheckers.IsNPC(item.ownerID) and item.ownerID not in const.legalOffensiveTargetOwnerIDs: 61 if not is_npc_hostile(item.hostile_response_threshold) and not is_npc_hostile_towards_player(item, session.charid): 62 if not self.TypeHasAttribute(item.typeID, const.attributeEntitySecurityStatusKillBonus): 63 if item.groupID not in [const.groupLargeCollidableObject, 64 const.groupControlBunker, 65 const.groupWormhole, 66 const.groupStructurePirateForwardOperatingBase]: 67 if not self.ConfirmationRequest(targetID, 'AttackGoodNPCAbort1', targetID): 68 return False 69 return True 70 71 def IsAggressionBlockedInStarterSpace(self, targetID, effect = None): 72 if not IsStarterSystem(session.solarsystemid): 73 return False 74 if targetID is not None: 75 item = self.michelle.GetItem(targetID) 76 if item and idCheckers.IsCharacter(item.ownerID): 77 return True 78 return False 79 if effect and effect.rangeAttributeID is not None: 80 return True 81 return False 82 83 def SafetyCheckPasses(self, requiredSafetyLevel): 84 if self.crimewatchSvc.CheckUnsafe(requiredSafetyLevel): 85 self.crimewatchSvc.SafetyActivated(requiredSafetyLevel) 86 return False 87 return True 88 89 def DoAttackConfirmations(self, targetID, effect = None): 90 if self.IsAggressionBlockedInStarterSpace(targetID, effect): 91 errorMsg = localization.GetByLabel('UI/Corporations/AccessRestrictions/StarterSpaceAggressionBlocked') 92 QuickMessage.show_message(errorMsg) 93 return False 94 requiredSafetyLevel = self.crimewatchSvc.GetSafetyLevelRestrictionForAttackingTarget(targetID, effect=effect) 95 if not self.SafetyCheckPasses(requiredSafetyLevel): 96 if IsStarterSystem(session.solarsystemid): 97 errorMsg = localization.GetByLabel('UI/Corporations/AccessRestrictions/StarterSpaceAggressionBlocked') 98 QuickMessage.show_message(errorMsg) 99 return False 100 return self.ShowNPCAtttackConfirmationWindowIfAppropriate(requiredSafetyLevel, targetID) 101 102 def ConfirmationRequest(self, targetID, msgName, actualTargetID): 103 if self.HasConfirmation(targetID, msgName): 104 return 1 105 item = self.michelle.GetItem(actualTargetID) 106 targetName = 'your target' 107 if item is not None: 108 targetName = uix.GetSlimItemName(item) 109 k = (targetID, msgName) 110 if k in self.pendingConfirmations: 111 return self.pendingConfirmations[k].receive() 112 result = 0 113 self.pendingConfirmations[k] = uthread.Channel(('consider::ConfirmationRequest', k)) 114 try: 115 ret = prompt_player_fsd_dialog(msgName, {'target': targetName}, uiconst.YESNO, suppress=uiconst.ID_YES, default=uiconst.ID_NO) 116 if ret != uiconst.ID_YES: 117 result = 0 118 return 0 119 self.RememberConfirmation(targetID, msgName) 120 result = 1 121 finally: 122 if k in self.pendingConfirmations: 123 while self.pendingConfirmations[k].queue: 124 self.pendingConfirmations[k].send(result) 125 126 del self.pendingConfirmations[k] 127 128 return result 129 130 def RememberConfirmation(self, targetID, msgName): 131 if targetID not in self.confirmationCache: 132 self.confirmationCache[targetID] = [] 133 self.confirmationCache[targetID].append(msgName) 134 135 def HasConfirmation(self, targetID, msgName): 136 return targetID in self.confirmationCache and msgName in self.confirmationCache[targetID] 137 138 def TypeHasAttribute(self, typeID, attributeID): 139 for typeAttribute in dogma.data.get_type_attributes(typeID): 140 if typeAttribute.attributeID == attributeID: 141 return 1 142 143 return 0 144 145 def ConfirmTakeIllicitGoods(self, items): 146 if not session.solarsystemid: 147 return True 148 if is_zero_sec_solar_system(session.solarsystemid2): 149 return True 150 toFactionID = sm.GetService('faction').GetFactionOfSolarSystem(session.solarsystemid) 151 for item in items: 152 illegality = inventorycommon.typeHelpers.GetIllegalityInFaction(item.typeID, toFactionID) 153 if illegality: 154 return prompt_player_fsd_dialog('ConfirmTakeIllicitGoods', {'faction': cfg.eveowners.Get(toFactionID).name}, uiconst.YESNO, suppress=uiconst.ID_YES) == uiconst.ID_YES 155 156 return True