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

component_listing.py (6297B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\ships\skins\static_data\component_listing.py
      2 import uuid
      3 import datetime
      4 import time
      5 from cosmetics.client.ships.skins.live_data.component_license import ComponentLicense
      6 from cosmetics.common.ships.skins.live_data.component_license_type import ComponentLicenseType
      7 from cosmetics.common.ships.skins.static_data.component import ComponentsDataLoader
      8 from cosmetics.common.ships.skins.util import Currency, COMPONENT_LIMITED_OFFER_THRESHOLD_DAYS
      9 from eveProto import get_single_value_from_split_precision_message, split_precision
     10 from eveProto.generated.eve_public.isk.isk_pb2 import Currency as IskCurrency
     11 from eveProto.generated.eve_public.plex.plex_pb2 import Currency as PlexCurrency
     12 from eveProto.generated.eve_public.inventory.generic_item_type_pb2 import Identifier as ItemTypeIdentifier
     13 from eveProto.generated.eve_public.cosmetic.market.component.listing.listing_pb2 import Attributes as ListingAttributes
     14 from google.protobuf.timestamp_pb2 import Timestamp
     15 
     16 class ComponentListing(object):
     17 
     18     def __init__(self, identifier, valid_until, currency, price, quantity, component_item_type_id, bundle_size, discount_percent):
     19         self._id = identifier
     20         self._valid_until = valid_until
     21         self._currency = currency
     22         self._price = price
     23         self._quantity = quantity
     24         self._component_item_type_id = component_item_type_id
     25         self._bundle_size = bundle_size
     26         self._discount_percent = discount_percent
     27 
     28     @property
     29     def identifier(self):
     30         return self._id
     31 
     32     @property
     33     def valid_until(self):
     34         return self._valid_until
     35 
     36     @property
     37     def valid_until_seconds(self):
     38         return time.mktime(self.valid_until.timetuple())
     39 
     40     @property
     41     def currency(self):
     42         return self._currency
     43 
     44     @property
     45     def price(self):
     46         return self._price
     47 
     48     @property
     49     def quantity(self):
     50         return self._quantity
     51 
     52     @property
     53     def component_item_type_id(self):
     54         return self._component_item_type_id
     55 
     56     @property
     57     def component_id(self):
     58         return self.get_component_data().component_id
     59 
     60     @property
     61     def license_type(self):
     62         item_data = self.get_component_item_data()
     63         if item_data:
     64             return item_data.license_type
     65 
     66     def get_component_item_data(self):
     67         component_data = self.get_component_data()
     68         item_data = component_data.component_item_data_by_type_id.get(self._component_item_type_id)
     69         return item_data
     70 
     71     def get_component_data(self):
     72         return ComponentsDataLoader.get_component_for_component_type(self._component_item_type_id)
     73 
     74     @property
     75     def bundle_size(self):
     76         return self._bundle_size
     77 
     78     @property
     79     def discount_percent(self):
     80         return self._discount_percent
     81 
     82     @property
     83     def component_license(self):
     84         return ComponentLicense(owner_character_id=None, component_id=self.component_id, license_type=self.license_type, remaining_license_uses=self.bundle_size)
     85 
     86     @property
     87     def name(self):
     88         return self.component_license.name
     89 
     90     @property
     91     def name_with_quantity(self):
     92         if self.component_license.license_type == ComponentLicenseType.UNLIMITED:
     93             return self.name
     94         else:
     95             return u'{} x {}'.format(self.component_license.remaining_license_uses, self.name)
     96 
     97     def is_limited_offer(self):
     98         return self.valid_until < datetime.datetime.now() + datetime.timedelta(days=COMPONENT_LIMITED_OFFER_THRESHOLD_DAYS)
     99 
    100     def has_discount(self):
    101         return self._discount_percent > 0
    102 
    103     def __eq__(self, other):
    104         if other is None:
    105             return False
    106         return self.identifier == other.identifier and self.valid_until == other.valid_until and self.currency == other.currency and self.price == other.price and self.quantity == other.quantity and self.component_item_type_id == other.component_item_type_id and self.bundle_size == other.bundle_size and self.discount_percent == other.discount_percent
    107 
    108     def __ne__(self, other):
    109         return not self.__eq__(other)
    110 
    111     def __str__(self):
    112         result = 'id: {id}\nvalid_until: {valid_until}\nprice: {price} {currency} (discount {discount}%\noffer: {bundle_size} x {component_type_id}\nquantity: {quantity}'.format(id=self.identifier, valid_until=self.valid_until, price=self.price, quantity=self.quantity, currency=self.currency, discount=self.discount_percent, bundle_size=self.bundle_size, component_type_id=self.component_item_type_id)
    113         return result
    114 
    115     @staticmethod
    116     def build_from_proto(payload, identifier):
    117         if payload.HasField('isk'):
    118             currency = Currency.ISK
    119             price = get_single_value_from_split_precision_message(payload.isk)
    120         elif payload.HasField('plex'):
    121             currency = Currency.PLEX
    122             price = payload.plex.total_in_cents / 100
    123         else:
    124             raise Exception('unknown currency type for skin component listing %s' % identifier)
    125         listing = ComponentListing(identifier=identifier, valid_until=datetime.datetime.fromtimestamp(payload.sale_end.seconds), currency=currency, price=price, quantity=-1, component_item_type_id=payload.component_item.sequential, bundle_size=payload.bundle_size, discount_percent=payload.discount_percent)
    126         return listing
    127 
    128     @staticmethod
    129     def build_proto_from_component_listing(component_listing):
    130         sale_end = Timestamp()
    131         sale_end.FromDatetime(component_listing.valid_until)
    132         payload = ListingAttributes(sale_end=sale_end, component_item=ItemTypeIdentifier(sequential=component_listing.component_item_type_id), bundle_size=component_listing.bundle_size, discount_percent=component_listing.discount_percent)
    133         if component_listing.currency == Currency.PLEX:
    134             payload.plex.CopyFrom(PlexCurrency(total_in_cents=component_listing.price * 100))
    135         elif component_listing.currency == Currency.ISK:
    136             units, nanos = split_precision(component_listing.price)
    137             payload.isk.CopyFrom(IskCurrency(units=units, nanos=nanos))
    138         else:
    139             raise Exception('unknown currency type for skin component listing %s' % component_listing.identifier)
    140         return payload