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()
async def leave(ctx, name): try: npc = party[name] except KeyError: await ctx.send("No party member named " + name) return party.pop(name) npcs[name] = npc await ctx.send(name + " removed from party!") shared_functions.backup_characters()
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)
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
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)
async def random_char(ctx, boss=False): if boss: stat_cap = world["boss stat cap"] else: stat_cap = world["stat cap"] if world["number"] <= 0: await ctx.send("Invalid world.") return global next_backstory global next_short_name global next_name if next_backstory: backstory = next_backstory next_backstory = None else: backstory = random.choice(random_lists.Backstories) if next_short_name: first_name = next_short_name next_short_name = None else: first_name = random.choice(names.Names) while first_name in npcs.keys(): first_name = random.choice(names.Names) if next_name: full_name = next_name next_name = None else: middle_name = None if random.randint(1, 2) == 2: middle_name = random.choice(names.Names) last_name = random.choice(names.Names) if middle_name: full_name = first_name + " " + middle_name + " " + last_name else: full_name = first_name + " " + last_name strongness = random.randint(0, stat_cap) smartness = random.randint(0, stat_cap) coolness = random.randint(0, stat_cap) health = 2 * strongness + 1 gold = random.randint(0, stat_cap * 10) blessing_level = None blessing_roll = random.randint(1, 20) if blessing_roll <= world["number"]: blessing_level = "Level I" blessing_roll = random.randint(1, 20) if blessing_roll <= world["number"]: blessing_level = "Level II" blessing_roll = random.randint(1, 20) if blessing_roll <= world["number"]: blessing_level = "Level III" blessing_name = random.choice(random_lists.Blessings) if blessing_level is None: blessing = "No blessing" else: blessing = "**Blessing of " + blessing_name + "** " + blessing_level trait1 = random.choice(list(traits.trait_dict.keys())) trait2 = trait1 while trait2 == trait1: trait2 = random.choice(list(traits.trait_dict.keys())) color_string = shared_functions.random_color() inventory = [] for i in range(0, 3): if random.randint(1, 4) == 1: inventory.append((await items.random_item(ctx, -2 * world["number"], 1, False)).name) else: inventory.append("Empty slot") if boss: backstory = random.choice(random_lists.BossBackstories) trait1 = random.choice(list(traits.boss_trait_dict.keys())) health *= (5 * world["number"]) gold *= (world["number"] * world["number"]) full_name = "*Boss:* " + full_name secondary_trait_roll = random.randint(1, 20) if secondary_trait_roll <= world["number"]: trait2 = random.choice(traits.boss_trait_dict) while trait1 == trait2: trait2 = random.choice(traits.boss_trait_dict) character = { "Backstory": backstory, "Name": full_name, "Traits": [trait1, trait2], "Smartness": smartness, "Coolness": coolness, "Strongness": strongness, "Health": health, "Gold": gold, "Color": color_string, "Inventory": inventory, "Blessing": blessing } npcs[first_name] = character await ctx.send(embed=characters.print_character(first_name)) shared_functions.backup_characters()
async def recruit(ctx, name): npc = npcs[name] npcs.pop(name) party[name] = npc shared_functions.backup_characters() await ctx.send(name + " added to party!")