wield.txt 1.1 KB
def wield(id, players, tokens, mud):
    if len(tokens) == 0:
        mud.send_message(id, " %greenYou are currently wielding: %reset%bold%white{}".format(players[id]['weapon']))
    else:
        if tokens[0] not in players[id]["inventory"]:
            mud.send_message(id, 'You do not have {} in your inventory.'.format(tokens[0]))
        else:
            gear = utils.load_object_from_file('inventory/' + tokens[0] + '.json')
            if gear["type"] == "armor":
                mud.send_message(id, 'That is armor and must be "equip".')
            elif gear["type"] != "weapon":
                mud.send_message(id, 'That cannot be wielded.')
            else:
                players[id]["weapon"] = tokens[0]
                mud.send_message(id, 'You wield the {}!'.format(tokens[0]))
                players[id]["inventory"][tokens[0]].pop()
                if len(players[id]["inventory"][tokens[0]]) == 0:
                    del players[id]["inventory"][tokens[0]]

                utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))


wield(id, players, tokens, mud)
del wield