def execute_buff(self, battle, user_id, target_id): (stat, stages) = (self.extra['stat'], self.extra['stages']) user = battle.get_pokemon(user_id) if self.extra.get('target') == 'self': target_id = user_id target = user else: target = battle.get_pokemon(target_id) if not self.hits(battle, user, target): return self.execute_miss(battle, user_id, target_id) callback = self.get_secondary_effect(battle, target_id, target) return (Callbacks.do_buff(battle, target_id, stat, stages, callback=callback), True)
def post_move_hook(self, battle, user_id, outcome, callback=None): if 'post_move_hook' in self.extra: hook = self.extra.get('post_move_hook') if hook['type'] == 'buff': if uniform(0, 1) < hook['rate']: (stat, stages) = (hook['stat'], hook['stages']) return Callbacks.do_buff(battle, user_id, stat, stages, callback=callback) elif hook['type'] == 'recoil': assert('damage' in outcome), 'Unexpected outcome %s for %s' % (outcome, self.name) damage = max(int(hook['ratio']*outcome['damage']), 1) message = "%s's hit by the recoil!" % (battle.get_name(user_id),) return Callbacks.do_damage(battle, user_id, damage, message, callback=callback) else: assert(False), 'Unexpected hook: %s' % (hook,) return callback
def get_secondary_effect(self, battle, target_id, target, callback=None): total_mass = 1.0 stat_rate = self.extra.get('stat_rate') if stat_rate: if uniform(0, total_mass) < stat_rate: (stat, stages) = (self.extra['stat'], self.extra['stages']) assert(stages < 0), 'Unexpect stat buff: %s' % (self.name,) return Callbacks.do_buff(battle, target_id, stat, stages, callback=callback) total_mass -= stat_rate for status in Status.OPTIONS: rate = self.extra.get(status + '_rate') if rate: if uniform(0, total_mass) < rate: return Callbacks.set_status(battle, target_id, status, self, callback=callback) total_mass -= rate return callback