objectspawning.py (5211B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\actions\objectspawning.py 2 import random 3 import logging 4 import evetypes 5 from behaviors.tasks import Task 6 from behaviors.utility.ballparks import get_my_position 7 from behaviors.utility.inventory import get_inventory2 8 from behaviors.utility.owner import get_owner_id 9 from inventorycommon.const import flagNone 10 from utillib import KeyVal 11 logger = logging.getLogger(__name__) 12 13 class SpawnSpaceObjectsFromDungeon(Task): 14 15 def OnEnter(self): 16 self.SetStatusToSuccess() 17 inventory_2 = get_inventory2(self) 18 owner_id = get_owner_id(self) 19 replaced_object = self._generate_replaced_objects() 20 assets = self._get_assets_from_dungeon() 21 for object_for_spawning in assets: 22 object_name_id = object_for_spawning.objectNameID 23 object_custom_info = self._get_object_custom_info(object_for_spawning, object_name_id) 24 type_id = self._get_type_id_for_object_spawning(object_for_spawning.typeID, replaced_object) 25 if type_id is None: 26 continue 27 inventory_2.AddFakeLocation(type_id, owner_id, self.context.ballpark.solarsystemID, flagNone, 1, '', self.context.myBall.x + object_for_spawning.x, self.context.myBall.y + object_for_spawning.y, self.context.myBall.z + object_for_spawning.z, object_name_id, object_custom_info) 28 29 def _generate_replaced_objects(self): 30 return {self.attributes.object1TypeIdForReplacing: {'count': 0, 31 'max_count': random.randint(self.attributes.object1MinCount, self.attributes.object1MaxCount), 32 'type_list_id': self.attributes.eveTypeList1}, 33 self.attributes.object2TypeIdForReplacing: {'count': 0, 34 'max_count': random.randint(self.attributes.object2MinCount, self.attributes.object2MaxCount), 35 'type_list_id': self.attributes.eveTypeList2}, 36 self.attributes.object3TypeIdForReplacing: {'count': 0, 37 'max_count': random.randint(self.attributes.object3MinCount, self.attributes.object3MaxCount), 38 'type_list_id': self.attributes.eveTypeList3}} 39 40 def _get_assets_from_dungeon(self): 41 dungeon_id = self._get_dungeon_id() 42 keeper = sm.GetService('keeper') 43 dungeon_data = keeper.GetDungeonData(dungeon_id) 44 return dungeon_data.roomObjects[next(iter(dungeon_data.roomObjects))] 45 46 def _get_dungeon_id(self): 47 return self.attributes.dungeonId 48 49 def _get_object_custom_info(self, object_for_spawning, object_name_id): 50 custom_info = KeyVal() 51 if None not in (object_for_spawning.yaw, object_for_spawning.pitch, object_for_spawning.roll) and (object_for_spawning.yaw or object_for_spawning.pitch or object_for_spawning.roll): 52 custom_info.dunRotation = (object_for_spawning.yaw, object_for_spawning.pitch, object_for_spawning.roll) 53 if object_for_spawning.objectID is not None: 54 custom_info.dunObjectID = object_for_spawning.objectID 55 custom_info.dunObjectNameID = object_name_id 56 return custom_info 57 58 def _get_type_id_for_object_spawning(self, object_type_id, replaced_object): 59 if object_type_id not in replaced_object: 60 return object_type_id 61 if replaced_object[object_type_id]['count'] == replaced_object[object_type_id]['max_count']: 62 return None 63 type_list_id = evetypes.GetTypeIDsByListID(replaced_object[object_type_id]['type_list_id']) 64 picked_type_id = random.choice(tuple(type_list_id)) 65 replaced_object[object_type_id]['count'] += 1 66 return picked_type_id 67 68 69 def _get_spawn_coordinates(task): 70 if task.HasAttribute('coordinateAddress'): 71 return task.GetLastBlackboardValue(task.attributes.coordinateAddress) 72 return get_my_position(task) 73 74 75 class SpawnSpaceObject(Task): 76 77 def OnEnter(self): 78 inventory_2 = get_inventory2(self) 79 owner_id = get_owner_id(self) 80 coordinates = _get_spawn_coordinates(self) 81 if coordinates is None: 82 self.SetStatusToFailed() 83 return 84 x, y, z = coordinates 85 inventory_2.AddFakeLocation(self.attributes.typeId, owner_id, self.context.ballpark.solarsystemID, flagNone, 1, '', x, y, z) 86 self.SetStatusToSuccess() 87 88 89 class SpawnPersistentSpaceObject(Task): 90 91 def OnEnter(self): 92 inventory_2 = get_inventory2(self) 93 owner_id = get_owner_id(self) 94 coordinates = _get_spawn_coordinates(self) 95 if coordinates is None: 96 self.SetStatusToFailed() 97 return 98 x, y, z = coordinates 99 item = inventory_2.EveInsertLocation(self.attributes.typeId, owner_id, self.context.ballpark.solarsystemID, flagNone, '', x, y, z) 100 self.SetStatusToSuccess() 101 logger.info('Behavior %s spawned PersistentSpaceObject of type : %s and itemID: %s', self.behaviorTree.GetBehaviorId(), self.attributes.typeId, item.itemID)