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

actionDisplay.py (9195B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\tacticalNavigation\actionDisplay.py
      2 from __future__ import absolute_import
      3 import blue
      4 import destiny
      5 import math
      6 import tacticalNavigation.ui.util as tacticalui
      7 import uthread2
      8 from .ballparkFunctions import GetBall, GetBallpark
      9 from destructionEffect import destructionType as destructionEffectType
     10 from eve.client.script.ui.inflight.squadrons.shipFighterState import GetShipFighterState
     11 
     12 class ActionDisplay:
     13 
     14     def __init__(self, navPointContainer):
     15         self.shipid = 'shipid'
     16         self.items = [self.shipid]
     17         self.targetConnectors = {}
     18         self.orbitConnectors = {}
     19         self.navPointContainer = navPointContainer
     20         self.itemKeyToNavPoint = {}
     21         self.abilityTargets = {}
     22         self.shipFighterState = None
     23         self._updateThreadRunning = False
     24 
     25     def Enable(self, enable):
     26         if enable:
     27             if self.shipid not in self.items:
     28                 self.items.append(self.shipid)
     29             if not self._updateThreadRunning:
     30                 self._updateThreadRunning = True
     31                 uthread2.StartTasklet(self._UpdateThread)
     32         else:
     33             self.ClearAll()
     34             self._updateThreadRunning = False
     35 
     36     def SetMaxMoveRange(self, range):
     37         self.maxMoveDistance = range * 2.0
     38 
     39     def _SetNavigationPoint(self, itemKey, globalPosition):
     40         ballID = self._GetBallID(itemKey)
     41         if self._HasCorrectNavPoint(itemKey, globalPosition):
     42             return self.itemKeyToNavPoint[itemKey]
     43         self._RemoveNavPointForBall(itemKey)
     44         navPoint = self.navPointContainer.GetOrCreatePoint(globalPosition)
     45         self.navPointContainer.ConfirmNavPoint(ballID, navPoint)
     46         self.itemKeyToNavPoint[itemKey] = navPoint
     47         return navPoint
     48 
     49     def _RemoveNavPointForBall(self, itemKey):
     50         if itemKey in self.itemKeyToNavPoint:
     51             oldNavPoint = self.itemKeyToNavPoint[itemKey]
     52             self.navPointContainer.Dereference(oldNavPoint)
     53             del self.itemKeyToNavPoint[itemKey]
     54 
     55     def _HasCorrectNavPoint(self, itemKey, globalPosition):
     56         if itemKey in self.itemKeyToNavPoint:
     57             oldNavPoint = self.itemKeyToNavPoint[itemKey]
     58             if oldNavPoint.globalPosition == globalPosition:
     59                 return True
     60         return False
     61 
     62     def _GetBallID(self, itemKey):
     63         if itemKey == self.shipid:
     64             return session.shipid
     65         return itemKey
     66 
     67     def _ClearUIForItem(self, itemKey):
     68         itemID = self._GetBallID(itemKey)
     69         if itemKey in self.itemKeyToNavPoint:
     70             self._RemoveNavPointForBall(itemKey)
     71         if itemKey in self.targetConnectors:
     72             self._RemoveMovementLine(itemKey)
     73         if itemKey in self.orbitConnectors:
     74             self._RemoveOrbit(itemKey)
     75         if itemID in self.abilityTargets:
     76             for targetID in self.abilityTargets[itemID]:
     77                 connector = self.abilityTargets[itemID][targetID]
     78                 connector.Destroy()
     79 
     80             del self.abilityTargets[itemID]
     81 
     82     def ClearAll(self):
     83         for itemKey in self.items:
     84             self._ClearUIForItem(itemKey)
     85 
     86         self.positionToNavPoint = {}
     87         self.itemKeyToNavPoint = {}
     88         self.abilityTargets = {}
     89         self.items = [self.shipid]
     90 
     91     def _AddMovementLine(self, itemKey, sourceBall, targetBall, maxDistance):
     92         if targetBall is None:
     93             return
     94         if itemKey in self.targetConnectors:
     95             self.targetConnectors[itemKey].SetDestinationCurve(targetBall)
     96             self.targetConnectors[itemKey].lineConnector.length = maxDistance
     97         else:
     98             connector = tacticalui.CreateMovementConnector(sourceBall, targetBall)
     99             self.targetConnectors[itemKey] = connector
    100             self.targetConnectors[itemKey].lineConnector.length = maxDistance
    101 
    102     def _RemoveMovementLine(self, itemKey):
    103         if itemKey in self.targetConnectors:
    104             connector = self.targetConnectors[itemKey]
    105             connector.Destroy()
    106             del self.targetConnectors[itemKey]
    107 
    108     def _SetOrbitLine(self, itemKey, sourceBall, targetBall):
    109         if itemKey in self.orbitConnectors:
    110             connector = self.orbitConnectors[itemKey]
    111             self.orbitConnectors[itemKey].SetDestinationCurve(targetBall)
    112             self.orbitConnectors[itemKey].SetSourceCurve(sourceBall)
    113         else:
    114             connector = tacticalui.CreateOrbitConenctor(sourceBall, targetBall)
    115             self.orbitConnectors[itemKey] = connector
    116         connector.lineConnector.length = targetBall.radius + sourceBall.followRange + sourceBall.radius
    117         precession = 0.001
    118         currentTime = GetBallpark().currentTime
    119         phi1 = currentTime * precession
    120         phi2 = (sourceBall.id & 65535) + currentTime * precession
    121         x = math.cos(phi1) * math.cos(phi2)
    122         y = math.sin(phi2)
    123         z = math.sin(phi1) * math.cos(phi2)
    124         connector.lineConnector.planeNormal = (x, y, z)
    125 
    126     def _RemoveOrbit(self, itemKey):
    127         if itemKey in self.orbitConnectors:
    128             connector = self.orbitConnectors[itemKey]
    129             connector.Destroy()
    130             del self.orbitConnectors[itemKey]
    131 
    132     def AddFighter(self, fighterID):
    133         if fighterID in self.items:
    134             return
    135         if self.shipFighterState is None:
    136             self.shipFighterState = GetShipFighterState()
    137             self.shipFighterState.ConnectFighterTargetUpdatedHandler(self._OnFighterTargetUpdate)
    138         self.items.append(fighterID)
    139         self._RebuildConnectorsForFighter(fighterID)
    140 
    141     def _OnFighterTargetUpdate(self, fighterID, abilitySlotID, targetID):
    142         self._RebuildConnectorsForFighter(fighterID)
    143 
    144     def _RebuildConnectorsForFighter(self, fighterID):
    145         if fighterID not in self.abilityTargets:
    146             self.abilityTargets[fighterID] = {}
    147         fighterBall = GetBall(fighterID)
    148         if fighterBall is None:
    149             return
    150         targets = self.shipFighterState.GetAbilityTargetsForFighter(fighterID)
    151         for targetID in self.abilityTargets[fighterID]:
    152             connector = self.abilityTargets[fighterID][targetID]
    153             connector.Destroy()
    154 
    155         self.abilityTargets[fighterID] = {}
    156         for targetID in targets:
    157             targetBall = GetBall(targetID)
    158             if targetBall is not None and not (getattr(targetBall, 'released', False) or getattr(targetBall, 'destructionEffectId', destructionEffectType.NONE) is not destructionEffectType.NONE):
    159                 connector = tacticalui.CreateAgressionConnector(fighterBall, targetBall)
    160                 self.abilityTargets[fighterID][targetID] = connector
    161 
    162         self._UpdateItem(fighterID)
    163 
    164     def RemoveFighter(self, fighterID):
    165         self.items.remove(fighterID)
    166         self._ClearUIForItem(fighterID)
    167 
    168     def RemoveBall(self, ballID):
    169         rebuildFighters = []
    170         for fighterID in self.abilityTargets:
    171             if ballID in self.abilityTargets[fighterID]:
    172                 rebuildFighters.append(fighterID)
    173 
    174         for fighterID in rebuildFighters:
    175             self._RebuildConnectorsForFighter(fighterID)
    176 
    177     def _GetMode(self, ball):
    178         mode = None
    179         if ball.mode == destiny.DSTBALL_GOTO:
    180             mode = destiny.DSTBALL_GOTO
    181         elif ball.mode == destiny.DSTBALL_ORBIT:
    182             mode = ball.mode
    183         elif ball.followId != 0:
    184             mode = destiny.DSTBALL_FOLLOW
    185         return mode
    186 
    187     def _UpdateItem(self, itemKey):
    188         ballID = self._GetBallID(itemKey)
    189         ball = GetBall(ballID)
    190         if ball is None:
    191             self._ClearUIForItem(ballID)
    192             return
    193         maxMoveDistance = 0
    194         if itemKey == self.shipid:
    195             maxMoveDistance = self.maxMoveDistance
    196         followBall = None
    197         if ballID == session.structureid:
    198             mode = None
    199         else:
    200             mode = self._GetMode(ball)
    201         if mode == destiny.DSTBALL_FOLLOW or mode == destiny.DSTBALL_ORBIT:
    202             followBall = GetBall(ball.followId)
    203             self._RemoveNavPointForBall(itemKey)
    204         elif mode == destiny.DSTBALL_GOTO:
    205             globalPosition = (ball.gotoX, ball.gotoY, ball.gotoZ)
    206             followBall = self._SetNavigationPoint(itemKey, globalPosition).GetNavBall()
    207             if followBall is None:
    208                 self._RemoveNavPointForBall(itemKey)
    209         else:
    210             self._RemoveNavPointForBall(itemKey)
    211         if followBall is None:
    212             self._RemoveMovementLine(itemKey)
    213         elif ballID in self.abilityTargets and followBall.id in self.abilityTargets[ballID]:
    214             self._RemoveMovementLine(itemKey)
    215         elif mode == destiny.DSTBALL_ORBIT:
    216             self._RemoveMovementLine(itemKey)
    217         else:
    218             self._AddMovementLine(itemKey, ball, followBall, maxMoveDistance)
    219         if mode == destiny.DSTBALL_ORBIT and followBall:
    220             self._SetOrbitLine(itemKey, ball, followBall)
    221         else:
    222             self._RemoveOrbit(itemKey)
    223 
    224     def _UpdateThread(self):
    225         while self._updateThreadRunning:
    226             for each in self.items:
    227                 self._UpdateItem(each)
    228 
    229             blue.synchro.SleepSim(500)