participation.py (3534B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\campaigns\client\v2\data_model\participation.py 2 3 4 class ParticipationConfiguration(object): 5 6 def __init__(self, commitment_required, eligibility): 7 self._commitment_required = commitment_required 8 self._eligibility = eligibility 9 10 @property 11 def commitment_required(self): 12 return self._commitment_required 13 14 @property 15 def eligibility(self): 16 return self._eligibility 17 18 @classmethod 19 def from_proto(cls, configuration): 20 eligibility_class = configuration.WhichOneof('eligibility') 21 if eligibility_class == 'eligibility_all': 22 eligibility = AllEligibility() 23 elif eligibility_class == 'eligibility_filter': 24 eligibility = FilteredEligibility.from_proto(configuration.eligibility_filter) 25 else: 26 raise NotImplementedError('Unknown participation eligibility: %s' % eligibility_class) 27 return ParticipationConfiguration(configuration.commitment_required, eligibility) 28 29 def __eq__(self, other): 30 if not isinstance(other, ParticipationConfiguration): 31 raise NotImplementedError 32 return self.commitment_required == other.commitment_required and self.eligibility == other.eligibility 33 34 def __ne__(self, other): 35 return not self.__eq__(other) 36 37 def __repr__(self): 38 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 39 40 41 class AllEligibility(object): 42 43 def __eq__(self, other): 44 if not isinstance(other, AllEligibility): 45 raise NotImplementedError 46 return True 47 48 def __ne__(self, other): 49 return not self.__eq__(other) 50 51 def __repr__(self): 52 return '<%s>' % self.__class__.__name__ 53 54 55 class FilteredEligibility(object): 56 57 def __init__(self, selectors): 58 self._selectors = selectors 59 60 @property 61 def selectors(self): 62 return self._selectors 63 64 @classmethod 65 def from_proto(cls, eligibility_filter): 66 selectors = [] 67 for selector in eligibility_filter.selectors: 68 selector_class = selector.WhichOneof('selector') 69 if selector_class == 'faction_enlistment': 70 selectors.append(FactionEnlistmentSelector.from_proto(selector.faction_enlistment)) 71 else: 72 raise NotImplementedError('Unknown participation eligibility selector: %s' % selector_class) 73 74 return FilteredEligibility(selectors) 75 76 def __eq__(self, other): 77 if not isinstance(other, FilteredEligibility): 78 raise NotImplementedError 79 return self.selectors == other.selectors 80 81 def __ne__(self, other): 82 return not self.__eq__(other) 83 84 def __repr__(self): 85 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 86 87 88 class FactionEnlistmentSelector(object): 89 90 def __init__(self, faction_ids): 91 self._faction_ids = faction_ids 92 93 @property 94 def faction_ids(self): 95 return self._faction_ids 96 97 @classmethod 98 def from_proto(cls, faction_enlistment): 99 return FactionEnlistmentSelector([ faction.sequential for faction in faction_enlistment.factions ]) 100 101 def __eq__(self, other): 102 if not isinstance(other, FactionEnlistmentSelector): 103 raise NotImplementedError 104 return self.faction_ids == other.faction_ids 105 106 def __ne__(self, other): 107 return not self.__eq__(other) 108 109 def __repr__(self): 110 return '<%s %r>' % (self.__class__.__name__, self.__dict__)