예제 #1
0
 def advance(self) -> None:
     if self.turn_a:
         attacker = self.hta
         defender = self.htb
     else:
         attacker = self.htb
         defender = self.hta
     self.turn_a = not self.turn_a
     if attacker.is_dead():
         messages.log('Too dead to attack')
     elif defender.is_dead():
         messages.log('No point attacking a corpse')
     else:
         event_args = {
             'attacker':attacker,
             'attack_modes':[]
         }
         for health_point in attacker:
             event_args['weapon'] = health_point
             health_point.get_abilities().call('list_attack_modes', event_args)
         attack_modes = event_args['attack_modes']
         if attack_modes:
             debug.log('possible attack modes: {0}'.format(attack_modes))
             weapon, attack_mode = choice(attack_modes)
             debug.log('chosen attack mode: {0}, {1}'.format(weapon, attack_mode))
             self.process_attack(defender, attacker, weapon, attack_mode)
             messages.log("Damaged. {0}.".format(
                 "Dead" if defender.is_dead() else "Not dead"))
         else:
                 messages.log("Unable to attack")
예제 #2
0
 def add_hook(self, event : str, hook : EventHook) -> None:
     check_event(event)
     debug.log('adding hook for event {0}'.format(event))
     self._hook_counter[(event,hook)] += 1
     if self._hook_counter[(event,hook)] == 1:
         debug.log('hook is new for event, adding to call list')
         self._hooks[event].add(hook)
예제 #3
0
def execute_attack(event_args: EventArgs):
    if 'targetted_health_point' not in event_args:
        event_args['targetted_health_point'] = None
    damage_point = event_args['damage_point']
    damage_point.call('target_health_point', event_args)
    targetted_health_point = event_args['targetted_health_point']
    if targetted_health_point is not None:
        debug.log('targetted health point: {0}'.format(targetted_health_point))
        if targetted_health_point.is_healthy:
            debug.log('targetted health point is healthy')
            event_args['damage_resisted'] = False
            targetted_health_point.get_abilities().call(
                'resist_damage_point', event_args)
            event_args['defender'].call('resist_damage_tableau', event_args)
            if not event_args['damage_resisted']:
                targetted_health_point.is_healthy = False
                debug.log('damage taken')
                return
        else:
            debug.log('targetted health point is already damaged')
    else:
        debug.log('failed to target health point')
예제 #4
0
def target_normal(event_args: EventArgs):
    debug.log('finding target health point')
    for health_point in reversed(event_args['defender']):
        if health_point.is_healthy:
            debug.log('found valid target: {0}'.format(health_point))
            event_args['targetted_health_point'] = health_point
            return
    debug.log('found no valid target')
예제 #5
0
 def add_abilities(self, abilities: List[Union[str, Ability]] = []) -> None:
     abilities = [x if isinstance(x, str) else x.name for x in abilities]
     debug.log('adding abilities {0} to bag'.format(abilities))
     self._ability_counter.update(abilities)
     for ability in abilities:
         debug.log('adding ability {0} to bag'.format(ability))
         ability = get_ability(ability)
         if self._ability_counter[ability.name] == 1:
             debug.log('ability is new, updating event hooks')
             for event, hooks in ability.hooks.items():
                 for hook in hooks:
                     self._hooks.add_hook(event, hook)
         else:
             debug.log('ability is not new (count={0})'.format(
                 self._ability_counter[ability.name]))
예제 #6
0
 def call(self, event : str, event_args : Dict[str, Any]):
     check_event(event)
     debug.log('event called : {0}'.format(event))
     if event in self._hooks:
         debug.log('{0} hooks handling it'.format(len(self._hooks[event])))
         for hook in self._hooks[event]:
             hook(event_args)
     else:
         debug.log('no hooks for this event')
예제 #7
0
def target_piercing(event_args: EventArgs):
    debug.log('finding target health point')
    found_healthy_point = False
    for health_point in reversed(event_args['defender']):
        if health_point.is_healthy:
            if not found_healthy_point:
                found_healthy_point = True
                target_point = health_point
                debug.log(
                    'found first healthy point: {0}'.format(target_point))
                event_args['targetted_health_point'] = target_point
                event_args['point_to_bypass'] = target_point
                event_args['bypass_successful'] = True
                target_point.get_abilities().call('resist_bypass', event_args)
                if not event_args['bypass_successful']:
                    debug.log('bypass unsuccessful')
                    return
                else:
                    debug.log('bypass successful')
            else:
                event_args['targetted_health_point'] = health_point
                return
예제 #8
0
 def process_attack(self,
                    defender : HealthTableau,
                    attacker : Optional[HealthTableau]=None,
                    weapon : Optional[HealthPoint]=None,
                    attack_mode : Optional[str]=None) -> None:
     event_args = {
         'attacker':attacker,
         'defender':defender,
         'weapon':weapon,
         'attack_mode':attack_mode
     }
     debug.log('preparing attack')
     weapon.get_abilities().call('prepare_attack', event_args)
     debug.log('augmenting attack')
     attacker.call('augment_attack', event_args)
     damage_tableau = event_args['damage_tableau']
     debug.log('executing attack')
     damage_tableau.execute_attack(event_args)
예제 #9
0
def resist_damage(event_args: EventArgs):
    debug.log('resisting damage')
    event_args['damage_resisted'] = True
예제 #10
0
def check_event(event: str) -> None:
    if ERROR_ON_UNREGISTERED_EVENT:
        assert event in _events, event
    else:
        if event not in _events: debug.log('event {0} not registered'.format(event))