Modified mobs to fit in devices ram.
Showing
4 changed files
with
45 additions
and
128 deletions
... | @@ -79,13 +79,13 @@ while True: | ... | @@ -79,13 +79,13 @@ while True: |
79 | if tick >= 1: | 79 | if tick >= 1: |
80 | spawn += tick | 80 | spawn += tick |
81 | tick = 0 | 81 | tick = 0 |
82 | try: | 82 | # try: |
83 | ldict = {} | 83 | ldict = {} |
84 | with open('mobs.txt', 'r', encoding='utf-8') as f: | 84 | with open('mobs.txt', 'r', encoding='utf-8') as f: |
85 | exec(f.read(), globals(), ldict) | 85 | exec(f.read(), globals(), ldict) |
86 | except Exception as e: | 86 | # except Exception as e: |
87 | print('mob error:') | 87 | # print('mob error:') |
88 | print(e) | 88 | # print(e) |
89 | # 'update' must be called in the loop to keep the game running and give | 89 | # 'update' must be called in the loop to keep the game running and give |
90 | # us up-to-date information | 90 | # us up-to-date information |
91 | mud.update() | 91 | mud.update() | ... | ... |
1 | # 1. every tick loop through the players | ||
2 | # 2. for each player load the roomname_monsters.txt | ||
3 | # 3. execute any current action [flee (maybe later), attack, continue combat, special attack (if enough mp or stamina)] | ||
4 | # 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 | # 5. Process any special commands from the player [spells, special attacks based on stamina] | ||
6 | # 6. Write results of action to the player file [damage, mp use, stamina use] | ||
7 | # 7. Write any new inventory to the room file. Expire any inventory that is old TBD.... | ||
8 | # 8. Every minute respawn mobs for any room the players are in. | ||
9 | |||
10 | |||
11 | |||
12 | |||
13 | # def randint(start, stop): | ||
14 | # return randrange(start, stop + 1) | ||
15 | 1 | ||
16 | def run_mobs(players, mud): | 2 | def run_mobs(players, mud): |
3 | def get_att(d): | ||
4 | att = 0 | ||
5 | if 'd' in d: | ||
6 | dice = d.split('d') | ||
7 | for d in range(int(dice[0])): | ||
8 | att += randrange(int(dice[1])) + 1 | ||
9 | else: | ||
10 | att = int(d) | ||
11 | return att | ||
12 | def calc_att(pid, attacks, bank): | ||
13 | v_att = [] | ||
14 | att = 0 | ||
15 | for attack in attacks: | ||
16 | if attack['cost'] < bank: | ||
17 | v_att.append(attack) | ||
18 | # Select a random attack | ||
19 | if len(v_att) > 0: | ||
20 | attack = v_att[randrange(len(v_att))] | ||
21 | att = get_att(attack['dmg']) | ||
22 | mud.send_message(pid, "%s for %d" % (attack['desc'], att,)) | ||
23 | bank -= attack['cost'] | ||
24 | return att, bank | ||
25 | |||
17 | def randrange(start, stop=None): | 26 | def randrange(start, stop=None): |
18 | if 'esp' in sys.platform: | 27 | if 'esp' in sys.platform: |
28 | if start == 1: | ||
29 | return 0 | ||
19 | if stop is None: | 30 | if stop is None: |
20 | stop = start | 31 | stop = start |
21 | start = 0 | 32 | start = 0 |
... | @@ -38,8 +49,6 @@ def run_mobs(players, mud): | ... | @@ -38,8 +49,6 @@ def run_mobs(players, mud): |
38 | for pid, player in players.items(): | 49 | for pid, player in players.items(): |
39 | if not player['name']: | 50 | if not player['name']: |
40 | continue | 51 | continue |
41 | # print(player) | ||
42 | # print('checking actions in room: ' + player['room']) | ||
43 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(player['room'])) | 52 | room_monsters = utils.load_object_from_file('rooms/{}_monsters.json'.format(player['room'])) |
44 | if not room_monsters: | 53 | if not room_monsters: |
45 | continue | 54 | continue |
... | @@ -48,7 +57,6 @@ def run_mobs(players, mud): | ... | @@ -48,7 +57,6 @@ def run_mobs(players, mud): |
48 | if not monster_template: | 57 | if not monster_template: |
49 | continue | 58 | continue |
50 | for active_monster_idx, active_monster in enumerate(monster['active']): | 59 | for active_monster_idx, active_monster in enumerate(monster['active']): |
51 | # Recover MP and Stamina | ||
52 | mp = active_monster['mp'] | 60 | mp = active_monster['mp'] |
53 | hp = active_monster['hp'] | 61 | hp = active_monster['hp'] |
54 | sta = active_monster['sta'] | 62 | sta = active_monster['sta'] |
... | @@ -61,118 +69,27 @@ def run_mobs(players, mud): | ... | @@ -61,118 +69,27 @@ def run_mobs(players, mud): |
61 | if active_monster['action'] == "attack" and active_monster['target'] == player['name']: | 69 | if active_monster['action'] == "attack" and active_monster['target'] == player['name']: |
62 | if hp == 0: | 70 | if hp == 0: |
63 | DEAD = 1 | 71 | DEAD = 1 |
64 | if "d" in monster_template['aa']: | 72 | att = get_att(monster_template['aa']) |
65 | dice = monster_template['aa'].split('d') | 73 | players[pid]['hp'] -= att |
66 | att = 0 | 74 | mud.send_message(pid, "You were hit by a %s for %d" % (mon_name, att,)) |
67 | for d in range(int(dice[0])): | ||
68 | att += randrange(int(dice[1])) + 1 | ||
69 | players[pid]['hp'] -= att | ||
70 | mud.send_message(pid, "You were hit by a %s for %d" % (mon_name, att,)) | ||
71 | # wait until at least 50% of stamina or mp are regenerated or hp is less than 25% | 75 | # wait until at least 50% of stamina or mp are regenerated or hp is less than 25% |
72 | 76 | ||
73 | 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): | 77 | 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): |
74 | magic_cast = False | 78 | magic_cast = False |
75 | # Try magic first | ||
76 | if mp > 0: | 79 | if mp > 0: |
77 | valid_spells = [] | 80 | att, mp = calc_att(pid, monster_template['sp'], mp) |
78 | for spell in monster_template['sp']: | 81 | active_monster['mp'] = mp |
79 | if spell['cost'] < mp: | 82 | players[pid]['hp'] -= att |
80 | valid_spells.append(spell) | 83 | if att > 0: |
81 | # Select a random spell | 84 | magic_cast = True |
82 | if len(valid_spells) > 0: | ||
83 | spell = valid_spells[randrange(len(valid_spells))] | ||
84 | del valid_spells | ||
85 | att = 0 | ||
86 | if 'd' in spell['dmg']: | ||
87 | dice = spell['dmg'].split('d') | ||
88 | for d in range(int(dice[0])): | ||
89 | att += randrange(int(dice[1])) + 1 | ||
90 | else: | ||
91 | att = int(spell['dmg']) | ||
92 | active_monster['mp'] -= spell['cost'] | ||
93 | players[pid]['hp'] -= att | ||
94 | mud.send_message(pid, "%s for %d" % (spell['desc'], att,)) | ||
95 | magic_cast = True | ||
96 | if not magic_cast: | 85 | if not magic_cast: |
97 | # if mp is exhaused or unavailable switch to stamina actions | ||
98 | if sta > 0: | 86 | if sta > 0: |
99 | print(sta) | 87 | att, sta = calc_att(pid, monster_template['at'], sta) |
100 | valid_attacks = [] | 88 | active_monster['sta'] = sta |
101 | for attack in monster_template['at']: | 89 | players[pid]['hp'] -= att |
102 | if attack['cost'] < sta: | ||
103 | valid_attacks.append(attack) | ||
104 | # Select a random attack | ||
105 | if len(valid_attacks) > 0: | ||
106 | rand_val = randrange(len(valid_attacks)) | ||
107 | print("Random attack result: {} Len: {}".format(rand_val, len(valid_attacks))) | ||
108 | attack = valid_attacks[rand_val] | ||
109 | del valid_attacks | ||
110 | att = 0 | ||
111 | if 'd' in attack['dmg']: | ||
112 | dice = attack['dmg'].split('d') | ||
113 | for d in range(int(dice[0])): | ||
114 | att += randrange(int(dice[1])) + 1 | ||
115 | else: | ||
116 | att = int(attack['dmg']) | ||
117 | active_monster['sta'] -= attack['cost'] | ||
118 | players[pid]['hp'] -= att | ||
119 | mud.send_message(pid, "%s for %d" % (attack['desc'], att,)) | ||
120 | magic_cast = True | ||
121 | 90 | ||
122 | room_monsters[mon_name]['active'][active_monster_idx] = active_monster | 91 | room_monsters[mon_name]['active'][active_monster_idx] = active_monster |
123 | 92 | ||
124 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(player['room'])) | 93 | utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(player['room'])) |
125 | # { | ||
126 | # "cricket": { | ||
127 | # "max": 1, | ||
128 | # "active": [ | ||
129 | # { | ||
130 | # "hp": 100, | ||
131 | # "mp": 0, | ||
132 | # "sta": 10, | ||
133 | # "action": "attack", | ||
134 | # "target": "test", | ||
135 | # } | ||
136 | # ] | ||
137 | # } | ||
138 | # } | ||
139 | #prompt(pid) | ||
140 | # active_mobs = utils.load_object_from_file('activemobs.json') | ||
141 | # # check to see if everything has been spawned that needs to be. | ||
142 | # { | ||
143 | # "cricket": { | ||
144 | # "room001": { | ||
145 | # "max": 2, | ||
146 | # "active": [ | ||
147 | # { | ||
148 | # "hp": 100, | ||
149 | # "mp": 0, | ||
150 | # "sta": 10, | ||
151 | # "inv": [] | ||
152 | # }, | ||
153 | # { | ||
154 | # "hp": 100, | ||
155 | # "mp": 0, | ||
156 | # "sta": 10, | ||
157 | # "inv": [] | ||
158 | # } | ||
159 | # ] | ||
160 | # }, | ||
161 | # "tavern": { | ||
162 | # "max": 1, | ||
163 | # "active": [ | ||
164 | # { | ||
165 | # "hp": 100, | ||
166 | # "mp": 0, | ||
167 | # "sta": 10, | ||
168 | # "inv": [] | ||
169 | # } | ||
170 | # ] | ||
171 | # } | ||
172 | # } | ||
173 | # } | ||
174 | # for mob in active_mobs: | ||
175 | |||
176 | |||
177 | 94 | ||
178 | run_mobs(players, mud) | 95 | run_mobs(players, mud) |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -6,7 +6,7 @@ import sys | ... | @@ -6,7 +6,7 @@ import sys |
6 | ###################################### | 6 | ###################################### |
7 | # EDIT THIS TO MATCH YOUR SETTINGS | 7 | # EDIT THIS TO MATCH YOUR SETTINGS |
8 | PORT = 'COM17' | 8 | PORT = 'COM17' |
9 | IPADDRESS = '192.168.1.122' | 9 | IPADDRESS = '192.168.1.189' |
10 | ###################################### | 10 | ###################################### |
11 | 11 | ||
12 | BAUDRATE = 115200 | 12 | BAUDRATE = 115200 | ... | ... |
1 | {"cricket": {"max": 1, "active": [{"hp": 100, "mp": 4.0, "sta": 2.550000000000001, "maxhp": 100, "maxmp": 10, "maxsta": 10, "action": "attack", "target": "test"}]}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | {"cricket": {"max": 1, "active": [{"hp": 100, "mp": 2.75, "sta": 1.7500000000000182, "maxhp": 100, "maxmp": 10, "maxsta": 10, "action": "attack", "target": "test"}]}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment