Example #1
0
async def combat(ctx,
                 name,
                 weapon_damage,
                 target,
                 global_modifier=0,
                 stat="Strongness"):
    damage_target = False
    try:
        defense = int(target)
    except ValueError:
        target_character = shared_functions.find_character(target)
        if not target_character:
            await ctx.send("Could not find target.")
            return
        if stat in target_character:
            defense = target_character[stat]
        else:
            await ctx.send("Stat does not exist.")
        damage_target = True
    try:
        global_modifier = int(global_modifier)
        weapon_damage = int(weapon_damage)
    except ValueError:
        await ctx.send("One of the numerical parameters was not a number.")
        return
    character = shared_functions.find_character(name)
    global_modifier += world["modifier"]
    if not character:
        await ctx.send("No character named " + name)
        return
    if stat not in character:
        await ctx.send("Invalid stat")
        return
    roll = random.randint(1, 20)
    print(roll)
    miss = False
    crit = 1
    if roll == 20:
        crit = 2
    if roll == 1:
        miss = True
    else:
        damage_done = (character[stat] - defense + roll + global_modifier -
                       10) * (weapon_damage * crit)
        if damage_done < 0:
            damage_done = 0
    if miss:
        await ctx.send("Missed!")
    else:
        if damage_target and damage_done > 0:
            await damage(ctx, target, damage_done)
        await ctx.send("Did " + str(damage_done) + " damage!")
        if crit > 1:
            await ctx.send("A critical hit!")
Example #2
0
async def sell(ctx, character_name, item_name, show_price=False):
    # TODO: Add support to attempt to sell an item to an NPC.
    character = shared_functions.find_character(character_name)
    if not character:
        await ctx.send("No character named " + character_name)
        return
    if item_name not in items.item_dict.keys():
        await ctx.send("No item named " + item_name)
        return
    if item_name not in character["Inventory"]:
        await ctx.send(character_name + " does not have " + item_name +
                       " in their inventory!")
        return
    item = items.item_dict[item_name]
    if item.quality == 0:
        price = 0
    elif item.quality == 1:
        price = 1
    elif item.quality == 2:
        price = 10
    elif item.quality == 3:
        price = 50
    elif item.quality == 4:
        price = 100
    elif item.quality == 5:
        price = 1000
    if show_price:
        await ctx.send("Selling this item will net you ", price, " gold.")
    else:
        character["Gold"] += price
        await remove_item(ctx, character_name, item_name)
    shared_functions.backup_characters()
Example #3
0
def change_character_data(name, data, value):
    if data == "Strongness" or data == "Smartness" or data == "Coolness" or data == "Health" or data == "Gold":
        value = int(value)
    # Hidden stats need handling here when implemented.

    character = shared_functions.find_character(name)
    if not character:
        return
    character[data] = value
Example #4
0
async def change_blessing(ctx, name, blessing, override=False):
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Character does not exist")
        return
    if blessing not in blessing_dict and override is not False:
        await ctx.send("Blessing does not exist or is not unlocked")
        return
    character["Blessing"] = blessing
    await ctx.send(embed=characters.print_character(name))
Example #5
0
async def next_name_function(ctx, name):
    global next_short_name
    global next_name
    next_short_name = name.split(" ")[0]
    if shared_functions.find_character(next_short_name) is not None:
        await ctx.send("A character already exists with the name " +
                       next_short_name + ".")
        next_short_name = None
        return
    next_name = name
Example #6
0
async def check(ctx, name, stat, required_number, global_modifier=0):
    try:
        required_number = int(required_number)
    except ValueError:
        target = shared_functions.find_character(required_number)
        if not target:
            await ctx.send("There is no character named " + required_number)
            return
        if stat not in target:
            await ctx.send(required_number + " has no stat " + stat)
            return
        required_number = target[stat]
        # get required_number from target stat.
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("There is no character named " + name)
        return
    try:
        global_modifier = int(global_modifier)
    except ValueError:
        await ctx.send("Modifier is not a number...")
        return
    if stat not in character:
        await ctx.send(name + " has no stat " + stat)
        return
    global_modifier += world["modifier"]
    roll = random.randint(1, 20)
    print(roll)
    passed = False
    if roll == 20:
        passed = True
    elif roll == 1:
        pass
    else:
        if (character[stat] - required_number) + roll + global_modifier >= 11:
            passed = True
    if passed:
        await ctx.send(stat + " check passed!")
    else:
        await ctx.send(stat + " check failed!")
Example #7
0
async def heal(ctx, name, number=None):
    if number is not None:
        await increase(ctx, name, "Health", number)
    else:
        character = shared_functions.find_character(name)
        if not character:
            await ctx.send("Character " + name + " does not exist, dummy")
            return
        # hardcoded max health right now; will eventually need to change to a character["Max Health"] attribute if i
        # implement things like Blessing of Bloat
        characters.change_character_data(name, "Health",
                                         2 * character["Strongness"] + 1)
        await ctx.send(embed=characters.print_character(name))
Example #8
0
async def add_item(ctx, name, item):
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Character does not exist!")
        return
    for i in range(0, len(character["Inventory"])):
        if character["Inventory"][i] == "Empty slot" or character["Inventory"][
                i] == "Empty Slot":
            character["Inventory"][i] = item
            break
    else:
        await ctx.send(name + "'s inventory is full!")
        return
    await ctx.send(embed=characters.print_character(name))
Example #9
0
async def remove_item(ctx, name, item):
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Character does not exist!")
        return
    length = len(item)
    for i in range(0, len(character["Inventory"])):
        print(character["Inventory"][i][0:length])
        if character["Inventory"][i][0:length] == item:
            character["Inventory"][i] = "Empty slot"
            break
    else:
        await ctx.send("Item not found.")
        return
    await ctx.send(embed=characters.print_character(name))
Example #10
0
async def inventory_size(ctx, name, size):
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Character does not exist!")
        return
    try:
        int(size)
    except ValueError:
        await ctx.send("That is not a number you moron!")
        return
    length = len(party[name]["Inventory"])
    if length > int(size):
        party[name]["Inventory"] = party[name]["Inventory"][0:int(size)]
    elif length < int(size):
        for i in range(length, int(size)):
            party[name]["Inventory"].append("Empty slot")
    else:
        await ctx.send("Character already has inventory of size " + size + ".")
        return
    await ctx.send(embed=characters.print_character(name))
Example #11
0
async def buy(ctx, name, item_name):
    if item_name not in item_dict.keys():
        await ctx.send("I've never heard of that item...")
        return
    gold = item_dict[item_name].last_price
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Character " + name + " does not exist!")
        return
    if gold > int(character["Gold"]):
        await ctx.send("Not enough gold!")
        return
    for slot in character["Inventory"]:
        if slot == "Empty slot":
            slot_number = character["Inventory"].index(slot)
            break
    else:
        await ctx.send("Not enough inventory space!")
    character["Inventory"][slot_number] = item_name
    character["Gold"] = character["Gold"] - gold
    await ctx.send(embed=characters.print_character(name))
Example #12
0
async def change_trait(ctx, name, old_trait, new_trait):
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Party member or NPC not found.")
        return
    if new_trait not in trait_dict:
        await ctx.send("Trait " + new_trait + " does not exist!")
        return
    if old_trait not in character["Traits"]:
        if old_trait == "1":
            old_trait = character["Traits"][0]
        elif old_trait == "2":
            old_trait = character["Traits"][1]
        elif old_trait == "3":
            old_trait = character["Traits"][2]
        else:
            await ctx.send("Character " + name + " does not have trait " +
                           old_trait + "!")
            return
    character["Traits"][character["Traits"].index(old_trait)] = new_trait
    await ctx.send(embed=characters.print_character(name))
Example #13
0
async def increase(ctx, name, stat, number):
    try:
        number = int(number)
    except ValueError:
        await ctx.send("Stat must be increased by a number.")
        return
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Character " + name + " does not exist")
        return
    if stat not in character:
        await ctx.send("Stat " + stat + " does not exist")
        return
    try:
        # prevent some jackass from crashing bot by trying to increase "Backstory"
        int(character[stat])
    except ValueError:
        await ctx.send("Are you trying to increase a non-numerical stat...?")
        return
    character[stat] += number
    await ctx.send(embed=characters.print_character(name))
Example #14
0
async def kill_char(ctx, name):
    # TODO: Have a character drop their entire inventory upon being killed, activating any explosives.
    #  It would be pretty comical to randomly trigger %use (prompting for a target if necessary).

    # TODO: File away deceased characters in an additional dictionary for use with Necromancer.
    character = shared_functions.find_character(name)
    if not character:
        await ctx.send("Could not find party member or NPC named " + name)
        return
    if name in npcs.keys():
        relevant_dict = npcs
    else:
        relevant_dict = party
    # later: add to necromancy dictionary
    response = "**" + relevant_dict[name]["Name"] + " has been slain.**"
    for item in relevant_dict[name]["Inventory"]:
        if item != "Empty slot":
            response += "\nThe following item dropped: " + items.item_dict[
                item].print_teaser()
    relevant_dict.pop(name, False)
    shared_functions.backup_characters()
    await ctx.send(response)
Example #15
0
def print_character(name):
    """Given the name of a character which is either in the party or npc dictionaries, returns an Embed object with all of their relevant qualities."""
    character = shared_functions.find_character(name)
    if not character:
        return discord.Embed(title="Invalid character")
    embed = discord.Embed(title=character["Name"], description=character["Backstory"],
                          color=int(character["Color"], 16))
    embed.add_field(name="**Strongness**", value=character["Strongness"])
    embed.add_field(name="**Smartness**", value=character["Smartness"])
    embed.add_field(name="**Coolness**", value=character["Coolness"])
    embed.add_field(name="**Health**", value=character["Health"])
    embed.add_field(name="**Gold**", value=character["Gold"])
    traits_field = ""
    for trait in character["Traits"]:
        try:
            traits_field += traits.trait_dict[trait].print() + "\n"
        except KeyError:
            traits_field += traits.boss_trait_dict[trait].print() + "\n"
    embed.add_field(name="__**Traits**__", value=traits_field)
    # TODO: Implement support in print_character for blessings that aren't unlocked.
    #  None are currently implemented, so it can wait.
    if character["Blessing"] in traits.blessing_dict:
        embed.add_field(name="__**Blessing**__", value=traits.blessing_dict[character["Blessing"]].print())
    else:
        if character["Blessing"] != "No blessing":
            embed.add_field(name="__**Blessing**__", value="**" + character["Blessing"] + "**: ????")
    inventory_string = ""
    for item in character["Inventory"]:
        if item != "Empty slot":
            if name in npcs.keys():
                inventory_string += "**Unknown item**: ???\n"
            else:
                item = items.item_dict[item]
                inventory_string += "- " + item.print() + "\n"
        else:
            inventory_string += "- Empty slot\n"
    embed.add_field(name="__**Inventory**__", value=inventory_string)
    shared_functions.backup_characters()
    return embed
Example #16
0
async def wizard_main(message):
    wizards = shared_functions.get_dict_from_json("wizards.json")
    wizard_data = await get_user_data(wizards, message)
    if not wizard_data:
        return
    phase = wizard_data["Phase"]
    if phase == "Long name":
        wizard_data["Short name"] = message.content.split(" ")[0]
        if shared_functions.find_character(wizard_data["Short name"]):
            await message.channel.send(
                "Alas, a character already exists with the name of " +
                wizard_data["Short name"] + ". Please try again.")
            return
        wizard_data["Long name"] = message.content
        wizard_data["Traits"] = []
        wizard_data["Phase"] = "Backstory"
        await message.channel.send("What is your character's backstory?")
    elif phase == "Backstory":
        wizard_data["Backstory"] = message.content
        wizard_data["Phase"] = "Strongness"
        await message.channel.send(
            "What is your character's Strongness? (There are 3 stats; they must add up to 11.)"
        )
    elif phase == "Strongness":
        if await check_numerical(message):
            wizard_data["Strongness"] = int(message.content)
            wizard_data["Phase"] = "Smartness"
            await message.channel.send("What is your character's Smartness?")
    elif phase == "Smartness":
        if await check_numerical(message):
            wizard_data["Smartness"] = int(message.content)
            wizard_data["Phase"] = "Coolness"
            await message.channel.send("What is your character's Coolness?")
    elif phase == "Coolness":
        if await check_numerical(message):
            wizard_data["Coolness"] = int(message.content)
        stat_total = wizard_data["Strongness"] + wizard_data[
            "Smartness"] + wizard_data["Coolness"]
        if stat_total != 11:
            await message.channel.send(
                "Is math not your strong suit...? Those numbers add up to " +
                str(stat_total) +
                ", not 11!\n What is your character's Strongness?")
            wizard_data["Phase"] = "Strongness"
        else:
            starting_gold = random.randint(0, 100)
            await message.channel.send("Your character will start with " +
                                       str(starting_gold) + " Gold.")
            wizard_data["Gold"] = starting_gold
            wizard_data["Health"] = wizard_data["Strongness"] * 2 + 1
            wizard_data["Traits"].append(
                random.choice(list(traits.trait_dict.keys())))
            await message.channel.send(
                "Your random trait is: " +
                traits.trait_dict[wizard_data["Traits"][0]].print())
            wizard_data["Options"] = await assign_options(
                traits.trait_dict, 3, message)
            wizard_data["Phase"] = "Traits"
    elif phase == "Traits":
        if await check_if_valid_option(wizard_data["Options"], message):
            wizard_data["Traits"].append(message.content)
            wizard_data["Options"] = await assign_options(
                traits.blessing_dict, 5, message)
            wizard_data["Phase"] = "Blessing"
    elif phase == "Blessing":
        if await check_if_valid_option(wizard_data["Options"], message):
            wizard_data["Blessing"] = message.content
            wizard_data["Options"] = await assign_options(
                items.item_dict, 3, message, True)
            # TODO: Instead of giving completely random items, give items based on a roll.
            #  This probably involves an actual roll refactor, which would make sense ASAP.
            #  I don't love the way world is currently implemented, particularly in relation to the wizard.
            wizard_data["Phase"] = "Item"
    elif phase == "Item":
        if message.content in ["Strongness", "Smartness", "Coolness"]:
            if wizard_data[message.content] > 0:
                wizard_data[message.content] -= 1
                wizard_data["Options"] = await assign_options(
                    items.item_dict, 3, message, True)
            else:
                await message.channel.send("You don't have any more " +
                                           message.content + " to gamble!")
        elif await check_if_valid_option(wizard_data["Options"], message):
            wizard_data["Inventory"] = [
                message.content, "Empty slot", "Empty slot"
            ]
            await message.channel.send(
                "Character creation wizard complete. Adding character to the party."
            )
            character_dict = {
                "Name": wizard_data["Long name"],
                "Strongness": wizard_data["Strongness"],
                "Coolness": wizard_data["Coolness"],
                "Smartness": wizard_data["Smartness"],
                "Traits": wizard_data["Traits"],
                "Inventory": wizard_data["Inventory"],
                "Blessing": wizard_data["Blessing"],
                "Color": shared_functions.random_color(),
                "Health": wizard_data["Health"],
                "Gold": wizard_data["Gold"],
                "Backstory": wizard_data["Backstory"]
            }
            party[wizard_data["Short name"]] = character_dict
            shared_functions.backup_characters()
            wizards.pop(wizard_data["Discriminator"])

    shared_functions.backup_wizards(wizards)
Example #17
0
async def damage(ctx, name, number):
    await decrease(ctx, name, "Health", number)
    character = shared_functions.find_character(name)
    if character and character["Health"] <= 0:
        await kill_char(ctx, name)