-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_functions.py
117 lines (87 loc) · 4.14 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
import tcod as libtcod
from components import ai
from game_messages import Message
from render_functions import RenderOrder
def heal(*args, **kwargs):
entity = args[0]
amount = kwargs.get('amount')
results = []
if entity.fighter.hp == entity.fighter.max_hp:
results.append({'consumed': False, 'message': Message('You are already at full health', 'minor_error')})
else:
entity.fighter.heal(amount)
results.append({'consumed': True, 'message': Message('Your wounds start to feel better!', 'effect_bonus')})
return results
def cast_lightning(*args, **kwargs):
caster = args[0]
entities = kwargs.get('entities')
fov_map = kwargs.get('fov_map')
damage = kwargs.get('damage')
maximum_range = kwargs.get('maximum_range')
results = []
target = None
closet_distance = maximum_range + 1
for entity in entities:
#todo change map_is_in_fov to map.Map.fov
if entity.fighter and entity != caster and libtcod.map_is_in_fov(fov_map, entity.x, entity.y):
distance = caster.distance_to(entity)
if distance < closet_distance:
target = entity
closet_distance = distance
if target:
results.append({'consumed': True, 'target': target, 'message': Message(
'A lighting bolt strikes the {0} with loud thunder! The damage is {1}'.format(target.name, damage),
'effect_damage')})
results.extend(target.fighter.take_damage(damage))
else:
results.append(
{'consumed': False, 'target': None, 'message':
Message('No enemy is close enough to strike.', 'minor_error')})
return results
def cast_fireball(*args, **kwargs):
entities = kwargs.get('entities')
fov_map = kwargs.get('fov_map')
damage = kwargs.get('damage')
radius = kwargs.get('radius')
target_x = kwargs.get('target_x')
target_y = kwargs.get('target_y')
results = []
#todo change map_is_in_fov to map.Map.fov
if not libtcod.map_is_in_fov(fov_map, target_x, target_y):
results.append({'consumed': False,
'message': Message('You cannot target a tile outside your field of view.', 'minor_error')})
return results
results.append({'consumed': True,
'message': Message('The fireball explodes, burning everything with {0} tiles'.format(radius),
'minor_effect')})
for entity in entities:
if entity.distance(target_x, target_y) <= radius and entity.fighter:
results.append({'message': Message('The {0} gets burned for {1} hit points.'.format(entity.name, damage),
'effect_damage')})
results.extend(entity.fighter.take_damage(damage))
return results
def cast_confuse(*args, **kwargs):
entities = kwargs.get('entities')
fov_map = kwargs.get('fov_map')
target_x = kwargs.get('target_x')
target_y = kwargs.get('target_y')
results = []
#todo change map_is_in_fov to map.Map.fov
if not libtcod.map_is_in_fov(fov_map, target_x, target_y):
results.append({'consumed': False,
'message': Message('You cannot target a tile outside your field of view.', 'minor_error')})
return results
for entity in entities:
# Entity at location x,y with an ai and isn't a corpse
if entity.x == target_x and entity.y == target_y and entity.ai and entity.render_order != RenderOrder.CORPSE:
confused_ai = ai.ConfusedMonster(entity.ai, 10)
confused_ai.owner = entity
entity.ai = confused_ai
results.append({'consumed': True,
'message': Message('{0} looks confused, as they starts to stumble around!'
.format(entity.full_name), 'minor_effect')})
break
else:
results.append(
{'consumed': False, 'message': Message('There is no enemy at that location.', 'minor_error')})
return results