/
cond.py
198 lines (155 loc) · 4.91 KB
/
cond.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"""
Governs 'conditions', status effects that modify a Dude's movement in some way.
"""
import action
import coordinates
import symbol
import log
HASTE_COLOR = (0, 255, 255)
class Condition(object):
"""
A condition.
"""
def __init__(self, time, name):
"""
Create a new Condition.
time - the number of turns until the condition will wear off.
name - a unique identifier for the condition, and the way it will be
displayed to the player.
"""
self.time = time
self.name = name
def getDisplayName(self):
"""
Get the name of this condition used to display it on the Sidebar.
If a condition does not want to be displayed on the Sidebar, this method
should return an empty string.
"""
return self.name
def passTurn(self):
"""
Indicate to the condition that a turn has passed.
"""
self.time -= 1
def isOver(self):
"""
Return True if the condition is over, False otherwise.
"""
return self.time < 0
def getAction(self, dude_):
"""
Get an action, if this condition decides to control its dude's actions.
Returns "None" if the condition allows the dude to choose its own
actions.
"""
return None
def modifyAction(self, act):
"""
Modify an action, if that action is not allowed under this condition.
Returns: the new action that will be performed in place of the old.
"""
return act
def modifyGlyph(self, glyph):
"""
Modify the glyph of a dude to be displayed.
Returns: the new glyph which should be displayed.
"""
return glyph
def apply(self, dude_):
"""
Apply any effects that occur when the condition is given to a dude.
"""
return
def cancel(self, dude_):
"""
Do any effects that occur once the condition is over. That is, return
the dude to its original state.
"""
return
class Stuck(Condition):
"""
A condition in which a dude cannot move.
"""
def __init__(self, duration):
Condition.__init__(self, 8, "stuck")
def modifyAction(self, act):
"""
If a dude is Stuck, all of their moves become Wait actions.
"""
if act.strcode == "MOVE":
return action.Wait(act.source)
else:
return act
class Haste(Condition):
"""
A condition in which the dude's speed doubles.
"""
def __init__(self, duration):
Condition.__init__(self, duration, "haste")
def modifyGlyph(self, glyph):
"""
Turn the hasted thing a funny color to indicate its haste.
"""
return symbol.Glyph(glyph.char, HASTE_COLOR)
def apply(self, dude_):
dude_.speed /= 2
def cancel(self, dude_):
dude_.speed *= 2
class TimeBomb(Condition):
"""
A condition in which a dude explodes after a certain number of turns.
"""
GRENADE_COLORS = {3 : (0, 255, 0),
2 : (0, 255, 0),
1 : (255, 255, 0),
0 : (255, 65, 0)}
EXPLOSION_GLYPH = symbol.Glyph('#', (255, 0, 0))
def __init__(self, timer):
Condition.__init__(self, 0, "timebomb")
self.timer = timer
self.exploded = False
def modifyGlyph(self, glyph):
return symbol.Glyph(glyph.char, self.GRENADE_COLORS[self.timer])
def passTurn(self):
pass
def isOver(self):
return self.exploded
def getAction(self, dude_):
assert self.timer >= 0
if self.timer == 0:
return action.Detonate(dude_)
else:
return action.BombTick(dude_)
class Resting(Condition):
"""
A condition in which a dude rests until it has full health.
This condition is interrupted if there is a monster in sight.
"""
def __init__(self):
Condition.__init__(self, 200, "resting")
def getDisplayName(self):
return ""
def getAction(self, dude_):
if len(dude_.fov.dudes) > 0 or dude_.cur_HP >= dude_.max_HP:
self.time = -5
return None
else:
return action.Wait(dude_)
class Running(Condition):
"""
A condition in which the player moves in a specific direction.
This condition is interrupted if there is a monster in sight, or if there
is something blocking the player's path.
"""
def __init__(self, direction):
Condition.__init__(self, 200, "running")
self.direction = direction
def getDisplayName(self):
return ""
def getAction(self, dude_):
if dude_.canMove(coordinates.add(dude_.coords, self.direction)) \
and len(dude_.fov.dudes) == 0:
return action.Move(dude_, self.direction)
else:
self.time = -5
return None