perform.txt
2.35 KB
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
import utils
# for now actions can only be cast on the thing you are fighting since I don't have a good lexer to pull
# out targets. This also means that actions are offensive only since you cant cast on 'me'
# TODO: Add proper parsing so you can do: cast fireball on turkey or even better, cast fireball on the first turkey
def perform(id, params, players, mud, command):
if params == '':
params = command.strip()
else:
params = params.strip()
if len(params) == 0:
mud.send_message(id, 'What action do you want to perform?')
return True
action = players[id]['at'].get(params)
if not action:
mud.send_message(id, 'You do not appear to know the action %s.' % (params,))
return True
sta = players[id]['sta']
if sta > 0 and sta > action['cost']:
room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(players[id]['room']))
if not room_monsters:
mud.send_message(id, 'There is nothing here to perform that action on.')
for mon_name, monster in room_monsters.items():
monster_template = utils.load_object_from_file('mobs/{}.json'.format(mon_name))
if not monster_template:
continue
fighting = False
for active_monster_idx, active_monster in enumerate(monster['active']):
if active_monster['action'] == "attack" and active_monster['target'] == players[id]['name']:
fighting = True
att, sta = utils.calc_att(mud, id, [], sta, action)
players[id]['sta'] = sta
active_monster['hp'] -= att
# don't let them off without saving cheating sons of bees
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
room_monsters[mon_name]['active'][active_monster_idx] = active_monster
if not fighting:
mud.send_message(id, 'You are not currently in combat')
return True
utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(players[id]['room']))
else:
mud.send_message(id, 'You do not have enough stamina to perform that action.')
if command is None and cmd is not None:
command = cmd
perform(id, params.strip(), players, mud, command)
del perform