-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem_functions.py
176 lines (143 loc) · 4.59 KB
/
item_functions.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
import tcod
from game_messages import Message
from components.ai import ConfusedMonster
from utils import disk
from effect import GFX_Effect
def heal(*args, **kwargs):
entity = args[0]
amount = kwargs.get('amount')
results = []
if entity.fighter.current_hp == entity.fighter.max_hp:
results.append({
'consumed':
False,
'message':
Message('You are already at full health', "yellow")
})
else:
entity.fighter.heal(amount)
results.append({
'consumed':
True,
'message':
Message('Your wounds start to feel better!', "green")
})
return results
def cast_chaos_bolt(*args, **kwargs):
caster = args[0]
entities = kwargs.get("entities")
game_map = kwargs.get("game_map")
damage = kwargs.get("damage")
maximum_range = kwargs.get("maximum_range")
results = []
target = None
closest_distance = maximum_range + 1
for entity in entities:
if entity.fighter and entity != caster and game_map.fov[entity.
x, entity.y]:
distance = caster.distance_to(entity)
if distance < closest_distance:
target = entity
closest_distance = distance
if target:
results.append({
"consumed":
True,
"target":
target,
"message":
Message(
f"A bolt of entropic energies strikes the {target.name} for {damage} damage!",
"crimson")
})
results.extend(target.fighter.take_damage(damage))
game_map.effects.append(
GFX_Effect(target.x, target.y, gfx_effect_tile=0x1009))
else:
results.append({
"consumed":
False,
"target":
None,
"message":
Message("There are no enemies in range.", "red")
})
return results
def cast_fireball(*args, **kwargs):
entities = kwargs.get("entities")
game_map = kwargs.get("game_map")
damage = kwargs.get("damage")
radius = kwargs.get("radius")
target_x = kwargs.get("target_x")
target_y = kwargs.get("target_y")
results = []
if not game_map.fov[target_x, target_y]:
results.append({
"consumed":
False,
"message":
Message("You cannot target a tile outside your line of sight.",
"yellow")
})
return results
results.append({
"consumed":
True,
"message":
Message(
f"The fireball explodes in roaring flames, burning everything within {radius} tiles!"
)
})
target_area = disk(target_x, target_y, radius)
for entity in entities:
if entity.fighter and (entity.x, entity.y) in target_area:
results.append({
"message":
Message(
f"The {entity.name} is engulfed in flames and is burned for {damage} hit points!",
"orange")
})
results.extend(entity.fighter.take_damage(damage))
for map_coordinates in target_area:
game_map.effects.append(
GFX_Effect(map_coordinates[0],
map_coordinates[1],
gfx_effect_tile=0x1008))
return results
def cast_confuse(*args, **kwargs):
entities = kwargs.get("entities")
game_map = kwargs.get("game_map")
target_x = kwargs.get("target_x")
target_y = kwargs.get("target_y")
results = []
if not game_map.fov[target_x, target_y]:
results.append({
"consumed":
False,
"message":
Message("You cannot target a tile outside your line of sight.",
"yellow")
})
return results
for entity in entities:
if entity.x == target_x and entity.y == target_y and entity.ai:
confused_ai = ConfusedMonster(entity.ai, 10)
confused_ai.owner = entity
entity.ai = confused_ai
results.append({
"consumed":
True,
"message":
Message(
f"The eyes of the {entity.name} look vacant as it starts to stumble around!",
"light green")
})
break
else:
results.append({
"consumed":
False,
"message":
Message("There is no targetable enemy at that location.", "yellow")
})
return results