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

track_reward.py (9310B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\campaigns\client\v2\data_model\track_reward.py
      2 from campaigns.client.v2.data_model.ui_definition import UIDefinition
      3 from eveProto import get_single_value_from_split_precision_message
      4 ISSUER_TYPE_CHARACTER = 'character'
      5 ISSUER_TYPE_CORPORATION = 'corporation'
      6 ISSUER_TYPE_ALLIANCE = 'alliance'
      7 ISSUER_TYPE_FACTION = 'faction'
      8 _ISK_ISSUER_TYPES = (ISSUER_TYPE_CHARACTER, ISSUER_TYPE_CORPORATION)
      9 _STANDING_ISSUER_TYPES = (ISSUER_TYPE_CHARACTER,
     10  ISSUER_TYPE_CORPORATION,
     11  ISSUER_TYPE_ALLIANCE,
     12  ISSUER_TYPE_FACTION)
     13 
     14 def _issuer_from_proto(issuer, oneof_name, allowed_types):
     15     issuer_type = issuer.WhichOneof(oneof_name)
     16     if issuer_type not in allowed_types:
     17         raise NotImplementedError('Unknown reward issuer type: %s' % issuer_type)
     18     return (issuer_type, getattr(issuer, issuer_type).sequential)
     19 
     20 
     21 def _unredeemed_intervals(track_rewards, oneof_name):
     22     unredeemed = track_rewards.WhichOneof(oneof_name)
     23     if unredeemed == '%s_intervals_unredeemed' % oneof_name:
     24         return getattr(track_rewards, unredeemed)
     25     if unredeemed == 'no_%s_unredeemed' % oneof_name:
     26         return 0
     27     raise NotImplementedError('Unknown unredeemed %s rewards: %s' % (oneof_name, unredeemed))
     28 
     29 
     30 class ParticipantContributionTrack(object):
     31 
     32     def __init__(self, ui_definition, max_total_progress, rewards):
     33         self._ui_definition = ui_definition
     34         self._max_total_progress = max_total_progress
     35         self._rewards = rewards
     36 
     37     @property
     38     def ui_definition(self):
     39         return self._ui_definition
     40 
     41     @property
     42     def max_total_progress(self):
     43         return self._max_total_progress
     44 
     45     @property
     46     def rewards(self):
     47         return self._rewards
     48 
     49     @classmethod
     50     def from_proto(cls, participant_contribution_track):
     51         contribution_limit = participant_contribution_track.WhichOneof('contribution_limit')
     52         if contribution_limit == 'max_total_progress':
     53             max_total_progress = participant_contribution_track.max_total_progress
     54         elif contribution_limit == 'no_contribution_limit':
     55             max_total_progress = None
     56         else:
     57             raise NotImplementedError('Unknown participant contribution limit: %s' % contribution_limit)
     58         return ParticipantContributionTrack(ui_definition=UIDefinition.from_proto(participant_contribution_track.ui), max_total_progress=max_total_progress, rewards=[ TrackReward.from_proto(reward) for reward in participant_contribution_track.rewards ])
     59 
     60     def __eq__(self, other):
     61         if not isinstance(other, ParticipantContributionTrack):
     62             raise NotImplementedError
     63         return self.ui_definition == other.ui_definition and self.max_total_progress == other.max_total_progress and self.rewards == other.rewards
     64 
     65     def __ne__(self, other):
     66         return not self.__eq__(other)
     67 
     68     def __repr__(self):
     69         return '<%s %r>' % (self.__class__.__name__, self.__dict__)
     70 
     71 
     72 class TrackReward(object):
     73 
     74     def __init__(self, key, ui_definition, progress_interval, reward):
     75         self._key = key
     76         self._ui_definition = ui_definition
     77         self._progress_interval = progress_interval
     78         self._reward = reward
     79 
     80     @property
     81     def key(self):
     82         return self._key
     83 
     84     @property
     85     def ui_definition(self):
     86         return self._ui_definition
     87 
     88     @property
     89     def progress_interval(self):
     90         return self._progress_interval
     91 
     92     @property
     93     def reward(self):
     94         return self._reward
     95 
     96     @classmethod
     97     def from_proto(cls, reward):
     98         reward_type = reward.WhichOneof('reward_type')
     99         if reward_type == 'isk_reward':
    100             reward_details = IskTrackReward.from_proto(reward.isk_reward)
    101         elif reward_type == 'lp_reward':
    102             reward_details = LpTrackReward.from_proto(reward.lp_reward)
    103         elif reward_type == 'standing_reward':
    104             reward_details = StandingTrackReward.from_proto(reward.standing_reward)
    105         else:
    106             raise NotImplementedError('Unknown track reward type: %s' % reward_type)
    107         return TrackReward(reward.key, UIDefinition.from_proto(reward.ui), reward.progress_interval, reward_details)
    108 
    109     def __eq__(self, other):
    110         if not isinstance(other, TrackReward):
    111             raise NotImplementedError
    112         return self.key == other.key and self.ui_definition == other.ui_definition and self.progress_interval == other.progress_interval and self.reward == other.reward
    113 
    114     def __ne__(self, other):
    115         return not self.__eq__(other)
    116 
    117     def __repr__(self):
    118         return '<%s %r>' % (self.__class__.__name__, self.__dict__)
    119 
    120 
    121 class IskTrackReward(object):
    122 
    123     def __init__(self, amount_per_interval, issuer_type, issuer_id):
    124         self._amount_per_interval = amount_per_interval
    125         self._issuer_type = issuer_type
    126         self._issuer_id = issuer_id
    127 
    128     @property
    129     def amount_per_interval(self):
    130         return self._amount_per_interval
    131 
    132     @property
    133     def issuer_type(self):
    134         return self._issuer_type
    135 
    136     @property
    137     def issuer_id(self):
    138         return self._issuer_id
    139 
    140     @classmethod
    141     def from_proto(cls, isk_reward):
    142         issuer_type, issuer_id = _issuer_from_proto(isk_reward.issuer, 'owner_type', _ISK_ISSUER_TYPES)
    143         return IskTrackReward(amount_per_interval=get_single_value_from_split_precision_message(isk_reward.amount_per_interval), issuer_type=issuer_type, issuer_id=issuer_id)
    144 
    145     def __eq__(self, other):
    146         if not isinstance(other, IskTrackReward):
    147             raise NotImplementedError
    148         return self.amount_per_interval == other.amount_per_interval and self.issuer_type == other.issuer_type and self.issuer_id == other.issuer_id
    149 
    150     def __ne__(self, other):
    151         return not self.__eq__(other)
    152 
    153     def __repr__(self):
    154         return '<%s %r>' % (self.__class__.__name__, self.__dict__)
    155 
    156 
    157 class LpTrackReward(object):
    158 
    159     def __init__(self, amount_per_interval, issuing_corporation_id):
    160         self._amount_per_interval = amount_per_interval
    161         self._issuing_corporation_id = issuing_corporation_id
    162 
    163     @property
    164     def amount_per_interval(self):
    165         return self._amount_per_interval
    166 
    167     @property
    168     def issuing_corporation_id(self):
    169         return self._issuing_corporation_id
    170 
    171     @classmethod
    172     def from_proto(cls, lp_reward):
    173         return LpTrackReward(amount_per_interval=lp_reward.amount_per_interval.amount, issuing_corporation_id=lp_reward.amount_per_interval.associated_corporation.sequential)
    174 
    175     def __eq__(self, other):
    176         if not isinstance(other, LpTrackReward):
    177             raise NotImplementedError
    178         return self.amount_per_interval == other.amount_per_interval and self.issuing_corporation_id == other.issuing_corporation_id
    179 
    180     def __ne__(self, other):
    181         return not self.__eq__(other)
    182 
    183     def __repr__(self):
    184         return '<%s %r>' % (self.__class__.__name__, self.__dict__)
    185 
    186 
    187 class StandingTrackReward(object):
    188 
    189     def __init__(self, gain_percent_per_interval, issuer_type, issuer_id):
    190         self._gain_percent_per_interval = gain_percent_per_interval
    191         self._issuer_type = issuer_type
    192         self._issuer_id = issuer_id
    193 
    194     @property
    195     def gain_percent_per_interval(self):
    196         return self._gain_percent_per_interval
    197 
    198     @property
    199     def issuer_type(self):
    200         return self._issuer_type
    201 
    202     @property
    203     def issuer_id(self):
    204         return self._issuer_id
    205 
    206     @classmethod
    207     def from_proto(cls, standing_reward):
    208         issuer_type, issuer_id = _issuer_from_proto(standing_reward.issuer, 'source', _STANDING_ISSUER_TYPES)
    209         return StandingTrackReward(gain_percent_per_interval=get_single_value_from_split_precision_message(standing_reward.gain_percent_per_interval), issuer_type=issuer_type, issuer_id=issuer_id)
    210 
    211     def __eq__(self, other):
    212         if not isinstance(other, StandingTrackReward):
    213             raise NotImplementedError
    214         return self.gain_percent_per_interval == other.gain_percent_per_interval and self.issuer_type == other.issuer_type and self.issuer_id == other.issuer_id
    215 
    216     def __ne__(self, other):
    217         return not self.__eq__(other)
    218 
    219     def __repr__(self):
    220         return '<%s %r>' % (self.__class__.__name__, self.__dict__)
    221 
    222 
    223 class TrackUnredeemedRewards(object):
    224 
    225     def __init__(self, isk_intervals, lp_intervals):
    226         self._isk_intervals = isk_intervals
    227         self._lp_intervals = lp_intervals
    228 
    229     @property
    230     def isk_intervals(self):
    231         return self._isk_intervals
    232 
    233     @property
    234     def lp_intervals(self):
    235         return self._lp_intervals
    236 
    237     def combined_with(self, other):
    238         return TrackUnredeemedRewards(self.isk_intervals + other.isk_intervals, self.lp_intervals + other.lp_intervals)
    239 
    240     @classmethod
    241     def from_proto(cls, track_rewards):
    242         return TrackUnredeemedRewards(_unredeemed_intervals(track_rewards, 'isk'), _unredeemed_intervals(track_rewards, 'lp'))
    243 
    244     def __eq__(self, other):
    245         if not isinstance(other, TrackUnredeemedRewards):
    246             raise NotImplementedError
    247         return self.isk_intervals == other.isk_intervals and self.lp_intervals == other.lp_intervals
    248 
    249     def __ne__(self, other):
    250         return not self.__eq__(other)
    251 
    252     def __repr__(self):
    253         return '<%s %r>' % (self.__class__.__name__, self.__dict__)