mobs.txt
4.05 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
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
# 1. every tick loop through the players
# 2. for each player load the roomname_monsters.txt
# 3. execute any current action [flee (maybe later), attack, continue combat, special attack (if enough mp or stamina)]
# 4. Write results of action to the roomname_monsters.txt if the monster is killed or mp / stamina has changed. - Sidenote.. don't store inventory, get a list of possible inventory and randomize on death and drop on the ground (no corpses)
# 5. Process any special commands from the player [spells, special attacks based on stamina]
# 6. Write results of action to the player file [damage, mp use, stamina use]
# 7. Write any new inventory to the room file. Expire any inventory that is old TBD....
# 8. Every minute respawn mobs for any room the players are in.
# def randint(start, stop):
# return randrange(start, stop + 1)
def run_mobs(players, mud):
def randrange(start, stop=None):
if 'esp' in sys.platform:
if stop is None:
stop = start
start = 0
upper = stop - start
bits = 0
pwr2 = 1
while upper > pwr2:
pwr2 <<= 1
bits += 1
while True:
from urandom import getrandbits
r = getrandbits(bits)
if r < upper:
break
return r + start
else:
import random
return random.randrange(start)
for pid, player in players.items():
if not player['name']:
continue
print(player)
print('checking actions in room: ' + player['room'])
room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(player['room']))
for mon_name, monster in room_monsters.items():
print(mon_name)
monster_template = utils.load_object_from_file('mobs/{}.json'.format(mon_name))
print(monster)
for active_monster in monster['active']:
if active_monster['action'] == "attack":
if active_monster['hp'] == 0:
DEAD = 1
if "d" in monster_template['aa']:
dice = monster_template['aa'].split('d')
att = 0
for d in range(int(dice[0])):
att += randrange(int(dice[1]) + 1)
players[pid]['hp'] -= att
mud.send_message(pid, "You were hit by a %s for %d" % (mon_name, att,))
else:
print(randrange(120))
# {
# "cricket": {
# "max": 1,
# "active": [
# {
# "hp": 100,
# "mp": 0,
# "sta": 10,
# "action": "attack",
# "target": "test",
# }
# ]
# }
# }
#prompt(pid)
# active_mobs = utils.load_object_from_file('activemobs.json')
# # check to see if everything has been spawned that needs to be.
# {
# "cricket": {
# "room001": {
# "max": 2,
# "active": [
# {
# "hp": 100,
# "mp": 0,
# "sta": 10,
# "inv": []
# },
# {
# "hp": 100,
# "mp": 0,
# "sta": 10,
# "inv": []
# }
# ]
# },
# "tavern": {
# "max": 1,
# "active": [
# {
# "hp": 100,
# "mp": 0,
# "sta": 10,
# "inv": []
# }
# ]
# }
# }
# }
# for mob in active_mobs:
run_mobs(players, mud)