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

dotAppsOnTarget.py (4452B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dotWeapons\common\dotAppsOnTarget.py
      2 import dogma.const as dogmaConst
      3 import gametime
      4 from carbon.common.script.util.mathCommon import FloatCloseEnough
      5 from dotWeapons.common.dotConst import DOT_IDLE, DOT_ACTIVE
      6 from dotWeapons.common.dotPriorityQueue import DotPriorityQueue
      7 from utillib import KeyVal
      8 FLOAT_TOLERANCE_DAMAGE_CHANGES = 0.001
      9 
     10 class DotAppsOnTarget(object):
     11 
     12     def __init__(self, itemID, dogmaLM):
     13         self._itemID = itemID
     14         self.dogmaLM = dogmaLM
     15         self._dotApplications = DotPriorityQueue()
     16         self._damageHpFractionOnLastUpdate = None
     17         self._lastAppliedDamageApp = None
     18 
     19     def AddDotApplication(self, dotApplication):
     20         self._dotApplications.Add(dotApplication)
     21 
     22     def GetHighestDamageDotApplication(self, dogmaLM):
     23         if self._dotApplications.IsEmpty():
     24             return
     25         totalHp = self._GetTotalHp(dogmaLM)
     26         if totalHp is None:
     27             return
     28         currentMaxDmg = 0
     29         currentMaxDmgApp = None
     30         damageResistance = self.dogmaLM.GetAttributeValue(self._itemID, dogmaConst.attributeBreacherPodDamageResistance)
     31         for dotApplication in self._dotApplications.IterateDotApplications():
     32             effectiveDamage = dotApplication.GetEffectiveDamage(totalHp) * damageResistance
     33             if self._ReplaceCurrentMax(currentMaxDmgApp, currentMaxDmg, dotApplication, effectiveDamage):
     34                 currentMaxDmg = effectiveDamage
     35                 currentMaxDmgApp = dotApplication
     36 
     37         damageHpFraction = float(currentMaxDmg) / totalHp
     38         hdi = HighestDamageInfo(currentMaxDmgApp, currentMaxDmg, damageHpFraction)
     39         return hdi
     40 
     41     def _ReplaceCurrentMax(self, maxDamageApplication, currentMaxDamage, dotApplication, damage):
     42         if maxDamageApplication is None:
     43             return True
     44         if damage > currentMaxDamage:
     45             return True
     46         if damage == currentMaxDamage:
     47             if dotApplication == self._lastAppliedDamageApp:
     48                 return True
     49         return False
     50 
     51     def _GetTotalHp(self, dogmaLM):
     52         targetDogmaItem = dogmaLM.SafeGetDogmaItem(self._itemID)
     53         if not targetDogmaItem:
     54             return None
     55         shieldHp = dogmaLM.GetAttributeValue(self._itemID, dogmaConst.attributeShieldCapacity)
     56         armorHP = dogmaLM.GetAttributeValue(self._itemID, dogmaConst.attributeArmorHP)
     57         hullHp = dogmaLM.GetAttributeValue(self._itemID, dogmaConst.attributeHp)
     58         totalHp = shieldHp + armorHP + hullHp
     59         return totalHp
     60 
     61     def ExpireDotApplications(self):
     62         self._dotApplications.ExpireDotApplications(gametime.GetSimTime())
     63 
     64     def HasValidApplications(self):
     65         self.ExpireDotApplications()
     66         return not self._dotApplications.IsEmpty()
     67 
     68     def IsDifferentHpFraction(self, newDamageHpFracation):
     69         if not self._damageHpFractionOnLastUpdate:
     70             return True
     71         if FloatCloseEnough(self._damageHpFractionOnLastUpdate, newDamageHpFracation, FLOAT_TOLERANCE_DAMAGE_CHANGES):
     72             return False
     73         return True
     74 
     75     def UpdateLastUpdatedHpFraction(self, newDamageHpFracation):
     76         self._damageHpFractionOnLastUpdate = newDamageHpFracation
     77 
     78     def UpdateLastDamageApp(self, damgeApp):
     79         attackersToNotify = set()
     80         if self._lastAppliedDamageApp == damgeApp:
     81             return (False, attackersToNotify)
     82         if self._lastAppliedDamageApp:
     83             self._lastAppliedDamageApp.activityState = DOT_IDLE
     84             attackersToNotify.add(self._lastAppliedDamageApp.charID)
     85         if damgeApp:
     86             damgeApp.activityState = DOT_ACTIVE
     87             attackersToNotify.add(damgeApp.charID)
     88         self._lastAppliedDamageApp = damgeApp
     89         return (True, attackersToNotify)
     90 
     91     def GetSimpleVersion(self):
     92         b = KeyVal(targetID=self._itemID, dotApplications=[])
     93         for dotApplications in self._dotApplications.IterateDotApplications():
     94             b.dotApplications.append(dotApplications.GetValues())
     95 
     96         return b
     97 
     98     def GetDataForDotUpdates(self):
     99         return {x.GetBasicInfoForClientUpdate() for x in self._dotApplications.IterateDotApplications()}
    100 
    101 
    102 class HighestDamageInfo(object):
    103 
    104     def __init__(self, dmgApplication, currentMax, damageHpFraction):
    105         self.dmgApplication = dmgApplication
    106         self.damage = currentMax
    107         self.damageHpFraction = damageHpFraction