mockDogmaLocation.py (7541B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dogma\mocks\mockDogmaLocation.py 2 from collections import defaultdict 3 from itertoolsext import Bundle 4 from inventorycommon.const import categoryShip, categoryModule, groupProjectileWeapon, categoryStarbase 5 import dogma.const 6 7 class MockDogmaLocation(object): 8 9 def __init__(self, isSolarsystem = True): 10 self.isSolarsystem = isSolarsystem 11 self.dogmaItems = {} 12 self.pilotsByShipID = {} 13 self.fittedItems = defaultdict(dict) 14 self.typeAttributes = defaultdict(dict) 15 self.effectsByType = defaultdict(dict) 16 self.requiredSkills = defaultdict(dict) 17 self.onlineEffects = {dogma.const.effectOnline: True, 18 dogma.const.effectOnlineForStructures: True} 19 self.dogmaStaticMgr = self._GetDogmaStaticMgr() 20 self.msgMgr = self._GetDogmaMsgMngr() 21 self.attributeChangeCallbacksByAttributeID = {} 22 23 def AddShip(self, typeID, ownerID, groupID = 1000): 24 itemID, _ = self._AddGenericItem(typeID, groupID, categoryShip, ownerID=ownerID, GetFittedItems=lambda : self._GetFittedItems(itemID)) 25 if ownerID is not None: 26 self.SetPilot(ownerID, itemID) 27 return itemID 28 29 def AddStructure(self, typeID, groupID = 1001): 30 itemID, _ = self._AddGenericItem(typeID, groupID, categoryStarbase, ownerID=None) 31 return itemID 32 33 def AddModuleToShip(self, typeID, locationID, flagID, groupID = 1): 34 itemID, module = self._AddGenericItem(typeID, groupID, categoryModule, locationID=locationID, ownerID=self.dogmaItems[locationID].ownerID, flagID=flagID, GetEnvironmentInfo=lambda : self._GetEnvironmentInfo(itemID)) 35 self.dogmaItems[itemID] = module 36 self.fittedItems[locationID][itemID] = module 37 return itemID 38 39 def _AddGenericItem(self, typeID, groupID, categoryID, **kwargs): 40 itemID = self._GetNewID() 41 item = Bundle(itemID=itemID, typeID=typeID, groupID=groupID, categoryID=categoryID, **kwargs) 42 self.dogmaItems[itemID] = item 43 return (itemID, item) 44 45 def AddProjectileToShip(self, typeID, locationID, flagID): 46 return self.AddModuleToShip(typeID, locationID, flagID, groupProjectileWeapon) 47 48 def AddTargetableEffect(self, effectID, typeID): 49 self.AddEffect(effectID, typeID, dogma.const.dgmEffTarget) 50 51 def SetPilot(self, pilotID, shipID): 52 self.pilotsByShipID[shipID] = pilotID 53 54 def AddEffect(self, effectID, typeID, effectCategory): 55 effect = Bundle(effectCategory=effectCategory) 56 self.dogmaStaticMgr.effects[effectID] = effect 57 self.effectsByType[typeID][effectID] = effect 58 59 def SetTypeAttribute(self, typeID, attributeID): 60 pass 61 62 def LoadItem(self, itemID, *args, **kwargs): 63 pass 64 65 def GetDogmaItem(self, itemID): 66 return self.dogmaItems[itemID] 67 68 def GetItem(self, itemID): 69 return self.dogmaItems[itemID] 70 71 def GetPilot(self, shipID): 72 return self.pilotsByShipID[shipID] 73 74 def GetSlaveModules(self, shipID, moduleID): 75 return [] 76 77 def StartEffect(self, *args, **kwargs): 78 pass 79 80 def AddLocationGroupModifier(self, op, location, toAttributeID, fromAttribute, groupID, *args): 81 location.locationGroupMods[groupID][toAttributeID].add((op, fromAttribute)) 82 for item in filter(lambda i: i.invItem.groupID == groupID and toAttributeID in i.attributes, location.subItems): 83 toAttrib = item.attributes[toAttributeID] 84 fromAttribute.AddOutgoingModifier(op, toAttrib) 85 toAttrib.AddIncomingModifier(op, fromAttribute) 86 87 def AddLocationModifier(self, op, location, toAttributeID, fromAttribute, *args): 88 location.locationMods[toAttributeID].add((op, fromAttribute)) 89 for item in filter(lambda i: toAttributeID in i.attributes, location.subItems): 90 toAttribute = item.attributes[toAttributeID] 91 fromAttribute.AddOutgoingModifier(op, toAttribute) 92 toAttribute.AddIncomingModifier(op, fromAttribute) 93 94 def RemoveLocationModifier(self, op, location, toAttributeID, fromAttribute): 95 location.locationMods[toAttributeID].remove((op, fromAttribute)) 96 if not location.locationMods[toAttributeID]: 97 del location.locationMods[toAttributeID] 98 for item in filter(lambda i: toAttributeID in i.attributes, location.subItems): 99 toAttribute = item.attributes[toAttributeID] 100 fromAttribute.RemoveOutgoingModifier(op, toAttribute) 101 toAttribute.RemoveIncomingModifier(op, fromAttribute) 102 103 def AddLocationSkillModifier(self, op, location, toAttributeID, fromAttribute, skillID, *args): 104 location.locationReqSkillMods[skillID][toAttributeID].add((op, fromAttribute)) 105 for item in filter(lambda i: skillID in i.reqSkills and toAttributeID in i.attributes, location.subItems): 106 toAttrib = item.attributes[toAttributeID] 107 fromAttribute.AddOutgoingModifier(op, toAttrib) 108 toAttrib.AddIncomingModifier(op, fromAttribute) 109 110 def AddOwnerSkillModifier(self, op, owner, toAttributeID, fromAttribute, skillID, *args): 111 owner.ownerReqSkillMods[skillID][toAttributeID].add((op, fromAttribute)) 112 for item in filter(lambda i: skillID in i.reqSkills and toAttributeID in i.attributes, owner.ownedItems): 113 toAttrib = item.attributes[toAttributeID] 114 fromAttribute.AddOutgoingModifier(op, toAttrib) 115 toAttrib.AddIncomingModifier(op, fromAttribute) 116 117 def _GetNewID(self): 118 try: 119 return max(self.dogmaItems.iterkeys()) + 1 120 except ValueError: 121 return 1 122 123 def _GetEnvironmentInfo(self, itemID): 124 item = self.dogmaItems[itemID] 125 return Bundle(charID=item.ownerID, itemID=item.itemID, shipID=item.locationID, otherID=None) 126 127 def _GetFittedItems(self, shipID): 128 return self.fittedItems[shipID] 129 130 def _GetDogmaStaticMgr(self): 131 return Bundle(effects={}, crystalModuleGroupIDs={}, effectsByType=self.effectsByType, GetTypeAttribute2=lambda typeID, attributeID: self.typeAttributes[typeID].get(attributeID, 0), GetRequiredSkills=lambda typeID: self.requiredSkills[typeID]) 132 133 def _GetDogmaMsgMngr(self): 134 return Bundle(AddAttribute=lambda x: x) 135 136 137 class MockServerDogmaLocation(MockDogmaLocation): 138 139 def __init__(self): 140 super(MockServerDogmaLocation, self).__init__() 141 self.__balls = {} 142 self.inventory2 = self._GetInventory2() 143 self.ballpark = self._GetBallpark() 144 145 def AddShip(self, typeID, ownerID, groupID = 1000): 146 itemID = super(MockServerDogmaLocation, self).AddShip(typeID, ownerID, groupID=groupID) 147 self.__balls[itemID] = Bundle(structures=[]) 148 return itemID 149 150 def AddStructure(self, typeID, groupID = 1001): 151 itemID = super(MockServerDogmaLocation, self).AddStructure(typeID, groupID=groupID) 152 self.__balls[itemID] = Bundle() 153 return itemID 154 155 def _GetInventory2(self): 156 return Bundle(IsPrimed=lambda itemID: itemID in self.dogmaItems, GetItem=lambda itemID: self.GetItem(itemID)) 157 158 def _GetBallpark(self): 159 return Bundle(HasBall=lambda ballID: ballID in self.__balls, IsWarping=lambda ballID: False, IsCloaked=lambda ballID: False, IsFrozen=lambda ballID: False, GetBall=self._GetBall, AbortSafeLogoff=lambda *args, **kwargs: None, GetInvulnerableState=lambda ballID: None) 160 161 def _GetBall(self, ballID): 162 return self.__balls[ballID]