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

fwEnlistmentSvc.py (5029B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\fwEnlistmentSvc.py
      2 from localization import GetByLabel
      3 import carbonui.const as uiconst
      4 from carbon.common.script.sys.service import Service
      5 from player_messaging.client.ui_message import prompt_player_fsd_dialog
      6 FACTION_ID_NOT_SET = 'FACTION_ID_NOT_SET'
      7 TIMESTAMP_NOT_SET = 'TIMESTAMP_NOT_SET'
      8 
      9 class FwEnlistmentSvc(Service):
     10     __guid__ = 'svc.fwEnlistmentSvc'
     11     __displayname__ = 'FW Enlistment client service'
     12     __startupdependencies__ = ['machoNet']
     13     __notifyevents__ = ['OnCharacterSessionChanged',
     14      'OnSessionReset',
     15      'OnEnlistmentStateUpdated',
     16      'OnSessionChanged',
     17      'OnEnlistmentCooldownCleared']
     18 
     19     def Run(self, memStream = None):
     20         Service.Run(self, memStream)
     21         self._ResetLocalData()
     22 
     23     def _ResetLocalData(self):
     24         self._myFactionID = FACTION_ID_NOT_SET
     25         self._directFactionID = FACTION_ID_NOT_SET
     26         self._corpFactionID = FACTION_ID_NOT_SET
     27         self._enlistmentCooldownTimestamp = TIMESTAMP_NOT_SET
     28 
     29     def OnCharacterSessionChanged(self, oldCharacterID, newCharacterID):
     30         self._ResetLocalData()
     31 
     32     def OnSessionReset(self):
     33         self._ResetLocalData()
     34 
     35     def OnSessionChanged(self, isRemote, sess, change):
     36         if session.charid and 'warfactionid' in change:
     37             self._ResetLocalData()
     38             sm.ScatterEvent('OnEnlistmentStateUpdated_Local')
     39 
     40     def OnEnlistmentStateUpdated(self, factionID, directFactionID, corpFactionID):
     41         self.LogInfo('OnEnlistmentStateUpdated', factionID, directFactionID, corpFactionID)
     42         self._myFactionID = factionID
     43         self._directFactionID = directFactionID
     44         self._corpFactionID = corpFactionID
     45         self._enlistmentCooldownTimestamp = TIMESTAMP_NOT_SET
     46         sm.ScatterEvent('OnEnlistmentStateUpdated_Local')
     47 
     48     def GetMyFaction(self):
     49         if self._myFactionID == FACTION_ID_NOT_SET:
     50             self._UpdateMyEnlistmentState()
     51         return self._myFactionID
     52 
     53     def IsEnlistedDirectly(self):
     54         if self._directFactionID == FACTION_ID_NOT_SET:
     55             self._UpdateMyEnlistmentState()
     56         return self._directFactionID is not None
     57 
     58     def IsEnlistedViaCorp(self):
     59         self.GetCorpFactionID()
     60         return self._corpFactionID is not None
     61 
     62     def GetCorpFactionID(self):
     63         if self._corpFactionID == FACTION_ID_NOT_SET:
     64             self._UpdateMyEnlistmentState()
     65         return self._corpFactionID
     66 
     67     def _UpdateMyEnlistmentState(self):
     68         factionID, directFactionID, corpFactionID = sm.RemoteSvc('fwCharacterEnlistmentMgr').GetMyEnlistment()
     69         self._myFactionID = factionID
     70         self._directFactionID = directFactionID
     71         self._corpFactionID = corpFactionID
     72 
     73     def RequestDirectEnlistInFaction(self, factionID):
     74         if self.IsEnlistedDirectly():
     75             raise RuntimeError('Cannot request direct enlistment - character is already directly enlisted')
     76         if self.IsEnlistedViaCorp():
     77             if self.GetMyFaction() != self.GetCorpFactionID():
     78                 text = GetByLabel('UI/FactionWarfare/Enlistment/CorpHasJoinPending')
     79                 raise UserError('CustomNotify', {'notify': text})
     80             raise RuntimeError('Cannot request direct enlistment - character is already enlisted via corp')
     81         sm.RemoteSvc('fwCharacterEnlistmentMgr').CreateMyDirectEnlistment(factionID)
     82 
     83     def RemoveMyDirectEnlistment(self):
     84         if not self.IsEnlistedDirectly():
     85             raise RuntimeError('Cannot remove enlistment - character is not directly enlisted')
     86         sm.RemoteSvc('fwCharacterEnlistmentMgr').RemoveMyDirectEnlistment()
     87 
     88     def GetCorpAllowedEnlistmentFactions(self, corporationID):
     89         return sm.RemoteSvc('fwCharacterEnlistmentMgr').GetCorpAllowedEnlistmentFactions(corporationID)
     90 
     91     def SetCorpAllowedEnlistmentFactions(self, allowedFactionIDs):
     92         ret = sm.RemoteSvc('fwCharacterEnlistmentMgr').SetMyCorpAllowedEnlistmentFactions(allowedFactionIDs)
     93         sm.ScatterEvent('OnCorpAllowedEnlistmentFactionsSet')
     94         return ret
     95 
     96     def OnEnlistMeDirectly(self, factionID):
     97         ownerName = cfg.eveowners.Get(factionID).name
     98         headerLabel = GetByLabel('UI/FactionWarfare/JoinConfirmationHeader')
     99         bodyLabel = GetByLabel('UI/FactionWarfare/JoinConfirmationQuestionDirectEnlistment', factionName=ownerName)
    100         ret = prompt_player_fsd_dialog('CustomQuestion', {'header': headerLabel,
    101          'question': bodyLabel}, uiconst.YESNO)
    102         if ret == uiconst.ID_YES:
    103             self.RequestDirectEnlistInFaction(factionID)
    104 
    105     def GetEnlistmentCooldownTimestamp(self):
    106         if self._enlistmentCooldownTimestamp == TIMESTAMP_NOT_SET:
    107             self._enlistmentCooldownTimestamp = sm.RemoteSvc('fwCharacterEnlistmentMgr').GetMyDirectEnlistmentCooldownTimestamp()
    108         return self._enlistmentCooldownTimestamp
    109 
    110     def OnEnlistmentCooldownCleared(self):
    111         self._enlistmentCooldownTimestamp = TIMESTAMP_NOT_SET