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

cosmeticsSvc.py (10661B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\cosmeticsSvc.py
      2 from __future__ import absolute_import
      3 from carbon.common.script.sys.service import Service
      4 from cosmetics.client.shipSkinApplicationSvc import get_ship_skin_application_svc
      5 from cosmetics.client.shipSkinStateController import ShipSkinStateController
      6 from cosmetics.client.structureCosmeticStatesController import StructureCosmeticStatesController
      7 from cosmetics.client.ships.skins.static_data.first_party_skins import FirstPartyStaticLicense, FirstPartyStaticSkin, FirstPartyStaticMaterial, FirstPartySkin
      8 from eve.common.script.sys.idCheckers import IsShip
      9 from eveprefs import boot
     10 import shipskins
     11 import evetypes
     12 from localization import GetByMessageID
     13 from .shipLogoController import ShipLogoController
     14 from eve.common.script.sys.idCheckers import IsCharacter, IsPlayerItem
     15 
     16 class CosmeticsService(Service):
     17     __guid__ = 'svc.cosmeticsSvc'
     18     __startupdependencies__ = ['publicGatewaySvc']
     19     __notifyevents__ = ['OnSkinLicenseActivated',
     20      'OnSkinLicenseRemoved',
     21      'OnSessionReset',
     22      'OnSessionChanged',
     23      'OnPodOrCorvetteAssembly']
     24 
     25     def Run(self, memStream = None):
     26         Service.Run(self, memStream)
     27         sm.FavourMe(self.OnSkinLicenseActivated)
     28         sm.FavourMe(self.OnSkinLicenseRemoved)
     29         self._ship_logo_controller = ShipLogoController()
     30         self._structure_cosmetic_states_controller = StructureCosmeticStatesController(self._get_public_gateway())
     31         self._skin_state_controller = ShipSkinStateController(self.publicGatewaySvc)
     32         self.static = shipskins.SkinStaticData(region=boot.region)
     33         self.lastSkinChange = None
     34         self.ResetCache()
     35 
     36     def Stop(self, memStream = None):
     37         self._structure_cosmetic_states_controller.shutdown()
     38         self._skin_state_controller.shutdown()
     39         super(CosmeticsService, self).Stop(memStream)
     40 
     41     def _get_public_gateway(self):
     42         return sm.GetService('publicGatewaySvc')
     43 
     44     def OnSessionChanged(self, _is_remote, _session, change):
     45         if 'charid' in change:
     46             self._ship_logo_controller.flush_cache()
     47             self._skin_state_controller.on_character_changed()
     48         if 'solarsystemid' in change:
     49             self._start_structure_cosmetic_state_update(session.solarsystemid2)
     50 
     51     def OnSessionReset(self):
     52         self.ResetCache()
     53 
     54     def ResetCache(self):
     55         self.ResetPersonalCache()
     56 
     57     def ResetPersonalCache(self):
     58         self._licensedSkins = None
     59         self._licensedSkinsByType = {}
     60 
     61     def GetAppliedSkinStateForCurrentSession(self, itemID):
     62         return self.GetAppliedSkinState(session.charid, itemID)
     63 
     64     def GetAppliedSkinState(self, licenseeID, itemID):
     65         if not IsCharacter(licenseeID) or not IsPlayerItem(itemID):
     66             return None
     67         try:
     68             return self._skin_state_controller.get_skin_state(itemID, licenseeID)
     69         except Exception as exc:
     70             self.LogInfo('Failed to retrieve current SKIN for ship {ship_id}, returning default. {exc}'.format(ship_id=itemID, exc=exc))
     71 
     72     def GetCachedAppliedSkinState(self, licenseeID, itemID):
     73         if not IsPlayerItem(itemID):
     74             return None
     75         return self._skin_state_controller.get_cached_skin_state(itemID, licenseeID)
     76 
     77     def ActivateShipSkinLicense(self, itemIDs):
     78         sm.RemoteSvc('shipCosmeticsMgr').ActivateSkinLicense(itemIDs)
     79 
     80     def GetSkins(self, hullTypeID):
     81         if not self.IsShip(hullTypeID):
     82             return []
     83         skinsByMaterial = {}
     84         licensedSkins = self.GetLicensedSkinsForType(hullTypeID)
     85         if licensedSkins:
     86             for licensedSkin in licensedSkins:
     87                 skin = self._CreateFirstPartySkinDataFromID(skinID=licensedSkin.skinID, licensed=True, expires=licensedSkin.expires, isSingleUse=licensedSkin.isSingleUse)
     88                 skinsByMaterial[skin.materialID] = skin
     89 
     90         staticSkins = self.static.GetSkinsForTypeID(hullTypeID)
     91         if staticSkins:
     92             for skin in staticSkins:
     93                 material = self.static.materials[skin.skinMaterialID]
     94                 if material.skinMaterialID not in skinsByMaterial:
     95                     skinsByMaterial[material.skinMaterialID] = FirstPartySkin(material)
     96 
     97         return skinsByMaterial.values()
     98 
     99     def GetLicensedSkins(self):
    100         if self._licensedSkins is None:
    101             shipCosmeticsMgr = sm.RemoteSvc('shipCosmeticsMgr')
    102             self._licensedSkins = shipCosmeticsMgr.GetLicencedSkins()
    103         return self._licensedSkins
    104 
    105     def GetLicensedSkinsForType(self, typeID):
    106         if self.IsShip(typeID):
    107             return self._GetLicensedPersonalSkinsForType(typeID)
    108 
    109     def _GetLicensedPersonalSkinsForType(self, typeID):
    110         if typeID not in self._licensedSkinsByType:
    111             shipCosmeticsMgr = sm.RemoteSvc('shipCosmeticsMgr')
    112             licensedSkins = shipCosmeticsMgr.GetLicencedSkinsForShipType(session.charid, typeID)
    113             self._licensedSkinsByType[typeID] = licensedSkins
    114         return self._licensedSkinsByType[typeID]
    115 
    116     def GetFirstPartySkinObjectForCurrentSession(self, skinID):
    117         return self.GetFirstPartySkinObject(session.charid, skinID)
    118 
    119     def GetFirstPartySkinObject(self, licenseeID, skinID):
    120         skin_data = sm.RemoteSvc('shipCosmeticsMgr').GetFirstPartySkinData(licenseeID, skinID)
    121         if skin_data is None:
    122             return
    123         return self._CreateFirstPartySkinDataFromID(skinID, licensed=True, expires=skin_data.expires, isSingleUse=skin_data.isSingleUse)
    124 
    125     def GetFirstPartySkinMaterialID(self, skinID):
    126         return self.static.skins[skinID].skinMaterialID
    127 
    128     def GetFirstPartySkinMaterialSetID(self, skinID):
    129         skin = self.static.skins[skinID]
    130         material = self.static.materials[skin.skinMaterialID]
    131         return material.materialSetID
    132 
    133     def GetFirstPartySkinMaterialDisplayName(self, skinID):
    134         skin = self.static.skins[skinID]
    135         material = self.static.materials[skin.skinMaterialID]
    136         messageID = int(material.displayNameID)
    137         return GetByMessageID(messageID)
    138 
    139     def GetSkinByLicenseType(self, typeID):
    140         license = self.static.licenses[typeID]
    141         return self._CreateFirstPartySkinDataFromID(license.skinID)
    142 
    143     def InternalApplySkin(self, itemID, hullTypeID, skin):
    144         skinID = skin.skinID if skin is not None else None
    145         if self.IsShip(hullTypeID):
    146             sm.RemoteSvc('shipCosmeticsMgr').ApplySkinToShip(itemID, skinID)
    147 
    148     def _CreateFirstPartySkinDataFromID(self, skinID, licensed = False, expires = None, isSingleUse = False):
    149         skin = self.static.skins[skinID]
    150         material = self.static.materials[skin.skinMaterialID]
    151         return FirstPartySkin(material, skin=skin, licensed=licensed, expires=expires, isSingleUse=isSingleUse, isStructureSkin=skin.isStructureSkin)
    152 
    153     def CreateSkinObjectFromLicensedSkin(self, staticSkin, licensedSkin = None):
    154         licensed = licensedSkin is not None
    155         expires = licensedSkin.expires if licensedSkin else None
    156         isSingleUse = licensedSkin.isSingleUse if licensedSkin else None
    157         return self._CreateFirstPartySkinDataFromID(staticSkin.skinID, licensed=licensed, expires=expires, isSingleUse=isSingleUse)
    158 
    159     def GetStaticLicenseByID(self, typeID):
    160         return FirstPartyStaticLicense(self.static, self.static.GetLicenseByID(typeID))
    161 
    162     def GetStaticSkinByID(self, skinID):
    163         return FirstPartyStaticSkin(self.static, self.static.GetSkinByID(skinID))
    164 
    165     def GetStaticMaterialByID(self, materialID):
    166         return FirstPartyStaticMaterial(self.static, self.static.GetMaterialByID(materialID))
    167 
    168     def FindOffersForTypes(self, typeIDs):
    169         try:
    170             store = sm.GetService('vgsService').GetStore()
    171             offers = store.SearchOffersByTypeIDs(typeIDs)
    172             return offers
    173         except Exception as e:
    174             if len(e.args) >= 1 and e.args[0] == 'tokenMissing':
    175                 self.LogWarn('Failed to search the NES for offers due to missing token')
    176             else:
    177                 self.LogException('Failed to search the NES for offers')
    178             return []
    179 
    180     def FindOffersForTypeWithMaterial(self, typeID, materialID):
    181         licenseTypes = self.GetLicencesForTypeWithMaterial(typeID, materialID)
    182         return self.FindOffersForTypes(licenseTypes)
    183 
    184     def GetLicencesForTypeWithMaterial(self, typeID, materialID):
    185         licenses = self.static.GetLicensesForTypeWithMaterial(typeID, materialID)
    186         return [ l.licenseTypeID for l in licenses ]
    187 
    188     def OpenMarketForTypeWithMaterial(self, typeID, materialID):
    189         licenses = self.GetLicencesForTypeWithMaterial(typeID, materialID)
    190         if licenses:
    191             sm.GetService('marketutils').ShowMarketDetails(licenses[0])
    192 
    193     def OnSkinLicenseActivated(self, _skinID, licenseeID):
    194         if licenseeID == session.charid:
    195             self.ResetPersonalCache()
    196 
    197     def OnSkinLicenseRemoved(self, _skinID, itemID, typeID):
    198         self.ResetCache()
    199 
    200     def OnPodOrCorvetteAssembly(self, item_id, type_id):
    201         get_ship_skin_application_svc().apply_default_skin(item_id, type_id)
    202 
    203     def enable_ship_cosmetic_license(self, license, slotIndex, groupIndex, enable):
    204         return self._ship_logo_controller.enable_ship_cosmetic_license(license, slotIndex, groupIndex, enable)
    205 
    206     def get_enabled_ship_cosmetics(self, shipID, forceRefresh = False, raises = False):
    207         try:
    208             return self._ship_logo_controller.get_enabled_ship_cosmetics(shipID, forceRefresh)
    209         except RuntimeError:
    210             if raises:
    211                 raise
    212             else:
    213                 return []
    214 
    215     def are_ship_emblems_disabled(self):
    216         return self._ship_logo_controller.are_ship_emblems_disabled()
    217 
    218     def get_cached_structure_cosmetic_state(self, structure_id):
    219         return self._structure_cosmetic_states_controller.get_cached_cosmetic_state(structure_id)
    220 
    221     def get_structure_cosmetic_state(self, structure_id, solar_system_id, force_refresh = False):
    222         return self._structure_cosmetic_states_controller.get_cosmetic_state(structure_id, solar_system_id, force_refresh)
    223 
    224     def get_structure_cosmetic_license_id_from_state(self, structure_id, solar_system_id, force_refresh = False):
    225         return self._structure_cosmetic_states_controller.get_cosmetic_license_id(structure_id, solar_system_id, force_refresh)
    226 
    227     def _start_structure_cosmetic_state_update(self, solar_system_id):
    228         self._structure_cosmetic_states_controller.start_update(solar_system_id)
    229 
    230     def IsShip(self, typeID):
    231         return IsShip(evetypes.GetCategoryID(typeID))