dotClientUtil.py (5369B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dotWeapons\client\dotClientUtil.py 2 from collections import defaultdict 3 import evetypes 4 import gametime 5 from dotWeapons.common.dotAppInfo import DotApplicationInfo 6 from dotWeapons.common.dotConst import DOT_ACTIVE, DOT_IDLE 7 from dotWeapons.common.dotUtil import GetEffectiveDamage 8 from eve.client.script.ui.inflight.shipHud.buffButtonsUtil import HintRow 9 from gametime import GetSimTime 10 from localization import GetByLabel 11 from localization.formatters import FormatTimeIntervalShortWritten 12 13 def GetFormattedDotInfoForCurrentShip(incomingDotTracker): 14 all = incomingDotTracker.GetDmgInfoForShipID(session.shipid) 15 active = [ x for x in all if x.activityState == DOT_ACTIVE ] 16 allPruned = PruneAndOrderDamageInfo(all) 17 idle = [ x for x in allPruned if x.activityState == DOT_IDLE ] 18 hpTotalMax = _GetTotalHp() 19 hintList = [] 20 for dmgList, header in ((active, GetByLabel('UI/Inflight/DotWeaponsCurrent')), (idle, GetByLabel('UI/Inflight/DotWeaponsPending'))): 21 if not dmgList: 22 continue 23 hintList.append(HintRow(fullRowText=header)) 24 for d in dmgList: 25 hr = _GetHintRowForDotVictim(d, hpTotalMax) 26 hintList.append(hr) 27 28 return hintList 29 30 31 def GetFormattedPendingDotsAsAttacker(incomingDotTracker): 32 ballpark = sm.GetService('michelle').GetBallpark() 33 hintList = [] 34 dmgInfoByAttacker = incomingDotTracker.GetOnGridDamageInfosForAttacker(session.charid) 35 if not dmgInfoByAttacker: 36 return hintList 37 active = [ x for x in dmgInfoByAttacker if x.activityState == DOT_ACTIVE ] 38 idle = PrunePendingAttackList([ x for x in dmgInfoByAttacker if x.activityState == DOT_IDLE ]) 39 for dmgList, header in ((active, GetByLabel('UI/Inflight/DotWeaponsCurrent')), (idle, GetByLabel('UI/Inflight/DotWeaponsPending'))): 40 if dmgList: 41 hintList.append(HintRow(fullRowText=header)) 42 for dmgInfo in dmgList: 43 hr = _GetHintRowForDotAttacker(dmgInfo, ballpark) 44 if hr: 45 hintList.append(hr) 46 47 return hintList 48 49 50 def _GetHintRowForDotVictim(dotInfo, hpTotalMax): 51 displayName = cfg.eveowners.Get(dotInfo.attackerID).name 52 if dotInfo.expiryTime is not None: 53 timeRemaining = max(0, dotInfo.expiryTime - GetSimTime()) 54 formattedTimeRemaining = FormatTimeIntervalShortWritten(timeRemaining) 55 else: 56 formattedTimeRemaining = '' 57 effectiveDamage = int(GetEffectiveDamage(dotInfo.maxDamage, dotInfo.maxHPNormalizedRatio, hpTotalMax)) 58 damageText = GetByLabel('UI/Inflight/DotWeaponsDps', dps=effectiveDamage) 59 hr = HintRow(col1=damageText, col2=displayName, col3=formattedTimeRemaining) 60 return hr 61 62 63 def _GetHintRowForDotAttacker(dotInfo, ballpark): 64 slimItem = ballpark.GetInvItem(dotInfo.targetID) 65 if not slimItem: 66 return 67 if slimItem.charID: 68 displayName = cfg.eveowners.Get(slimItem.charID).name 69 else: 70 displayName = slimItem.name 71 if dotInfo.expiryTime is not None: 72 timeRemaining = max(0, dotInfo.expiryTime - GetSimTime()) 73 formattedTimeRemaining = FormatTimeIntervalShortWritten(timeRemaining) 74 else: 75 formattedTimeRemaining = '' 76 maxDamage = int(dotInfo.maxDamage) 77 damageText = GetByLabel('UI/Inflight/DotWeaponsDps', dps=maxDamage) 78 hr = HintRow(col1=damageText, col2=displayName, col3=formattedTimeRemaining) 79 return hr 80 81 82 def PruneAndOrderDamageInfo(dmgInfo): 83 totalHp = _GetTotalHp() 84 sortedDamageInfoList = sorted(dmgInfo, key=lambda x: (x.activityState, x.GetEffectiveDamage(totalHp), x.expiryTime)) 85 relevant = [] 86 while sortedDamageInfoList: 87 currentDmgInfo = sortedDamageInfoList.pop(0) 88 if sortedDamageInfoList: 89 if not _IsDamageInfoRelevant(currentDmgInfo, sortedDamageInfoList, totalHp): 90 continue 91 relevant.append(currentDmgInfo) 92 93 relevant.reverse() 94 return relevant 95 96 97 def _IsDamageInfoRelevant(currentDmgInfo, sortedDamageInfo, totalHp): 98 for dmgInfo in sortedDamageInfo: 99 if dmgInfo.attackerID == currentDmgInfo.attackerID: 100 if currentDmgInfo.IsMaskedBy(dmgInfo, totalHp): 101 return False 102 103 return True 104 105 106 def PrunePendingAttackList(pendingDmgInfoList): 107 infoByTargetID = defaultdict(list) 108 for x in pendingDmgInfoList: 109 infoByTargetID[x.targetID].append(x) 110 111 ret = [] 112 for dmgList in infoByTargetID.itervalues(): 113 dmgList.sort(key=lambda x: x.expiryTime, reverse=True) 114 longestLasting = dmgList[0] 115 ret.append(longestLasting) 116 117 ret.sort(key=lambda x: x.expiryTime) 118 return ret 119 120 121 def _GetTotalHp(): 122 from eve.client.script.ui.inflight.shipHud import ActiveShipController 123 ship_controller = ActiveShipController() 124 return ship_controller.GetTotalHpMax() 125 126 127 def GetTotalTimeHintRow(incomingDotWeaponTracker): 128 timestamp = incomingDotWeaponTracker.GetLastExpiryTimestampForCurrentShip() 129 if not timestamp: 130 return [] 131 timeRemaining = timestamp - gametime.GetSimTime() 132 if timeRemaining < 0: 133 return [] 134 formattedTimeRemaining = FormatTimeIntervalShortWritten(timeRemaining) 135 text = GetByLabel('UI/Inflight/DotWeaponsPendingTotalDuration', totalTime=formattedTimeRemaining) 136 hr = HintRow(fullRowText=text) 137 return [hr]