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

priceCatalogue.py (2411B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\common\structures\priceCatalogue.py
      2 from cosmetics.common.structures.const import PAINT_ELIGIBLE_STRUCTURE_TYPE_IDS
      3 from cosmetics.common.structures.exceptions import StructureTypeNotEligibleError
      4 
      5 class PriceCatalogue(object):
      6 
      7     def __init__(self):
      8         self._price_table = {}
      9         for structure_type_id in PAINT_ELIGIBLE_STRUCTURE_TYPE_IDS:
     10             self._price_table[structure_type_id] = {}
     11 
     12     def define_price(self, structure_type_id, duration, price):
     13         if structure_type_id not in self._price_table:
     14             raise StructureTypeNotEligibleError
     15         self._price_table[structure_type_id][duration] = price
     16 
     17     def get_available_durations_sorted(self):
     18         durations = set()
     19         for structure_type_id, structure_prices in self._price_table.iteritems():
     20             for stored_duration, price in structure_prices.iteritems():
     21                 durations.add(stored_duration)
     22 
     23         return sorted(list(durations))
     24 
     25     def get_prices_for_structure_type_id(self, structure_type_id):
     26         if structure_type_id not in self._price_table:
     27             raise StructureTypeNotEligibleError
     28         return self._price_table[structure_type_id]
     29 
     30     def get_prices_for_duration(self, duration):
     31         result = {}
     32         for structure_type_id, structure_prices in self._price_table.iteritems():
     33             for stored_duration, price in structure_prices.iteritems():
     34                 if stored_duration == duration:
     35                     result[structure_type_id] = price
     36 
     37         return result
     38 
     39     def get_price_for_structure_type_id_and_duration(self, structure_type_id, duration):
     40         if structure_type_id not in self._price_table:
     41             raise StructureTypeNotEligibleError
     42         for stored_duration, price in self._price_table[structure_type_id].iteritems():
     43             if stored_duration == duration:
     44                 return price
     45 
     46         raise KeyError
     47 
     48     def get_all_prices(self):
     49         result = set()
     50         for structure_type_id, structure_prices in self._price_table.iteritems():
     51             for stored_duration, price in structure_prices.iteritems():
     52                 result.add((structure_type_id, stored_duration, price))
     53 
     54         return result
     55 
     56     def __eq__(self, other):
     57         return len(self.get_all_prices().difference(other.get_all_prices())) == 0