def _register_meta_types(container, candidates): for candidate in discovering.discover_classes(candidates, objects.MetaType): if candidate.TYPE in container: raise exceptions.DuplicateTypeError(type=candidate.TYPE) if candidate.TYPE is None: continue container[candidate.TYPE] = candidate
def _register_postponed_tasks(container, objects): for obj in discovering.discover_classes(objects, PostponedLogic): if obj.TYPE in container: raise PostponedTaskException(u'interanl logic "%s" for postponed task has being registered already' % obj.TYPE) if obj.TYPE is None: continue # skip abstract classes # raise PostponedTaskException(u'interanl logic "%r" for postponed task does not define TYPE' % obj) container[obj.TYPE] = obj
def _register_postponed_tasks(container, objects): for obj in discovering.discover_classes(objects, PostponedLogic): if obj.TYPE in container: raise PostponedTaskException( 'interanl logic "%s" for postponed task has being registered already' % obj.TYPE) if obj.TYPE is None: continue # skip abstract classes # raise PostponedTaskException(u'interanl logic "%r" for postponed task does not define TYPE' % obj) container[obj.TYPE] = obj
self.hero_2.pvp.set_advantage(0) self.percents = 1.0 - min(self.hero_1.health_percents, self.hero_2.health_percents) # update resources, etc self.update_hero_pvp_info(self.hero_1) self.update_hero_pvp_info(self.hero_2) self.hero_1.pvp.store_turn_data() self.hero_2.pvp.store_turn_data() # check if anyone has killed self._check_hero_health(self.hero_1, self.hero_2) self._check_hero_health(self.hero_2, self.hero_1) def _process(self): # check processed state before battle turn, to give delay to players to see battle result if self.state == self.STATE.BATTLE_ENDING: self.process_battle_ending() if self.state == self.STATE.BATTLE_RUNNING: self.process_battle_running() ACTION_TYPES = { action_class.TYPE:action_class for action_class in discovering.discover_classes(globals().values(), MetaAction) }
class UpgradeArtifact(BaseEffect): TYPE = relations.CARD_TYPE.INCREMENT_ARTIFACT_RARITY DESCRIPTION = u'Улучшает на один уровень качество случайного экипированного не эпического артефакта.' def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 artifacts = [artifact for artifact in task.hero.equipment.values() if not artifact.rarity.is_EPIC] if not artifacts: return task.logic_result(next_step=UseCardTask.STEP.ERROR, message=u'У героя нет экипированных не эпических артефактов.') artifact = random.choice(artifacts) task.hero.increment_equipment_rarity(artifact) return task.logic_result(message=u'Качество артефакта %(artifact)s улучшено.' % {'artifact': artifact.html_label()}) EFFECTS = {card_class.TYPE: card_class() for card_class in discovering.discover_classes(globals().values(), BaseEffect) if card_class.TYPE is not None} PREFERENCE_RESET_CARDS = {card_class.PREFERENCE: card_class() for card_class in discovering.discover_classes(globals().values(), PreferencesCooldownsResetBase)} HABIT_POINTS_CARDS = {card_class.TYPE: card_class() for card_class in discovering.discover_classes(globals().values(), ChangeHabitBase)}
return task.logic_result( next_step=UseCardTask.STEP.ERROR, message=u'У героя нет экипированных не эпических артефактов.') artifact = random.choice(artifacts) task.hero.increment_equipment_rarity(artifact) return task.logic_result( message=u'Качество артефакта %(artifact)s улучшено.' % {'artifact': artifact.html_label()}) EFFECTS = { card_class.TYPE: card_class() for card_class in discovering.discover_classes( globals().values(), BaseEffect) if card_class.TYPE is not None } PREFERENCE_RESET_CARDS = { card_class.PREFERENCE: card_class() for card_class in discovering.discover_classes( globals().values(), PreferencesCooldownsResetBase) } HABIT_POINTS_CARDS = { card_class.TYPE: card_class() for card_class in discovering.discover_classes(globals().values(), ChangeHabitBase) }
self.percents = 1.0 - min(self.hero_1.health_percents, self.hero_2.health_percents) # update resources, etc self.update_hero_pvp_info(self.hero_1_pvp) self.update_hero_pvp_info(self.hero_2_pvp) self.hero_1_pvp.store_turn_data() self.hero_2_pvp.store_turn_data() # check if anyone has killed self._check_hero_health(self.hero_1, self.hero_2) self._check_hero_health(self.hero_2, self.hero_1) def _process(self): # check processed state before battle turn, to give delay to players to see battle result if self.state == self.STATE.BATTLE_ENDING: self.process_battle_ending() if self.state == self.STATE.BATTLE_RUNNING: self.process_battle_running() ACTION_TYPES = { action_class.TYPE: action_class for action_class in discovering.discover_classes(globals().values(), MetaAction) }
MULTIPLIER = 2 @classmethod def modify_attribute(cls, type_, value): return value * cls.MULTIPLIER if type_.is_HABITS_INCREASE else value class Unbreakable(BaseEffect): TYPE = relations.ARTIFACT_EFFECT.UNBREAKABLE DESCRIPTION = u'Экипировка героя медленнее ломается' MULTIPLIER = 0.25 @classmethod def modify_attribute(cls, type_, value): return value + cls.MULTIPLIER if type_.is_SAFE_INTEGRITY else value class NoEffect(BaseEffect): TYPE = relations.ARTIFACT_EFFECT.NO_EFFECT DESCRIPTION = u'нет эффекта' class ChildGift(BaseEffect): TYPE = relations.ARTIFACT_EFFECT.CHILD_GIFT DESCRIPTION = u'Это потерянный подарок ребёнка. Помогите герою, когда артефакт лежит в рюкзаке, и подарок вернётся к ребёнку.' REMOVE_ON_HELP = True EFFECTS = {effect.TYPE: effect for effect in discovering.discover_classes(globals().values(), BaseEffect) if effect.TYPE is not None}
# expected value = effect * probability => effect = expected / probability # and mutliply by "turns number" (~ total energy) def modify_effect(self, expected): return self.hero_pvp.energy * expected / self.probability def apply(self): effectiveness_delta = int(round(c.PVP_EFFECTIVENESS_STEP * self.modify_effect(1.0)*(1 + self.hero.might_pvp_effectiveness_bonus))) self.hero_pvp.set_effectiveness(self.hero_pvp.effectiveness + effectiveness_delta) self.hero_pvp.set_energy(0) self.hero.add_message('pvp_use_ability_%s' % self.TYPE, duelist_1=self.hero, duelist_2=self.enemy, effectiveness=effectiveness_delta) self.enemy.add_message('pvp_use_ability_%s' % self.TYPE, turn_delta=1, duelist_1=self.hero, duelist_2=self.enemy, effectiveness=effectiveness_delta) class Flame(BasePvPAbility): TYPE = 'flame' NAME = 'Пламя' DESCRIPTION = 'Нарушить концентрацию противника и уменьшить прирост его энергии. Чем дольше копилась энергия, тем вероятнее успех применения способности. Сбросить прирост энергии меньше 1 нельзя.' @staticmethod def get_probability(energy, energy_speed): return min(1.0, energy * 10 / 100.0 / energy_speed) def apply(self): if self.enemy_pvp.energy_speed > 1: self.enemy_pvp.set_energy_speed(self.enemy_pvp.energy_speed - 1) self.hero_pvp.set_energy(0) self.hero.add_message('pvp_use_ability_%s' % self.TYPE, duelist_1=self.hero, duelist_2=self.enemy) self.enemy.add_message('pvp_use_ability_%s' % self.TYPE, turn_delta=1, duelist_1=self.hero, duelist_2=self.enemy) ABILITIES = {ability.TYPE:ability for ability in discovering.discover_classes(globals().values(), BasePvPAbility)}