skill_accelerators.py (3652B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\characterskills\skill_accelerators.py 2 from .attribute import ATTRIBUTEBONUS_BY_ATTRIBUTEID 3 import gametime 4 5 class BoosterInfo(object): 6 7 def __init__(self, expiry_time, booster_bonus, booster_type_id): 8 self.expiry_time = expiry_time 9 self.booster_bonus = booster_bonus 10 self.booster_type_id = booster_type_id 11 12 def get_attribute_bonus(self, attribute_id): 13 return self.booster_bonus.get(attribute_id, 0) 14 15 def is_active_at_time(self, start_time): 16 return self.expiry_time and self.expiry_time > start_time 17 18 def __repr__(self): 19 return 'BoosterInfo(%s)' % ', '.join(('%s=%s' % (k, v) for k, v in self.__dict__.iteritems())) 20 21 def get_inverted_bonuses(self): 22 return {attribute_id:-bonus_value for attribute_id, bonus_value in self.booster_bonus.iteritems()} 23 24 25 class SkillAcceleratorBoosters(object): 26 27 def __init__(self, get_type_attribute_func): 28 self._boosters = [] 29 self._get_current_time_func = None 30 self._get_type_attribute_func = get_type_attribute_func 31 self.reset_current_time_function() 32 33 def set_current_time_function(self, function): 34 self._get_current_time_func = function 35 36 def reset_current_time_function(self): 37 self._get_current_time_func = gametime.GetWallclockTime 38 39 def get_current_time(self): 40 return self._get_current_time_func() 41 42 def get_type_attribute(self, type_id, attribute_id): 43 return self._get_type_attribute_func(type_id, attribute_id) 44 45 def add_booster(self, expiry_time, booster_type_id): 46 booster_bonus = {} 47 for attribute_id, bonus_attribute_id in ATTRIBUTEBONUS_BY_ATTRIBUTEID.iteritems(): 48 booster_bonus[attribute_id] = self.get_type_attribute(booster_type_id, bonus_attribute_id) 49 50 self._boosters.append(BoosterInfo(expiry_time, booster_bonus, booster_type_id)) 51 52 def get_attribute_bonus(self, attribute_id): 53 attribute_bonus = 0 54 for booster in self._boosters: 55 attribute_bonus += booster.get_attribute_bonus(attribute_id) 56 57 return attribute_bonus 58 59 def get_attribute_bonus_expired_at_time_offset(self, attribute_id, time_offset = 0): 60 attribute_bonus = 0 61 for booster in self._boosters: 62 if booster.expiry_time and self.is_booster_expired_at_time_offset(time_offset, booster.expiry_time): 63 attribute_bonus += booster.get_attribute_bonus(attribute_id) 64 65 return attribute_bonus 66 67 def is_booster_expired_at_time_offset(self, time_offset, booster_expiry_time): 68 return booster_expiry_time <= self.get_current_time() + time_offset 69 70 def get_expiry_times_after_time(self, start_time): 71 active_booster_expiry_times = [] 72 for booster in self._boosters: 73 if booster.is_active_at_time(start_time): 74 active_booster_expiry_times.append(booster.expiry_time) 75 76 active_booster_expiry_times.sort() 77 return active_booster_expiry_times 78 79 def is_any_booster_active_at_time(self, start_time): 80 for booster in self._boosters: 81 if booster.is_active_at_time(start_time): 82 return True 83 84 return False 85 86 def apply_expired_attributes_at_time_offset(self, attribute_dict, time_offset): 87 for attribute_id in attribute_dict: 88 attribute_dict[attribute_id] -= self.get_attribute_bonus_expired_at_time_offset(attribute_id, time_offset) 89 90 def get_boosters(self): 91 return self._boosters[:] 92 93 def _set_boosters(self, boosters): 94 self._boosters = boosters