NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

reinforcements.py (3825B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\actions\reinforcements.py
      2 import logging
      3 from ballpark.entities.reinforcementmanager import CreateReinforcedGroup, ReinforcementWave
      4 from behaviors import status
      5 from behaviors.const.blackboardchannels import UNSPAWN_ENTITY
      6 from behaviors.groups.mixin import GroupTaskMixin
      7 from behaviors.tasks import Task
      8 from behaviors.utility import security
      9 from behaviors.utility.blackboards import get_response_thresholds
     10 from ccpProfile import TimedFunction
     11 logger = logging.getLogger(__name__)
     12 
     13 class CallInReinforcementsAction(Task):
     14 
     15     @TimedFunction('behaviors::actions::reinforcements::CallInReinforcementsAction::OnEnter')
     16     def OnEnter(self):
     17         self.status = status.TaskFailureStatus
     18         groupId = self.context.myEntityGroupId
     19         reinforcementManager = self.context.entityLocation.GetReinforcementManager()
     20         if not reinforcementManager.IsReinforcementAuthorized(groupId):
     21             return
     22         if not reinforcementManager.AreReinforcementsAvailable(groupId):
     23             return
     24         reinforcementManager.CallInReinforcements(self.context.myEntityGroupId, get_response_thresholds(self))
     25         self.status = status.TaskSuccessStatus
     26 
     27 
     28 class AddReinforcementsByOwnerId(Task, GroupTaskMixin):
     29 
     30     @TimedFunction('behaviors::actions::group::AddReinforcementsByOwnerId::OnEnter')
     31     def OnEnter(self):
     32         self.SetStatusToFailed()
     33         if self._IsAlreadyReinforced():
     34             return
     35         spawnlistId = security.get_spawnlist_by_group_owner_and_security_level(self)
     36         if not spawnlistId:
     37             logger.error('Unable to add reinforcements: Owner %s of group %s has no reinforcements defined.', self.GetGroupOwnerId(), self.context.myEntityGroupId)
     38             return
     39         reinforcedGroup = self._CreateReinforcedGroup(spawnlistId)
     40         reinforcedGroup.SetEntityGroupID(self.context.myEntityGroupId)
     41         self.context.entityLocation.reinforcementManager.AddEntityGroupReinforcement(reinforcedGroup)
     42         self.SetStatusToSuccess()
     43 
     44     def _IsAlreadyReinforced(self):
     45         reinforcement_manager = self.context.entityLocation.GetReinforcementManager()
     46         return reinforcement_manager.GetReinforcedGroup(self.context.myEntityGroupId) is not None
     47 
     48     def _CreateReinforcedGroup(self, spawnlistId):
     49         reinforcementWave = ReinforcementWave(reinforcementWaveId=spawnlistId, reinforcementWaveCooldownSeconds=self.attributes.reinforcementWaveCooldownSeconds, reinforcementThreshold=self.attributes.reinforcementThreshold, behaviorOverrideId=self._GetBehaviorOverrideId())
     50         return CreateReinforcedGroup(self._GetEntityCountForOriginalGroup(), self.GetGroupOwnerId(), reinforcementWave, None)
     51 
     52     def _GetEntityCountForOriginalGroup(self):
     53         return len(self.GetMemberIdList())
     54 
     55     def _GetBehaviorOverrideId(self):
     56         if self.HasAttribute('behaviorOverrideId'):
     57             return self.attributes.behaviorOverrideId
     58 
     59 
     60 class CallForUnspawningReinforcements(Task, GroupTaskMixin):
     61 
     62     @TimedFunction('behaviors::actions::group::UnspawnReinforcements::OnEnter')
     63     def OnEnter(self):
     64         reinforcedEntityIds = self.context.entityLocation.reinforcementManager.GetActiveReinforcedEntityIds(self.context.myEntityGroupId)
     65         for entityId in reinforcedEntityIds:
     66             self._CallForUnspawningEntity(entityId)
     67 
     68         self.context.entityLocation.reinforcementManager.RemoveActiveReinforcedEntityIds(self.context.myEntityGroupId)
     69         self.SetStatusToSuccess()
     70 
     71     def _CallForUnspawningEntity(self, entityId):
     72         try:
     73             _, channelAddressName = UNSPAWN_ENTITY
     74             channel = self.GetMessageChannelForItemId(entityId, channelAddressName)
     75             channel.SendMessage(True)
     76         except:
     77             pass