dotRegistry.py (5390B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dotWeapons\common\dotRegistry.py 2 import log 3 import gametime 4 import uthread2 5 from dotWeapons.common.dotApplication import DotApplication 6 from dotWeapons.common.dotApplicationStore import DotApplicationStore 7 from eveexceptions import ExceptionEater 8 import logging 9 logger = logging.getLogger(__name__) 10 DOT_TICK_RATE_SEC = 1 11 SLIM_ITEM_DOT_ATTR_NAME = 'dotHpPercentageApplied' 12 13 class DotRegistry(object): 14 15 def __init__(self, dogmaLM, dotClientNotifier): 16 self.dogmaLM = dogmaLM 17 self.clientNotifier = dotClientNotifier 18 self._dotProcessingTasklet = None 19 self._dynamicDotStore = DotApplicationStore(self.dogmaLM) 20 21 def ApplyHitToTarget(self, targetID, missileInfo): 22 dotApplication = DotApplication(gametime.GetSimTime(), missileInfo, targetID) 23 self._ApplyDotToTargets(targetID, dotApplication) 24 25 def _ApplyDotToTargets(self, targetID, dotApplication): 26 log.LogInfo('DotWeapons: ApplyDotToTargets', dotApplication) 27 self._dynamicDotStore.Insert(targetID, dotApplication) 28 self.clientNotifier.ScheduleTargetUpdate(targetID) 29 self.clientNotifier.ScheduleAttackerUpdate(dotApplication.charID, targetID) 30 31 def GetDotWeaponsByTargetID(self): 32 return self._dynamicDotStore.GetDotApplicationsForAllTargets() 33 34 def ProcessDotAppssInQueue(self): 35 log.LogInfo('DotWeapons: ProcessDotAppssInQueue') 36 ballpark = self.dogmaLM.ballpark 37 targetsToRemove = [] 38 damageInfoByTargetID = {} 39 for targetID, dotWeapons in self._dynamicDotStore.IterateApplicationByTargetID(): 40 dotWeapons.ExpireDotApplications() 41 if not dotWeapons.HasValidApplications(): 42 targetsToRemove.append(targetID) 43 continue 44 highestDamageInfo = dotWeapons.GetHighestDamageDotApplication(self.dogmaLM) 45 if highestDamageInfo is None: 46 continue 47 damageInfoByTargetID[targetID] = (dotWeapons, highestDamageInfo) 48 49 self.RemoveTargetsWithoutEffets(targetsToRemove) 50 self.ApplyDamageToTargets(ballpark, damageInfoByTargetID) 51 52 def ApplyDamageToTargets(self, ballpark, damageInfoByTargetID): 53 for targetID, damageInfo in damageInfoByTargetID.iteritems(): 54 try: 55 dotWeaponsForTarget, highestDamageInfo = damageInfo 56 dmgApp = highestDamageInfo.dmgApplication 57 self.dogmaLM.broker.dogma.ApplyFlatDamage(dmgApp.sourceShipItem.itemID, dmgApp.sourceShipItem, dmgApp.weaponItem, targetID, highestDamageInfo.damage, dmgApp.charID, self.dogmaLM) 58 damageHpFraction = highestDamageInfo.damageHpFraction 59 if dotWeaponsForTarget.IsDifferentHpFraction(damageHpFraction): 60 ballpark.UpdateSlimItemField(targetID, SLIM_ITEM_DOT_ATTR_NAME, 100 * damageHpFraction) 61 dotWeaponsForTarget.UpdateLastUpdatedHpFraction(damageHpFraction) 62 attackerChanged, attackersToNotify = dotWeaponsForTarget.UpdateLastDamageApp(dmgApp) 63 if attackerChanged: 64 self.clientNotifier.ScheduleTargetUpdate(targetID) 65 for attackerID in attackersToNotify: 66 self.clientNotifier.ScheduleAttackerUpdate(attackerID, targetID) 67 68 except Exception as e: 69 logger.exception('DotWeapons: Failed to apply damage') 70 71 def RemoveTargetsWithoutEffets(self, targetsToRemove): 72 ballpark = self.dogmaLM.ballpark 73 for targetID in targetsToRemove: 74 if not self._dynamicDotStore.IsTargetRecored(targetID): 75 continue 76 if self._dynamicDotStore.DoesTargetHaveValidApplication(targetID): 77 continue 78 self._dynamicDotStore.DeleteAllForTarget(targetID) 79 ballpark.DeleteSlimItemField(targetID, SLIM_ITEM_DOT_ATTR_NAME) 80 self.clientNotifier.ScheduleTargetUpdate(targetID) 81 82 def ClearApplicationsForTarget(self, targetID): 83 removed = self._dynamicDotStore.DeleteAllForTarget(targetID) 84 if removed: 85 self.dogmaLM.ballpark.DeleteSlimItemField(targetID, SLIM_ITEM_DOT_ATTR_NAME) 86 self.clientNotifier.ScheduleTargetUpdate(targetID) 87 88 def GetDotAppsOnTarget(self, targetID): 89 return self._dynamicDotStore.GetDotAppsOnTarget(targetID) 90 91 def ScheduleTargetUpdate(self, targetID): 92 self.clientNotifier.ScheduleTargetUpdate(targetID) 93 94 def KillDotProcessingTasklet(self): 95 if self._dotProcessingTasklet: 96 self._dotProcessingTasklet.Kill() 97 self._dotProcessingTasklet = None 98 99 def StartDotProcessingTasklet(self): 100 self.KillDotProcessingTasklet() 101 self._dotProcessingTasklet = self._StartDotProcessingTasklet() 102 103 def _StartDotProcessingTasklet(self): 104 105 def ProcessingFunc(): 106 while True: 107 with ExceptionEater('Error in ProcessDotAppssInQueue'): 108 self.ProcessDotAppssInQueue() 109 uthread2.SleepSim(DOT_TICK_RATE_SEC) 110 111 tasklet = uthread2.StartTasklet(ProcessingFunc, stackless_tracing_enabled=False) 112 tasklet.context = 'dotWeapon::StartDotProcessingTasklet' 113 return tasklet 114 115 def IsDotPorcessingTaskletRunning(self): 116 return bool(self._dotProcessingTasklet)