scripted_behavior_loader.py (6290B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\loaders\scripted_behavior_loader.py 2 from behaviors.blackboards.scopes import ScopeTypes 3 from behaviors.loaders import BehaviorDoesNotExistError 4 from behaviors.trees.drifters.driftertree import CreateDrifterBehaviorTree, CreateHiveSystemDrifterBehaviorTree 5 from behaviors.trees.fighters import CreateFighterBehaviorTree 6 from behaviors.trees.groups.incursions import CreateDrifterGroupBehaviorTree, CreateGroupBehaviorTree 7 from behaviors.trees.harvesting import CreateHarvestOutpostBehaviorTree 8 from behaviors.trees.incursions.dungeonseekertree import CreateDungeonSeekerBehaviorTree 9 from behaviors.trees.miners.antidps import CreateAntiDpsBehaviorTree 10 from behaviors.trees.miners.antilogistics import CreateAntiLogisticsBehaviorTree 11 from behaviors.trees.miners.basicdpstree import CreateBasicDpsBehaviorTree 12 from behaviors.trees.miners.tackler import CreateTacklerBehaviorTree 13 from behaviors.trees.pirate.shadow_of_the_serpent_trees import CreateRoamingShadowOfTheSerpentTree, CreateShadowOfTheSerpentisGroupTree 14 from behaviors.trees.reinforcements import CreateReinforcementTree 15 from behaviors.trees.scoutsidle import CreateAnalyzeTree 16 from behaviors.trees.sleep import CreateSleepBehaviorTree 17 from behaviors.trees.sleeperscouts import CreateSleeperScoutBehaviorTree, CreateHiveSystemSleeperScoutBehaviorTree 18 from behaviors.trees.driftercommander.driftercommandertree import CreateDrifterCommanderBehaviorTree 19 from behaviors.trees.dungeonboss.dungeonbosstree import CreateDungeonBossBehaviorTree 20 from behaviors.trees.incursions.dungeondriftertree import CreateDungeonDrifterBehaviorTree 21 from behaviors.trees.incursions.roamingdriftertree import CreateRoamingDrifterBehaviorTree 22 from behaviors.registry import get_task_registry 23 from ccpProfile import TimedFunction 24 25 class ScriptedBehaviorLoader(object): 26 27 def __init__(self): 28 self.registry = get_task_registry() 29 self.behaviors_by_scope_by_id = {ScopeTypes.Item: {'sleep': CreateSleepBehaviorTree, 30 'scan': CreateAnalyzeTree, 31 'reinforce': CreateReinforcementTree, 32 'harvest': CreateHarvestOutpostBehaviorTree, 33 'Roaming Sleeper Scout': CreateSleeperScoutBehaviorTree, 34 'Roaming Sleeper Scout In Hive System': CreateHiveSystemSleeperScoutBehaviorTree, 35 'Drifter Battleship': CreateDrifterBehaviorTree, 36 'Drifter Battleship In Hive System': CreateHiveSystemDrifterBehaviorTree, 37 'Drifter Commander': CreateDrifterCommanderBehaviorTree, 38 'Dungeon Boss': CreateDungeonBossBehaviorTree, 39 'Incursion Dungeon Drifter': CreateDungeonDrifterBehaviorTree, 40 'Incursion Dungeon Seeker': CreateDungeonSeekerBehaviorTree, 41 'Incursion Roaming Drifter': CreateRoamingDrifterBehaviorTree, 42 'fighter': CreateFighterBehaviorTree, 43 'Shadow Of The Serpent': CreateRoamingShadowOfTheSerpentTree, 44 'dps': CreateBasicDpsBehaviorTree, 45 'tackler': CreateTacklerBehaviorTree, 46 'antilogistics': CreateAntiLogisticsBehaviorTree, 47 'antidps': CreateAntiDpsBehaviorTree}, 48 ScopeTypes.EntityGroup: {'sleep': CreateSleepBehaviorTree, 49 'Incursion Group': CreateGroupBehaviorTree, 50 'Incursion Drifter Group': CreateDrifterGroupBehaviorTree, 51 'Shadow Of The Serpent Group': CreateShadowOfTheSerpentisGroupTree}} 52 53 @TimedFunction('behaviors::loaders::ScriptedBehaviorLoader::load') 54 def load(self, behavior_id, scope_type = None): 55 behavior_tree_script = None 56 if scope_type: 57 if scope_type in self.behaviors_by_scope_by_id: 58 behaviors_by_id = self.behaviors_by_scope_by_id.get(scope_type) 59 if behaviors_by_id: 60 behavior_tree_script = behaviors_by_id.get(behavior_id) 61 else: 62 for behaviors_by_id in self.behaviors_by_scope_by_id: 63 if behavior_id in behaviors_by_id: 64 behavior_tree_script = behaviors_by_id[behavior_id] 65 66 if behavior_tree_script is None: 67 raise BehaviorDoesNotExistError() 68 behavior_tree = behavior_tree_script() 69 behavior_tree.behaviorId = behavior_id 70 behavior_tree.scopeType = scope_type 71 return behavior_tree 72 73 def get_id_and_names_by_scope(self, scope_type): 74 return [ (str(behavior_id), '[Python] %s' % behavior_id) for behavior_id in self.behaviors_by_scope_by_id.get(scope_type, []) ] 75 76 def convert_script_to_fsd(self, behavior_id, scope_type): 77 behavior_tree = self.load(behavior_id, scope_type=scope_type) 78 root_task = behavior_tree.GetRootTask() 79 behavior_tree_data = {'name': behavior_id, 80 'description': behavior_id, 81 'scopeType': scope_type, 82 'root': self.convert_task_to_dict(root_task)} 83 return behavior_tree_data 84 85 def convert_task_to_dict(self, task): 86 task_name = get_class_name(task) 87 subTasks = [] 88 if task.HasSubTasks(): 89 for sub in task.GetSubTasks(): 90 subTasks.append(self.convert_task_to_dict(sub)) 91 92 return {'taskClass': task_name, 93 'attributes': self.convert_attributes(task_name, task.attributes), 94 'subTasks': subTasks} 95 96 def convert_attributes(self, task_name, attributes): 97 try: 98 return {name:self.convert_value_to_fsd(task_name, name, value) for name, value in attributes.iteritems()} 99 except: 100 raise 101 102 def convert_value_to_fsd(self, task_name, name, value): 103 if name == 'name': 104 return value 105 task_attributes = self.registry.get_class_attributes(task_name) 106 attribute = task_attributes[name] 107 return attribute.convert_attribute_to_fsd(value) 108 109 110 def get_class_name(task): 111 return '%s.%s' % (task.__class__.__module__, task.__class__.__name__)