mobs.txt 4.05 KB
# 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)