a610ab4f by Barry

Modified mobs to fit in devices ram.

1 parent 4c1a58d5
......@@ -79,13 +79,13 @@ while True:
if tick >= 1:
spawn += tick
tick = 0
try:
ldict = {}
with open('mobs.txt', 'r', encoding='utf-8') as f:
exec(f.read(), globals(), ldict)
except Exception as e:
print('mob error:')
print(e)
# try:
ldict = {}
with open('mobs.txt', 'r', encoding='utf-8') as f:
exec(f.read(), globals(), ldict)
# except Exception as e:
# print('mob error:')
# print(e)
# 'update' must be called in the loop to keep the game running and give
# us up-to-date information
mud.update()
......
# 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 get_att(d):
att = 0
if 'd' in d:
dice = d.split('d')
for d in range(int(dice[0])):
att += randrange(int(dice[1])) + 1
else:
att = int(d)
return att
def calc_att(pid, attacks, bank):
v_att = []
att = 0
for attack in attacks:
if attack['cost'] < bank:
v_att.append(attack)
# Select a random attack
if len(v_att) > 0:
attack = v_att[randrange(len(v_att))]
att = get_att(attack['dmg'])
mud.send_message(pid, "%s for %d" % (attack['desc'], att,))
bank -= attack['cost']
return att, bank
def randrange(start, stop=None):
if 'esp' in sys.platform:
if start == 1:
return 0
if stop is None:
stop = start
start = 0
......@@ -38,8 +49,6 @@ def run_mobs(players, mud):
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']))
if not room_monsters:
continue
......@@ -48,7 +57,6 @@ def run_mobs(players, mud):
if not monster_template:
continue
for active_monster_idx, active_monster in enumerate(monster['active']):
# Recover MP and Stamina
mp = active_monster['mp']
hp = active_monster['hp']
sta = active_monster['sta']
......@@ -61,118 +69,27 @@ def run_mobs(players, mud):
if active_monster['action'] == "attack" and active_monster['target'] == player['name']:
if 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,))
att = get_att(monster_template['aa'])
players[pid]['hp'] -= att
mud.send_message(pid, "You were hit by a %s for %d" % (mon_name, 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
# Try magic first
if mp > 0:
valid_spells = []
for spell in monster_template['sp']:
if spell['cost'] < mp:
valid_spells.append(spell)
# Select a random spell
if len(valid_spells) > 0:
spell = valid_spells[randrange(len(valid_spells))]
del valid_spells
att = 0
if 'd' in spell['dmg']:
dice = spell['dmg'].split('d')
for d in range(int(dice[0])):
att += randrange(int(dice[1])) + 1
else:
att = int(spell['dmg'])
active_monster['mp'] -= spell['cost']
players[pid]['hp'] -= att
mud.send_message(pid, "%s for %d" % (spell['desc'], att,))
magic_cast = True
att, mp = calc_att(pid, monster_template['sp'], mp)
active_monster['mp'] = mp
players[pid]['hp'] -= att
if att > 0:
magic_cast = True
if not magic_cast:
# if mp is exhaused or unavailable switch to stamina actions
if sta > 0:
print(sta)
valid_attacks = []
for attack in monster_template['at']:
if attack['cost'] < sta:
valid_attacks.append(attack)
# Select a random attack
if len(valid_attacks) > 0:
rand_val = randrange(len(valid_attacks))
print("Random attack result: {} Len: {}".format(rand_val, len(valid_attacks)))
attack = valid_attacks[rand_val]
del valid_attacks
att = 0
if 'd' in attack['dmg']:
dice = attack['dmg'].split('d')
for d in range(int(dice[0])):
att += randrange(int(dice[1])) + 1
else:
att = int(attack['dmg'])
active_monster['sta'] -= attack['cost']
players[pid]['hp'] -= att
mud.send_message(pid, "%s for %d" % (attack['desc'], att,))
magic_cast = True
att, sta = calc_att(pid, monster_template['at'], sta)
active_monster['sta'] = sta
players[pid]['hp'] -= att
room_monsters[mon_name]['active'][active_monster_idx] = active_monster
utils.save_object_to_file(room_monsters, 'rooms/{}_monsters.json'.format(player['room']))
# {
# "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)
\ No newline at end of file
......
......@@ -6,7 +6,7 @@ import sys
######################################
# EDIT THIS TO MATCH YOUR SETTINGS
PORT = 'COM17'
IPADDRESS = '192.168.1.122'
IPADDRESS = '192.168.1.189'
######################################
BAUDRATE = 115200
......
{"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
{"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
......