-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hooks.py
115 lines (100 loc) · 4.38 KB
/
Hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# coding: utf-8
from typing import Optional, List
from hook_priority import hook_priority
from Logger import messages, debug
from Events import EventArgs, EventHook
def get_hook(hook : str) -> EventHook:
return globals()[hook]
@hook_priority(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')
@hook_priority(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
@hook_priority(0)
def resist_damage(event_args : EventArgs):
debug.log('resisting damage')
event_args['damage_resisted'] = True
def _register_weapon(attack_mode : Optional[str]=None):
@hook_priority(0)
def register_weapon(event_args : EventArgs):
weapon = event_args['weapon']
event_args['attack_modes'].append((weapon,attack_mode))
return register_weapon
register_weapon = _register_weapon()
def _base_attack_abilities(abilities : List[str]):
@hook_priority(0)
def base_attack_abilities(event_args : EventArgs):
event_args['damage_tableau'].add_common_abilities(abilities)
return base_attack_abilities
base_attack_abilities_default = _base_attack_abilities(["Attack"])
def _add_attack_point(point : List[str]):
@hook_priority(0)
def base_attack_points(event_args : EventArgs):
from DamagePoint import DamagePoint
event_args['damage_tableau'].add_damage_point(DamagePoint(point, event_args['weapon']))
return base_attack_points
add_attack_point_normal = _add_attack_point(["Target Attack (Normal)"])
add_attack_point_piercing = _add_attack_point(["Target Attack (Piercing)"])
@hook_priority(0)
def add_attack_point_copy(event_args : EventArgs):
damage_tableau = event_args['damage_tableau']
try:
last_point = damage_tableau._damage_points[-1]
except IndexError:
return
damage_tableau.add_damage_point(last_point.copy())
@hook_priority(0)
def prepare_attack(event_args : EventArgs):
from DamageTableau import DamageTableau
damage_tableau = DamageTableau([],[])
event_args['damage_tableau'] = damage_tableau
weapon = event_args['weapon']
weapon.get_abilities().call('base_attack',event_args)
@hook_priority(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')