mobs.txt
3.41 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def run_mobs(players, mud):
from utils import load_object_from_file, save_object_to_file, calc_att, get_att
for pid, player in players.items():
if not player['name']:
continue
room_monsters = load_object_from_file('rooms/{}_monsters.json'.format(player['room']))
if not room_monsters:
continue
for mon_name, monster in room_monsters.items():
monster_template = load_object_from_file('mobs/{}.json'.format(mon_name))
if not monster_template:
continue
for active_monster_idx, active_monster in enumerate(monster['active']):
mp = active_monster['mp']
hp = active_monster['hp']
sta = active_monster['sta']
if mp < active_monster['maxmp']:
mp += monster_template['mpr']
active_monster['mp'] = mp
if sta < active_monster['maxsta']:
sta += monster_template['star']
active_monster['sta'] = sta
if active_monster['action'] == "attack" and active_monster['target'] == player['name']:
if player.get("weapon"):
weapon = load_object_from_file('inventory/{}.json'.format(player['weapon']))
att = get_att(weapon['damage'])
mud.send_message(pid, "Your %s strikes the %s for %d" % (weapon['title'], mon_name, att,))
else:
att = get_att(player['aa'])
mud.send_message(pid, "You hit the %s for %d" % (mon_name, att,))
hp -= att
if hp == 0:
DEAD = 1
if active_monster.get("weapon"):
weapon = load_object_from_file('inventory/{}.json'.format(active_monster['weapon']))
att = get_att(weapon['damage'])
mud.send_message(pid, "The %s strikes you with a %s for %d" % (mon_name, weapon['title'], att,))
else:
att = get_att(monster_template['aa'])
mud.send_message(pid, "You were hit by a %s for %d" % (mon_name, att,))
players[pid]['hp'] -= att
# wait until at least 50% of stamina or mp are regenerated or hp is less than 25%
if (hp/active_monster['maxhp'] < 0.25) or (mp > 0 and mp/active_monster['maxmp'] > 0.5) or (sta > 0 and sta/active_monster['maxsta'] > 0.5):
magic_cast = False
if mp > 0:
att, mp = calc_att(mud, pid, monster_template['sp'], mp)
active_monster['mp'] = mp
players[pid]['hp'] -= att
if att > 0:
magic_cast = True
if not magic_cast:
if sta > 0:
att, sta = calc_att(mud, pid, monster_template['at'], sta)
active_monster['sta'] = sta
players[pid]['hp'] -= att
room_monsters[mon_name]['active'][active_monster_idx] = active_monster
save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(player['room']))
run_mobs(players, mud)
del run_mobs