-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
72 lines (70 loc) · 2.73 KB
/
Game.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
# coding: utf-8
from AbilityBag import AbilityBag
from HealthTableau import HealthTableau
from HealthPoint import HealthPoint
from typing import Optional
from obsub import event
from random import choice
from Logger import messages, debug
class Game(object):
def __init__(self) -> None:
self.hta = self.make_generic_health_tableau()
self.htb = self.make_generic_health_tableau()
self.turn_a = True
def make_generic_health_tableau(self) -> HealthTableau:
ht = HealthTableau()
ht.insert_point('Heart')
ht.insert_point('Splanch')
ht.insert_point('Phylactery')
ht.insert_point('Arm')
ht.insert_point('SpareMuscles')
ht.insert_point('Spear')
return ht
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)
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")