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

component_license.py (5349B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\common\ships\skins\live_data\component_license.py
      2 from cosmetics.common.ships.skins.live_data.component_license_type import ComponentLicenseType
      3 from cosmetics.common.ships.skins.static_data.component import ComponentsDataLoader
      4 from cosmetics.common.ships.skins.static_data.component_category import ComponentCategory
      5 
      6 class BaseComponentLicense(object):
      7     LICENSE_KIND_PROTO = None
      8     COMPONENT_IDENTIFIER_PROTO = None
      9     COATING_IDENTIFIER_PROTO = None
     10     PATTERN_IDENTIFIER_PROTO = None
     11 
     12     def __init__(self, owner_character_id, component_id, license_type, remaining_license_uses = None):
     13         self._owner_character_id = owner_character_id
     14         self._component_id = component_id
     15         self._license_type = license_type
     16         self._remaining_license_uses = remaining_license_uses
     17 
     18     @property
     19     def owner_character_id(self):
     20         return self._owner_character_id
     21 
     22     @property
     23     def component_id(self):
     24         return self._component_id
     25 
     26     @property
     27     def license_type(self):
     28         return self._license_type
     29 
     30     @property
     31     def name(self):
     32         return self.get_component_data().name
     33 
     34     @property
     35     def remaining_license_uses(self):
     36         if self.license_type == ComponentLicenseType.LIMITED:
     37             return self._remaining_license_uses
     38 
     39     def set_remaining_license_uses(self, remaining_license_uses):
     40         self._remaining_license_uses = remaining_license_uses
     41 
     42     def has_enough_remaining_uses(self, num_runs):
     43         if self.license_type == ComponentLicenseType.UNLIMITED:
     44             return True
     45         return self.remaining_license_uses >= num_runs
     46 
     47     def get_required_sequence_binders(self):
     48         if self.license_type == ComponentLicenseType.LIMITED:
     49             return
     50         component_data = self.get_component_data()
     51         if component_data is not None:
     52             return (component_data.sequence_binder_type_id, component_data.sequence_binder_required_amount)
     53 
     54     def get_component_data(self):
     55         return ComponentsDataLoader.get_component_data(self.component_id)
     56 
     57     @classmethod
     58     def build_from_proto(cls, character_id, payload):
     59         component_id = cls.get_component_id_from_proto(payload.component)
     60         license_type = ComponentLicenseType.UNLIMITED if payload.HasField('infinite') else ComponentLicenseType.LIMITED
     61         remaining_license_uses = int(payload.finite) if payload.HasField('finite') else None
     62         return cls(character_id, component_id, license_type, remaining_license_uses)
     63 
     64     @classmethod
     65     def build_from_finite_proto(cls, character_id, component_id, payload):
     66         license_type = ComponentLicenseType.LIMITED
     67         remaining_license_uses = payload.capacity
     68         return cls(character_id, component_id, license_type, remaining_license_uses)
     69 
     70     @classmethod
     71     def build_from_infinite_proto(cls, character_id, component_id, _payload):
     72         license_type = ComponentLicenseType.UNLIMITED
     73         return cls(character_id, component_id, license_type, None)
     74 
     75     @classmethod
     76     def build_proto_from_component_license(cls, component_license):
     77         component_data = component_license.get_component_data()
     78         license_kind = cls.LICENSE_KIND_PROTO()
     79         license_kind.component.CopyFrom(cls.build_component_id_proto_from_component_id(component_license.component_id, component_data.category))
     80         if component_license.license_type == ComponentLicenseType.LIMITED:
     81             license_kind.finite = component_license.remaining_license_uses
     82         else:
     83             license_kind.infinite = True
     84         return license_kind
     85 
     86     @classmethod
     87     def build_component_id_proto_from_component_id(cls, component_id, component_type):
     88         component_proto = cls.COMPONENT_IDENTIFIER_PROTO()
     89         if component_type in [ComponentCategory.METALLIC, ComponentCategory.MATERIAL]:
     90             component_proto.coating.CopyFrom(cls.COATING_IDENTIFIER_PROTO(sequential=component_id))
     91         elif component_type in [ComponentCategory.PATTERN]:
     92             component_proto.pattern.CopyFrom(cls.PATTERN_IDENTIFIER_PROTO(sequential=component_id))
     93         else:
     94             raise NotImplementedError('Unknown component type for component id: {component_id}'.format(component_id=component_id))
     95         return component_proto
     96 
     97     @classmethod
     98     def get_component_id_from_proto(cls, payload):
     99         if payload.HasField('coating'):
    100             return payload.coating.sequential
    101         if payload.HasField('pattern'):
    102             return payload.pattern.sequential
    103         raise NotImplementedError('Unknown component type in component proto: {payload}'.format(payload=payload))
    104 
    105     def __eq__(self, other):
    106         if other is None:
    107             return False
    108         return self.owner_character_id == other.owner_character_id and self.component_id == other.component_id and self.license_type == other.license_type and self.remaining_license_uses == other.remaining_license_uses
    109 
    110     def __ne__(self, other):
    111         return not self.__eq__(other)
    112 
    113     def __str__(self):
    114         result = '%s Component License for component %s' % (self.license_type, self.component_id)
    115         if self.license_type == ComponentLicenseType.LIMITED:
    116             result += ' (remaining uses: %s)' % self.remaining_license_uses
    117         return result