async def equip(ctx): user = ctx.message.author message_contents = ctx.message.content[7:] weapon_id = game.hash_string(message_contents) if db.get_user_item(user.id, weapon_id) is not None: target_weapon = db.get_weapon(weapon_id) if target_weapon is not None: character_data = list(db.get_character(user.id)) boolean, error_str = character.can_equip( character_data, target_weapon) if not boolean: await ctx.message.channel.send(error_str) return if target_weapon[1] in character.get_class_weapons( character_data[3]): if character_data[2] != game.hash_string("fist"): db.add_item(user.id, character_data[2], 1) character_data[2] = weapon_id db.add_item(user.id, weapon_id, -1) db.update_character(character_data) await ctx.message.channel.send( f"{message_contents} has been equiped") return await ctx.message.channel.send( f"{character_data[3]} cannot equip {target_weapon[1]}") return await ctx.message.channel.send( f"{message_contents} is not a valid weapon") return await ctx.message.channel.send( f"you don't have a {message_contents}")
async def sell(ctx): user = ctx.message.author user_inv = db.get_inventory(user.id)[0] message_contents = ctx.message.content.split(" ") amount = 1 if message_contents[-1].isdigit(): item_name = " ".join(message_contents[1:-1]) amount = int(message_contents[-1]) else: item_name = " ".join(message_contents[1:]) for abbreviation in database.abbreviations: item_name = item_name.replace(abbreviation[0], abbreviation[1]) if item_name not in user_inv.keys(): await ctx.message.channel.send( f"you don't have any {item_name}") return if user_inv[item_name] >= amount: game.update_money( user.id, int( db.get_item(game.hash_string(item_name))[2] * amount / 4)) await ctx.message.channel.send( f"{user.mention} sold {str(amount)} X {item_name} for {int(db.get_item(game.hash_string(item_name))[2]*amount/4)}{self.get_discord_emoji(822330641559191573)}" ) db.add_item(user.id, game.hash_string(item_name), -amount) logging.info( f"{str(user.id)} has removed {str(amount)} X {item_name}") return await message.channel.send( f"you don't have enough {item_name}, my friend")
async def buy(ctx): message_contents = ctx.message.content.split(" ") user = ctx.message.author amount = 1 if message_contents[-1].isdigit(): item_name = " ".join(message_contents[1:-1]) amount = int(message_contents[-1]) else: item_name = " ".join(message_contents[1:]) if item_name in database.forbidden_items: await ctx.message.channel.send( f"you can't buy {item_name} here") return if db.get_inventory(ctx.message.author.id)[1] + amount > 20: await ctx.message.channel.send("you can't have over 20 items") return for abbreviation in database.abbreviations: item_name = item_name.replace(abbreviation[0], abbreviation[1]) if db.get_item(game.hash_string(item_name)) is None: await ctx.message.channel.send( f"{item_name} is not a valid item") return price = db.get_item(game.hash_string(item_name))[2] if item_name in self.shop.return_items(): price = price * 0.95 if game.update_money(user.id, -price * amount): db.add_item(user.id, game.hash_string(item_name), amount) await ctx.message.channel.send( f"{user.mention} bought {str(amount)} X {item_name}") logging.info(f"{user.id} bought {str(amount)} X {item_name}") return await ctx.message.channel.send( "you don't have enough money, my friend")
async def use(ctx): user = ctx.message.author target_item = ctx.message.content[5:] for abbreviation in database.abbreviations: target_item = target_item.replace(abbreviation[0], abbreviation[1]) if db.get_user_item(user.id, game.hash_string(target_item)) is None: await ctx.message.channel.send( f"you don't have a {target_item}") return item_data = db.get_usable(game.hash_string(target_item)) if item_data is None or item_data[0] == game.hash_string( "transportation ticket" ) or item_data[0] == game.hash_string("test seal"): await ctx.message.channel.send( f"{target_item} is not a valid item") return char_data = list(db.get_character(user.id)) db.add_item(user.id, game.hash_string(target_item), -1) char_data[item_data[1]] += item_data[2] char_data = await character.character_check( char_data, ctx.message.author, ctx.message) db.update_character(char_data) await ctx.message.channel.send( f"you gained {item_data[2]} {stats_target[item_data[1]-6]}")
async def raid(ctx): level = 5 user = ctx.message.author if ctx.message.channel.id not in id["channel"].values(): await ctx.message.channel.send("This is not a place for battle" ) return if "red essence" not in db.get_inventory(user.id)[0].keys(): await ctx.message.channel.send("you need red essence to raid") return timer_data = db.get_timer(user.id, ctx.message.channel.id) if timer_data is not None: dif = datetime.datetime.now() - timer_data[2] if dif.seconds < 180: await ctx.message.channel.send( f"{str(datetime.timedelta(seconds=180-int(dif.total_seconds())))} left" ) return else: db.update_timer(user.id, ctx.message.channel.id, datetime.datetime.now()) else: db.add_timer(user.id, ctx.message.channel.id, datetime.datetime.now()) if ctx.message.channel.id == id["channel"]["great-plains"]: character_class = "Warlord" level = 20 elif ctx.message.channel.id == id["channel"]["forest"]: character_class = "Sharpshooter" level = 30 elif ctx.message.channel.id == id["channel"]["mountain"]: character_class = "General" level = 40 elif ctx.message.channel.id == id["channel"]["prairies"]: character_class = "Gamer" level = 40 elif ctx.message.channel.id == id["channel"]["shores"]: character_class = "Viking" level = 50 elif ctx.message.channel.id == id["channel"]["valley"]: character_class = "Taoist" level = 60 elif ctx.message.channel.id == id["channel"]["out-skirts"]: character_class = "Viking" level = 100 boss_data = character.generate_boss( "boss", level, character_class, game.hash_string( character.generate_class_weapon(character_class, level))) boss_embed = self.create_enemy_embed(boss_data) db.add_item(user.id, game.hash_string("red essence"), -1) msg = await ctx.message.channel.send("a boss fight ig") thread = await msg.create_thread(name="thread for ur boss fight") boss_msg = await thread.send(embed=boss_embed) await boss_msg.add_reaction("⚔️") await boss_msg.add_reaction("💢") boss_data[0] = boss_msg.id db.add_enemy(boss_data) TBG_logger.info(f"spawning a {character_class}")
def create_inventory_embed(self, inventory_data): weapons, usables = "", "" for item_name in inventory_data: if db.get_usable(game.hash_string(item_name)) is not None: usables += f"{self.get_discord_emoji(db.get_graphic(item_name)[1])} {item_name} X {inventory_data[item_name]}\n" if db.get_weapon(game.hash_string(item_name)) is not None: weapons += f"{self.get_discord_emoji(db.get_graphic(item_name)[1])} {item_name} X {inventory_data[item_name]}\n" InventoryEmbed = discord.Embed(colour=discord.Colour.green()) InventoryEmbed.set_author(name="INVENTORY") if weapons != "": InventoryEmbed.add_field(name="`Weapons`", value=weapons) if usables != "": InventoryEmbed.add_field(name="`Usables`", value=usables) return InventoryEmbed
async def order(ctx): user = ctx.message.author target_drink = ctx.message.content[7:] user_data = list(db.get_user(user.id)) char_data = db.get_character(user.id) if user_data[6] >= int(char_data[4] / 5): await ctx.message.channel.send( f"you need to level up a little more to get more drinks") return if target_drink not in alcoholic_drinks: await ctx.message.channel.send( f"sorry man, i don't carry any {target_drink}") return cost = min(int(char_data[4] / 5), user_data[6] + 1) * 100 if game.update_money(user.id, -cost): user_data[6] += 1 db.add_item(user.id, game.hash_string(target_drink), 1) db.update_user(user_data) await ctx.message.channel.send( f"you bought {target_drink} for {cost}{self.get_discord_emoji(822330641559191573)}" ) return await ctx.message.channel.send( f"next drink costs {cost}{self.get_discord_emoji(822330641559191573)}" )
async def prestige(ctx): user = ctx.message.author char_data = list(db.get_character(user.id)) user_data = list(db.get_user(user.id)) if char_data[4] < 60: await ctx.message.channel.send("you're not level 60 yet") return num = int((char_data[4] - 60) / 20) + 1 user_data[5] += num user_data[6] = 0 char_data = character.generate_character( user.id, user.display_name, "swordsmen", game.hash_string("stone sword"), user_data[5]) db.update_user(user_data) db.update_character(char_data) db.update_bank(user.id, -db.get_bank(user.id)[1]) db.update_bank(user.id, 200) db.clear_inventory(user.id) member = await self.guild.fetch_member(user.id) for role in member.roles: if role.id in location_ids.values(): await member.remove_roles(role) await member.add_roles( self.guild.get_role(id["role"]["first floor"])) await ctx.message.channel.send( f"{user.mention} have been reset to level 1, and gained some bonus permanent {num} to all stats, and your inventory has been cleared, so here's 200 gold coins to start off " )
async def setup_player(self, user): if db.get_user(user.id) is None: db.add_user(user.id) db.add_character( character.generate_character(user.id, user.display_name, "swordsmen", game.hash_string("stone sword"), 0)) db.add_bank(user.id, 100)
def create_info_embed(self, name): item_data = db.get_item(game.hash_string(name)) usable_data = db.get_usable(game.hash_string(name)) weapon_data = db.get_weapon(game.hash_string(name)) class_data = db.get_class(name) if usable_data is not None: InfoEmbed = discord.Embed(colour=discord.Colour.light_grey(), description=db.get_item( game.hash_string(name))[4]) InfoEmbed.set_author(name=name) InfoEmbed.set_thumbnail( url=self.get_discord_emoji(db.get_graphic(name)[1]).url) InfoEmbed.add_field(name="`TARGET`", value=stats_target[usable_data[1] - 6]) InfoEmbed.add_field(name="`AMT`", value=usable_data[2]) InfoEmbed.add_field(name="`COST`", value=item_data[2]) return InfoEmbed elif weapon_data is not None: InfoEmbed = discord.Embed(colour=discord.Colour.light_grey(), description=db.get_item( game.hash_string(name))[4]) InfoEmbed.set_author(name=name) InfoEmbed.set_thumbnail( url=self.get_discord_emoji(db.get_graphic(name)[1]).url) InfoEmbed.add_field(name="`TYPE`", value=weapon_data[1]) InfoEmbed.add_field(name="`PWR`", value=weapon_data[2]) InfoEmbed.add_field(name="`CRT`", value=weapon_data[3]) InfoEmbed.add_field(name="`COST`", value=item_data[2]) return InfoEmbed elif class_data is not None: InfoEmbed = discord.Embed(colour=discord.Colour.light_grey(), description=class_data[2]) InfoEmbed.set_author(name=name) InfoEmbed.set_thumbnail(url=db.get_graphic(name)[1]) InfoEmbed.add_field(name="`GROWTH RATE`", value=class_data[1]) if class_data[3] == "": InfoEmbed.add_field(name="`ATTRIBUTE`", value="None") else: InfoEmbed.add_field(name="`ATTRIBUTE`", value=class_data[3]) InfoEmbed.add_field(name="`WEAPON CHOICE`", value=class_data[4]) return InfoEmbed else: return None
async def register(ctx): user = ctx.message.author if db.get_bank(user.id) is None: db.add_user(user.id) if db.get_character(user.id) is None: db.add_character( character.generate_character( user.id, user.display_name, "swordsmen", game.hash_string("stone sword"), 0)) if db.get_bank(user.id) is None: db.add_bank(user.id, 100) await ctx.message.channel.send(f"{user.name} has been registered")
async def menu(ctx): MenuEmbed = discord.Embed(colour=discord.Colour.dark_green()) MenuEmbed.set_author(name="Tavern Menu") for drink_name in alcoholic_drinks: item_data = db.get_usable(game.hash_string(drink_name)) MenuEmbed.add_field( name= f"{self.get_discord_emoji(db.get_graphic(drink_name)[1])} **{drink_name}**", value= f"`TRG` {stats_target[item_data[1]-6]} \n `AMT` {item_data[2]}" ) MenuEmbed.set_footer( text="Karl also offers free water every 30m using .drink") await ctx.message.channel.send(embed=MenuEmbed)
async def complete_reset(ctx): now = datetime.datetime.now() user = ctx.message.author db.update_character( character.generate_character(user.id, user.display_name, "swordsmen", game.hash_string("stone sword"), 0)) db.update_user( (user.id, now - datetime.timedelta(days=1), now - datetime.timedelta(days=7), now.date(), "", 0, 0)) db.clear_inventory(user.id) db.update_bank(user.id, 200) await ctx.message.channel.send("account completely cleared")
async def drink(ctx): user = ctx.message.author timer_data = db.get_timer(user.id, "drink") if timer_data is not None: dif = datetime.datetime.now() - timer_data[2] if dif.seconds < 1800: await ctx.message.channel.send( f"{str(datetime.timedelta(seconds=1800-int(dif.total_seconds())))} left" ) return else: db.update_timer(user.id, "drink", datetime.datetime.now()) else: db.add_timer(user.id, "drink", datetime.datetime.now()) db.add_item(user.id, game.hash_string("water"), 1) await ctx.message.channel.send( f"{user.mention} here's your water {self.get_discord_emoji(db.get_graphic('water')[1])}" )
async def travel(ctx): user = ctx.message.author target_location = ctx.message.content[8:].title() location_ids = { "First Floor": id["role"]["First Floor"], "Second Floor": id["role"]["Second Floor"], "Third Floor": id["role"]["Third Floor"] } if target_location == "": TravelEmbed = discord.Embed(colour=discord.Colour.orange()) TravelEmbed.set_author(name="Travel Locations") for location_name in location_ids: TravelEmbed.add_field(name=f"**{location_name}**", value="`COST` transportation ticket", inline=False) await ctx.message.channel.send(embed=TravelEmbed) return if "transportation ticket" not in db.get_inventory( user.id)[0].keys(): await ctx.message.channel.send( "you need transportation to travel") return if target_location not in location_ids.keys(): await ctx.message.channel.send( f"{target_location} is not a valid location") return if db.get_character(user.id)[4] < 40: await ctx.message.channel.send( f"you need to be at least level {40} to travel") return member = await self.guild.fetch_member(user.id) for role in member.roles: if role.id in location_ids.values(): if role.id == location_ids[target_location]: await ctx.message.channel.send( f"you are already at {target_location}") return await member.remove_roles(role) await member.add_roles( self.guild.get_role(id["role"][target_location])) db.add_item(user.id, game.hash_string("transportation ticket"), -1) await ctx.message.channel.send( f"{user.mention} has been transported to {target_location}")
async def change(ctx): user = ctx.message.author target_class = ctx.message.content[8:].title() if db.get_class(target_class) is None: await ctx.message.channel.send( f"{target_class} is not a valid class") return if "test seal" not in db.get_inventory(user.id)[0].keys(): await ctx.message.channel.send( "you need a test seal to change classes") return character_data = list(db.get_character(user.id)) if target_class in character.intermediate_classes and character_data[ 4] < 20: await ctx.message.channel.send( f"you need to be at least level 20 to changed to {target_class}" ) elif target_class in character.advanced_classes and character_data[ 4] < 40: await ctx.message.channel.send( f"you need to be at least level 40 to changed to {target_class}" ) elif character.change_class(character_data, target_class): character_data[3] = target_class db.update_character(character_data) db.add_item(user.id, game.hash_string("test seal"), -1) await ctx.message.channel.send( f"{character_data[1]}'s class has been changed to {target_class}" ) else: requirements = character.class_requirement(target_class) requirement_str = "" for num in range(len(requirements)): requirement_str += f"{int(requirements[num][1])} for {stats_target[requirements[num][0]+2]}" if num != 0: requirement_str += " or " await ctx.message.channel.send( f"{character_data[1]} doesn't meet the requirement for {target_class}, class requirements: {requirement_str}" )
def generate_enemy(name,level): #used the 0 at the start as placement for the message id weapon_type = random.choice(list(class_road_map.keys())) num_classes = min(int(level/20)+1,len(class_road_map[weapon_type])) classes = class_road_map[weapon_type][:num_classes] for num in range(len(classes)): classes[num] = random.choice(classes[num].split("-")) weapon_thing = generate_class_weapon(classes[-1],level) weapon_id = game.hash_string(weapon_thing) current_level = 0 enemy_data = [0, name, weapon_id, classes[-1], level, 0, 0, 3, 1, 1, 1, 1, 1,generate_enemy_loot(level),""] for class_name in classes: growth_rates = db.get_class(class_name)[1].split("-") for x in range(20): if current_level == level: break current_level+=1 for num in range(len(growth_rates)): if rng(float(growth_rates[num])): enemy_data[7+num]+=1 enemy_data[6] = enemy_data[7] return enemy_data
async def god_mode(ctx): now = datetime.datetime.now() user = ctx.message.author db.update_character( (user.id, user.display_name, game.hash_string("stone sword"), "swordsmen", 100, 0, 100, 100, 100, 100, 100, 100, 100))