timers.py (1370B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\decorators\timers.py 2 from behaviors.decorators import Decorator 3 import logging 4 from ccpProfile import TimedFunction 5 import random 6 logger = logging.getLogger(__name__) 7 8 class CooldownTimer(Decorator): 9 10 @TimedFunction('behaviors::decorators::timers::CooldownTimer::OnEnter') 11 def OnEnter(self): 12 self.SetStatusToFailed() 13 channel = self.GetChannelFromAddress(self.attributes.timerAddress) 14 timerValue = channel.GetLastMessageValue() 15 if timerValue is None: 16 super(CooldownTimer, self).OnEnter() 17 self.context.timerManager.StartTimer(self.GetTimeoutSeconds(), channel) 18 channel.AddObserver(self.OnTimeout) 19 20 def GetTimeoutSeconds(self): 21 return self.attributes.timeoutSeconds 22 23 def OnTimeout(self, name, message): 24 if message.value is None and not self.IsInvalid(): 25 self.behaviorTree.RequestReset(requestedBy=self) 26 27 def CleanUp(self): 28 if not self.IsInvalid(): 29 self.UnsubscribeToBlackboard(self.attributes.timerAddress, self.OnTimeout) 30 super(CooldownTimer, self).CleanUp() 31 32 33 class RandomCooldownTimer(CooldownTimer): 34 35 def GetTimeoutSeconds(self): 36 return random.randint(self.attributes.minTimeoutSeconds, self.attributes.maxTimeoutSeconds)