entities.py (3144B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\conditions\entities.py 2 import logging 3 import evetypes 4 from behaviors.tasks import Task 5 from behaviors.utility.inventory import is_my_cargo_full, is_my_cargo_empty 6 from behaviors.utility.roles import is_commander 7 from ccpProfile import TimedFunction 8 from inventorycommon.const import ownerUnknown 9 from inventorycommon.util import IsNPC 10 logger = logging.getLogger(__name__) 11 12 class HasAnyOfTypesInEntityAdditionalLoot(Task): 13 14 @TimedFunction('behaviors::condition::entities::HasAnyOfTypesInEntityAdditionalLoot::OnEnter') 15 def OnEnter(self): 16 for typeId in self.attributes.typeIds: 17 if self.context.myBall.HasTypeInAdditionalLoot(typeId): 18 self.SetStatusToSuccess() 19 break 20 else: 21 self.SetStatusToFailed() 22 23 24 class OwnerIsNpcCondition(Task): 25 26 @TimedFunction('behaviors::condition::entities::OwnerIsNpcCondition::OnEnter') 27 def OnEnter(self): 28 ownerId = self.GetLastBlackboardValue(self.attributes.ownerIdAddress) 29 if ownerId and (IsNPC(ownerId) or ownerId == ownerUnknown): 30 self.SetStatusToSuccess() 31 else: 32 self.SetStatusToFailed() 33 34 35 class HasEnoughCargoForType(Task): 36 37 @TimedFunction('behaviors::condition::entities::HasEnoughCargoForType::OnEnter') 38 def OnEnter(self): 39 typeId = self.GetLastBlackboardValue(self.attributes.typeIdAddress) 40 if typeId and self.HasEnoughCargoForType(typeId): 41 self.SetStatusToSuccess() 42 else: 43 self.SetStatusToFailed() 44 45 def HasEnoughCargoForType(self, typeId): 46 return self.context.myBall.HasEnoughAdditionalCargoCapacityForType(typeId) 47 48 49 class IsCargoAboveCapacityThreshold(Task): 50 51 @TimedFunction('behaviors::actions::entities::IsCargoAboveCapacityThreshold::OnEnter') 52 def OnEnter(self): 53 self.SetStatusToFailed() 54 totalCapacity = evetypes.GetAttributeForType(self.context.mySlimItem.typeID, 'capacity') 55 if not totalCapacity: 56 logger.error('Entity: %s - failed checking cargo due to having no cargo.', self.context.myItemId) 57 return 58 usedCapacity = totalCapacity - self.context.myBall.GetAvailableAdditionalCargoCapacity() 59 if usedCapacity / totalCapacity >= self.attributes.cargoCapacityThreshold: 60 self.SetStatusToSuccess() 61 62 63 class AmITheCommander(Task): 64 65 @TimedFunction('behaviors::actions::entities::AmITheCommander::OnEnter') 66 def OnEnter(self): 67 self.SetStatusToFailed() 68 if is_commander(self, self.context.myItemId): 69 self.SetStatusToSuccess() 70 71 72 class IsMyCargoFull(Task): 73 74 @TimedFunction('behaviors::actions::entities::IsMyInventoryFull::OnEnter') 75 def OnEnter(self): 76 self.SetStatusToFailed() 77 if is_my_cargo_full(self): 78 self.SetStatusToSuccess() 79 80 81 class IsMyCargoEmpty(Task): 82 83 @TimedFunction('behaviors::actions::entities::IsMyCargoEmpty::OnEnter') 84 def OnEnter(self): 85 self.SetStatusToFailed() 86 if is_my_cargo_empty(self): 87 self.SetStatusToSuccess()