mobs.txt
3.62 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
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['password']:
continue
if player['mp'] < player['maxmp']:
players[pid]['mp'] += player['mpr']
if player['sta'] < player['maxsta']:
players[pid]['sta'] += player['star']
room_monsters = load_object_from_file('rooms/{}_monsters.json'.format(player['room']))
for mon_name, monster in room_monsters.items():
monster_template = load_object_from_file('mobs/{}.json'.format(mon_name))
for active_monster_idx, active_monster in enumerate(monster['active']):
sta = active_monster['sta']
if active_monster['mp'] < active_monster['maxmp']:
active_monster['mp'] += monster_template['mpr']
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,), color='yellow')
else:
att = get_att(player['aa'])
mud.send_message(pid, "You hit the %s for %d" % (mon_name, att,), color='yellow')
active_monster['hp'] -= att
if active_monster['hp'] <= 0:
del room_monsters[mon_name]['active'][active_monster_idx]
mud.send_message(pid, "The %s dies." % (mon_name,), color=['bold', 'blue'])
break
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,), color='magenta')
else:
att = get_att(monster_template['aa'])
mud.send_message(pid, "You were hit by a %s for %d" % (mon_name, att,), color='magenta')
players[pid]['hp'] -= att
if (active_monster['hp']/active_monster['maxhp'] < 0.25) or (active_monster['mp'] > 0 and active_monster['mp']/active_monster['maxmp'] > 0.5) or (sta > 0 and sta/active_monster['maxsta'] > 0.5):
magic_cast = False
if active_monster['mp'] > 0:
att, active_monster['mp'] = calc_att(mud, pid, monster_template['sp'], active_monster['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