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

chargedAttribute.py (3490B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dogma\attributes\chargedAttribute.py
      2 import gametime
      3 from dogma.attributes import Attribute
      4 from math import exp, sqrt
      5 from dogma.dogmaLogging import LogTraceback
      6 from dogma.const import dgmTauConstant
      7 import weakref
      8 
      9 class ChargedAttribute(Attribute):
     10 
     11     def __init__(self, attribID, baseValue, dogmaItem, dogmaLM, staticAttr):
     12         super(ChargedAttribute, self).__init__(attribID, baseValue, dogmaItem, dogmaLM, staticAttr)
     13         self.rechargeRateAttribute = weakref.proxy(self.item.attributes[staticAttr.chargeRechargeTimeID])
     14         capVal = self.capAttrib.GetValue()
     15         self.currentValue = min(capVal, self.currentValue)
     16         self.prevCap = capVal
     17         self.lastCalcTime = gametime.GetSimTime()
     18         self.rechargeRate = self.rechargeRateAttribute.GetValue() / 5.0
     19         self.rechargeRateAttribute.AddNonModifyingDependant(self)
     20 
     21     def Update(self):
     22         capVal = self.capAttrib.GetValue()
     23         self.rechargeRate = self.rechargeRateAttribute.GetValue() / 5.0
     24         rechargeDelayFactor = self.rechargeRate
     25         if capVal == 0:
     26             self.currentValue = 0
     27             self.prevCap = 0
     28             return
     29         if capVal != self.prevCap:
     30             if self.prevCap > 0:
     31                 oldRatio = self.currentValue / self.prevCap
     32                 self.currentValue = oldRatio * capVal
     33             self.prevCap = capVal
     34         if capVal <= self.currentValue:
     35             self.currentValue = capVal
     36             return
     37         if rechargeDelayFactor == 0:
     38             self.lastCalcTime = gametime.GetSimTime()
     39             return
     40         currentTime = gametime.GetSimTime()
     41         timeDiff_ms = (currentTime - self.lastCalcTime) / float(dgmTauConstant)
     42         if timeDiff_ms < -0.0001:
     43             return
     44         oldRatio = self.currentValue / capVal
     45         root = sqrt(oldRatio)
     46         rootBlendFactor = exp(-timeDiff_ms / rechargeDelayFactor)
     47         rootBlended = (root - 1.0) * rootBlendFactor + 1.0
     48         newRatio = rootBlended ** 2
     49         self.currentValue = newRatio * capVal
     50         self.lastCalcTime = currentTime
     51 
     52     def GetValue(self):
     53         if self.dirty or self.lastCalcTime != gametime.GetSimTime():
     54             self.Update()
     55         return self.currentValue
     56 
     57     def GetFullChargedInfo(self):
     58         if self.dirty or self.lastCalcTime != gametime.GetSimTime():
     59             self.Update()
     60         return (self.currentValue, self.prevCap, self.rechargeRate)
     61 
     62     def MarkDirty(self, silent = False):
     63         super(ChargedAttribute, self).MarkDirty(silent)
     64         if not silent:
     65             self.Update()
     66 
     67     def SetBaseValue(self, newBaseValue):
     68         if self.currentValue != newBaseValue:
     69             self.currentValue = newBaseValue
     70             self.lastCalcTime = gametime.GetSimTime()
     71             self.MarkDirty()
     72 
     73     def AddIncomingModifier(self, op, attribute):
     74         LogTraceback('Cannot modify a charged attribute!')
     75 
     76     def RemoveIncomingModifier(self, op, attribute):
     77         LogTraceback('Cannot modify a charged attribute!')
     78 
     79     def ResetBaseValue(self):
     80         self.Update()
     81         self.currentValue = self.typeValue
     82 
     83     def IncreaseBaseValue(self, addAmount):
     84         self.Update()
     85         self.currentValue += addAmount
     86 
     87     def DecreaseBaseValue(self, decAmount):
     88         self.Update()
     89         self.currentValue -= decAmount
     90 
     91     def GetPersistData(self):
     92         self.Update()
     93         return self.currentValue