diff options
Diffstat (limited to 'cogs/adv_inc')
-rw-r--r-- | cogs/adv_inc/AdventurersInc.py | 107 | ||||
-rw-r--r-- | cogs/adv_inc/Calculate.py | 52 | ||||
-rw-r--r-- | cogs/adv_inc/Combat.py | 167 | ||||
-rw-r--r-- | cogs/adv_inc/Enemy.py | 82 | ||||
-rw-r--r-- | cogs/adv_inc/Items.py | 245 | ||||
-rw-r--r-- | cogs/adv_inc/LevelUp.py | 41 | ||||
-rw-r--r-- | cogs/adv_inc/PlayerCreate.py | 65 | ||||
-rw-r--r-- | cogs/adv_inc/PlayerDeath.py | 41 | ||||
-rw-r--r-- | cogs/adv_inc/PlayerStats.py | 79 | ||||
-rw-r--r-- | cogs/adv_inc/Resting.py | 204 | ||||
-rw-r--r-- | cogs/adv_inc/__init__.py | 0 |
11 files changed, 1083 insertions, 0 deletions
diff --git a/cogs/adv_inc/AdventurersInc.py b/cogs/adv_inc/AdventurersInc.py new file mode 100644 index 0000000..f47bd5e --- /dev/null +++ b/cogs/adv_inc/AdventurersInc.py @@ -0,0 +1,107 @@ +import configparser +import pymysql +from discord.ext import commands +import discord +import importlib +import utils + +from cogs.adv_inc import PlayerStats +from cogs.adv_inc import PlayerCreate +from cogs.adv_inc import LevelUp +from cogs.adv_inc import Resting +from cogs.adv_inc import Combat + +importlib.reload(utils) +importlib.reload(PlayerStats) +importlib.reload(PlayerCreate) +importlib.reload(LevelUp) +importlib.reload(Resting) +importlib.reload(Combat) + + +class AdventurersInc(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def a(self, ctx, *arg): + if "adventurers-inc" in str(ctx.channel): + # Variables + str_input_group = ctx.message.content.split(" ") + try: + str_cmd1 = ctx.message.content.split(" ")[1] + except: + str_cmd1 = "" + try: + str_cmd2 = ctx.message.content.split(" ")[2] + except: + str_cmd2 = "" + + # config = configparser.ConfigParser() + # config.read(r'config.ini') + # pgloader mysql://adventure:egg@lexicade.uk:3306/AdventurersInc postgresql://Lexicade:LetMeIn123@localhost:5432/AdventurersInc + # str_player_state = "debug" + # params = {'LiveDB': 'AdventurersInc', + # 'LiveVersion': '1.0', + # 'GameVersion': '1.3.1', + # 'Nick': ctx.author.id, + # "db": '5.135.189.226', + # 'dbuser': 'adventure', + # 'dbpass': 'egg', + # 'cmd1': str_cmd1, + # 'cmd2': str_cmd2, + # 'msg': ctx.message.content[3:]} + params = {'game_version': '1.4', + 'nick': ctx.author.id, + 'ctx': ctx, + 'cmd1': str_cmd1, + 'cmd2': str_cmd2, + 'msg': ctx.message.content[3:]} + + player_stats = await PlayerStats.refresh_stats(params) + # print(player_stats) + + str_output = 'Oh hi there... \\_(:oćā )\\_' + # Global Commands + if str_cmd1 == "git": + str_output = "Adventurers Inc - git: http://www.blatech.co.uk/JasonFS/Artifact-v2" + elif str_cmd1 == "version": + str_output = "Adventurers Inc - alpha 0.1" + else: + # Actions based on player state + if player_stats is None: + print("OH GOD NO") + str_output = await PlayerCreate.pick_character_clan(params) + + elif player_stats["player_state"] == "creation_name": + str_output = await PlayerCreate.pick_character_name(params, player_stats) + + elif player_stats["player_state"] == "creation_race": + str_output = await PlayerCreate.pick_character_race(params, player_stats) + + elif player_stats["player_state"] == "rest" and player_stats['attribute_points'] > 0: + str_output = await LevelUp.level_up_attributes(params) + + elif player_stats["player_state"] == "rest" and player_stats['attribute_points'] == 0: + str_output = await Resting.player_resting(params, player_stats) + + elif player_stats["player_state"] == "combat": + str_output = await Combat.player_in_combat(params) + + if str_output is not None: + if type(str_output) == str or type(str_output) == dict: + await ctx.send(content=f"{ctx.author.mention}: {str_output}") + else: + await ctx.send(content=f"{ctx.author.mention}", embed=str_output) + else: + await ctx.send(content=f"Wrong channel {ctx.channel}") + + +def setup(bot): + print("INFO: Loading [Adventurers Inc]... ", end="") + bot.add_cog(AdventurersInc(bot)) + print("Done!") + + +def teardown(bot): + print("INFO: Unloading [Adventurers Inc]") diff --git a/cogs/adv_inc/Calculate.py b/cogs/adv_inc/Calculate.py new file mode 100644 index 0000000..b6861ca --- /dev/null +++ b/cogs/adv_inc/Calculate.py @@ -0,0 +1,52 @@ +import math +import random + + +async def get_dodge_chance(dexterity, dodge, coefficient=110): + system_percentage = (dodge + (dexterity / 3)) / ((dodge+(dexterity / 3)) + coefficient) + return system_percentage + + +async def get_block_chance(strength, block, coefficient=30): + strength_bonus = 0 if strength < 17 else math.floor((strength-17) / 3) + system_percentage = (block + (strength_bonus / 3)) / ((block + (strength_bonus / 3)) + coefficient) + return system_percentage + + +async def get_luck_chance(luck, coefficient=50): + luck_rolls = round((luck / (luck + coefficient)) * 15, 0) + return int(luck_rolls) + + +async def get_attack_power(strength, dexterity): + str_bonus = strength * 1 + dex_bonus = math.floor(dexterity / 2) + attack_power = random.uniform((str_bonus + dex_bonus) * 1.1, (str_bonus + dex_bonus) * 0.9) + return math.floor(attack_power) + + +async def get_hit_chance(dexterity, accuracy, coefficient=50): + system_percentage = (accuracy + (dexterity / 3)) / ((accuracy + (dexterity / 3)) + coefficient) + return system_percentage + + +async def get_max_life(strength, constitution): + str_bonus = math.floor(strength / 3) + con_bonus = constitution * 2 + max_life = con_bonus + str_bonus + return math.floor(max_life) + + +async def get_armour_percentage(armour, strength, constitution, coefficient=80): + strength_bonus = 0 if strength < 20 else math.floor((strength-16) / 4) + constitution_bonus = 0 if constitution < 20 else math.floor((constitution-16) / 4) + armour_bonus = armour * 3 + armour_perc = (strength_bonus + constitution_bonus + armour_bonus / 3) / ((strength_bonus + constitution_bonus + armour_bonus / 3) + coefficient) + return round(armour_perc, 2) + + +async def get_crit_percentage(dexterity, critical, coefficient=100): + critical = critical * 2 + dexterity_bonus = math.floor(dexterity / 3) + critical_chance = (critical + dexterity_bonus / 3) / ((critical + dexterity_bonus / 3) + coefficient) + return round(critical_chance, 2) diff --git a/cogs/adv_inc/Combat.py b/cogs/adv_inc/Combat.py new file mode 100644 index 0000000..578ff31 --- /dev/null +++ b/cogs/adv_inc/Combat.py @@ -0,0 +1,167 @@ +import pymysql +import math +import re +import sys +import random +import os +import importlib +import utils + +from cogs.adv_inc import PlayerStats +from cogs.adv_inc import Items +from cogs.adv_inc import Enemy +from cogs.adv_inc import PlayerDeath +from cogs.adv_inc import Calculate + +importlib.reload(utils) +importlib.reload(PlayerStats) +importlib.reload(Items) +importlib.reload(Enemy) +importlib.reload(PlayerDeath) +importlib.reload(Calculate) + + +async def player_in_combat(params): + player_stats = await PlayerStats.refresh_stats(params) + enemy_stats = await Enemy.get_enemy_stats(params) + if enemy_stats is None: + str_output = "Combat error, returning to camp." + await utils.sql_postgres('CALL adventurersinc.del_player_enemies(%s)', (params['nick'],), False) + await utils.sql_postgres('CALL adventurersinc.set_player_state(%s, %s)', (params['nick'], 'rest',), False) + return str_output + + str_attack_log = '' + + # Attack + if params['cmd1'] == 'a' or params['cmd1'] == 'attack': + # Players attack + str_attack_log = str_attack_log + await perform_attack(player_stats, enemy_stats, params) + + if enemy_stats['hp'] <= 0: + str_attack_log = str_attack_log + f"The {enemy_stats['enemy_name']} falls to the floor. " + + # Generate equipment item + if random.randint(1, 2) == 1 and enemy_stats['enemy_class'] == 'normal': + + # Generate Shard of Chaos on Chaos kill + if enemy_stats['unlock'] == 'chaos': + await utils.sql_postgres(f"CALL adventurersinc.add_shard_of_chaos(%s)", (params["nick"],), False) + return "You acquire a Shard of Chaos from the remains of the enemy." + + # Generate normal equipment drop + elif enemy_stats['unlock'] == 'default': + # Equipment Drop Rarity:Element:Item:Enchantment:Fabled + item_gen = await Items.generate_equipment(params, '0:0:0:0:0') + str_attack_log = str_attack_log + f"You obtained a {item_gen['equipment_colour']} {item_gen['equipment_name']}. " + await Items.add_to_inventory(params, item_gen) + + # Generate gold drop + if random.randint(1, 1) == 1: + await utils.sql_postgres("CALL adventurersinc.set_player_exit_combat(%s, %s)", (enemy_stats['gold_carried'], params["nick"],), False) + str_attack_log = str_attack_log + f"You found {enemy_stats['gold_carried']} gold. " + + await utils.sql_postgres("CALL adventurersinc.del_player_enemies(%s)", (params["nick"],), False) + + # Attempt to restock shop + if random.randint(1, 2) == 1: + str_attack_log = str_attack_log + "A new travelling merchant has arrived. " + await utils.sql_postgres("CALL adventurersinc.del_player_shop(%s)", (params["nick"],), False) + + for i in range(1, (random.randint(3, 5) + 1)): + await Items.add_to_shop(params, await Items.generate_equipment(params, '0:0:0:0:1')) + + # # Unlock boss items + # if enemy_stats['unlock'] is not 'default' and enemy_stats['enemy_class'] is 'boss': + # await utils.sql_postgres("", (params['nick'], enemy_stats['Unlock'],), True) + # sql_unlock_check = c.fetchone() + # if str(sql_unlock_check['requirement']) == '0': + # Items.unlock_items(params, str(enemy_stats['unlock'])) + # return "Additional items will now begin appearing" + + player_stats = await PlayerStats.refresh_stats(params) + if float(player_stats['challenge_rating']).is_integer(): + int_attribute_points = 2 + int(player_stats["challenge_rating"]) + await utils.sql_postgres("CALL adventurersinc.set_player_attribute_points(%s, %s)", (int_attribute_points, params["nick"],), False) + str_attack_log = str_attack_log + f"You have gained {int_attribute_points} attribute points. " + else: + # Enemy attack + str_attack_log = str_attack_log + await perform_attack(enemy_stats, player_stats, params) + + if player_stats['hp'] <= 0: + str_attack_log = f"{str_attack_log}. You died. (http://adventurersinc.lelong.uk/graveyard/)" + await PlayerDeath.character_death(player_stats, params) + + return "" + str_attack_log + + # flee + elif params['cmd1'].lower() == 'f' or params['cmd1'].lower() == 'flee': + if random.randint(1, 2) == 1: + return await flee_combat(params) + else: + str_output = f"You failed to escape. {await perform_attack(enemy_stats, player_stats, params)}" + if player_stats['hp'] <= 0: + str_output = f"{str_output}. You were struck down as you attempted to flee. You died. (http://adventurersinc.lelong.uk/graveyard/)" + await PlayerDeath.character_death(player_stats, params) + return str_output + + # Admin commands + elif params['cmd1'].lower() == 'admin' and input.admin: + return perform_attack(player_stats, enemy_stats, params["nick"]) + else: + return "Available commands: (a)ttack, (f)lee" + + +async def perform_attack(attacker_stats, defender_stats, params): + # Check if the defender dodges + dodge_perc = await Calculate.get_dodge_chance(int(defender_stats['dexterity']), int(defender_stats['dodge'])) + if random.randint(0, 100) < math.floor(dodge_perc * 100): + if attacker_stats['unit_type'] == 'player': + return "You miss. " + elif attacker_stats['unit_type'] == 'enemy': + return f"You dodge the {attacker_stats['enemy_name']}'s attack. " + + # Check if the defender blocks + block_perc = await Calculate.get_block_chance(defender_stats['strength'], defender_stats['block']) + if random.randint(0, 100) < math.floor(block_perc * 100): + if attacker_stats['unit_type'] == 'player': + return "The enemy blocks your attack. " + elif attacker_stats['unit_type'] == 'enemy': + return f"You block the {attacker_stats['enemy_name']}'s attack. " + + # Generate combat values + int_attack_damage = await Calculate.get_attack_power(attacker_stats['strength'], attacker_stats['dexterity']) + int_armour_perc = await Calculate.get_armour_percentage(attacker_stats['armour'], attacker_stats['strength'], attacker_stats['constitution']) + int_crit_chance = await Calculate.get_crit_percentage(attacker_stats['crit'], attacker_stats['dexterity']) + int_final_damage = int_attack_damage - (int_attack_damage * int_armour_perc) + + # Determine if the attacker is going to crit + if random.randint(0, 100) < (int_crit_chance * 100): + int_final_damage = int_final_damage * 2 + str_crit = '**CRIT**' + else: + str_crit = 'did' + + # Round this up to avoid decimals + int_final_damage = math.ceil(int_final_damage) + + # Update defender health + defender_stats['hp'] = defender_stats['hp'] - int_final_damage + + # Update HP of the appropriate unit_type + await utils.sql_postgres(f"CALL adventurersinc.set_{str(defender_stats['unit_type'])}_health(%s, %s);", (int(defender_stats['hp']), int(params['nick']),), False) + + # Assemble hit message + if attacker_stats['unit_type'] == 'player': + return f"You {str_crit} {int_final_damage} damage. " + elif attacker_stats['unit_type'] == 'enemy': + return f"The {attacker_stats['enemy_name']} {str_crit} {int_final_damage} damage. " + + +async def flee_combat(params): + # Delete players opponent + await utils.sql_postgres("CALL adventurersinc.del_player_enemies(%s);", (params['nick'],), False) + + # Update player record for player + await utils.sql_postgres("CALL adventurersinc.set_player_state(%s,%s)", (params['nick'], 'rest',), False) + + return "You flee your enemy." diff --git a/cogs/adv_inc/Enemy.py b/cogs/adv_inc/Enemy.py new file mode 100644 index 0000000..f5f76e6 --- /dev/null +++ b/cogs/adv_inc/Enemy.py @@ -0,0 +1,82 @@ +import pymysql +import math +import random +import importlib +import utils + +importlib.reload(utils) + + +async def create_enemy(enemy_stats, player_stats, params): + # Update player state for combat + await utils.sql_postgres("CALL adventurersinc.set_playerstate_combat(%s)", (params['nick'],), False) + + # If challenge_rating is an INT we'll swap for a boss + if player_stats['challenge_rating'] == int(math.ceil(player_stats['challenge_rating'] / 4) * 4): + str_class = "boss" + else: + str_class = "normal" + + # Get enemy weighting list + all_enemies = await utils.sql_postgres(f"SELECT adventurersinc.get_all_enemies(%s)", (str_class,), True) + int_total_weight = random.randint(1, all_enemies[0][0]['total_weight']) + + # Apply challenge rating modifier to enemy + int_challenge_modifier = player_stats['challenge_rating'] / 2 + + for enemy in all_enemies: + int_total_weight = int_total_weight - enemy[0]['enemy_weight'] + if int_total_weight <= 0: + # Set stats + enemy[0]['enemy_colour'] = enemy[0]['enemy_colour'] + enemy[0]['enemy_name'] = str(enemy[0]['enemy_name']) + enemy[0]['enemy_class'] = str(enemy[0]['enemy_class']) + enemy[0]['unlock'] = str(enemy[0]['unlock']) + enemy[0]['hp'] = math.floor(enemy[0]['hp'] * int_challenge_modifier) + enemy[0]['enemy_weight'] = math.floor(enemy[0]['enemy_weight'] * int_challenge_modifier) + enemy[0]['challenge_rating'] = math.floor(enemy[0]['challenge_rating'] * int_challenge_modifier) + enemy[0]['gold_carried'] = math.floor(enemy[0]['gold_carried'] * int_challenge_modifier) + enemy[0]['strength'] = math.floor(enemy[0]['strength'] * int_challenge_modifier) + enemy[0]['dexterity'] = math.floor(enemy[0]['dexterity'] * int_challenge_modifier) + enemy[0]['constitution'] = math.floor(enemy[0]['constitution'] * int_challenge_modifier) + enemy[0]['intelligence'] = math.floor(enemy[0]['intelligence'] * int_challenge_modifier) + enemy[0]['dodge'] = math.floor(enemy[0]['dodge'] * int_challenge_modifier) + enemy[0]['crit'] = math.floor(enemy[0]['crit'] * int_challenge_modifier) + enemy[0]['accuracy'] = math.floor(enemy[0]['accuracy'] * int_challenge_modifier) + enemy[0]['resistance'] = math.floor(enemy[0]['resistance'] * int_challenge_modifier) + enemy[0]['luck'] = math.floor(enemy[0]['luck'] * int_challenge_modifier) + enemy[0]['block'] = math.floor(enemy[0]['block'] * int_challenge_modifier) + break + + await utils.sql_postgres("CALL adventurersinc.add_player_enemy(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", + (params['nick'], enemy[0]['enemy_colour'], enemy[0]['enemy_name'], enemy[0]['enemy_class'], enemy[0]['unlock'], enemy[0]['hp'], enemy[0]['enemy_weight'],enemy[0]['challenge_rating'], enemy[0]['gold_carried'], + enemy[0]['strength'], enemy[0]['dexterity'], enemy[0]['constitution'], enemy[0]['intelligence'], enemy[0]['dodge'], enemy[0]['crit'], enemy[0]['accuracy'], enemy[0]['resistance'], enemy[0]['luck'], enemy[0]['block'],), False) + + return enemy[0] + + +async def get_enemy_stats(params): + enemy = await utils.sql_postgres("SELECT adventurersinc.get_player_enemy(%s)", (params['nick'],), True) + if enemy[0][0] is None: + return None + + enemy[0][0]['enemy_colour'] = enemy[0][0]['enemy_colour'] + enemy[0][0]['enemy_name'] = enemy[0][0]['enemy_name'] + enemy[0][0]['enemy_class'] = enemy[0][0]['enemy_class'] + enemy[0][0]['unlock'] = enemy[0][0]['unlock'] + enemy[0][0]['hp'] = enemy[0][0]['hp'] + enemy[0][0]['gold_carried'] = enemy[0][0]['gold_carried'] + enemy[0][0]['strength'] = enemy[0][0]['strength'] + enemy[0][0]['dexterity'] = enemy[0][0]['dexterity'] + enemy[0][0]['constitution'] = enemy[0][0]['constitution'] + enemy[0][0]['intelligence'] = enemy[0][0]['intelligence'] + enemy[0][0]['dodge'] = enemy[0][0]['dodge'] + enemy[0][0]['crit'] = enemy[0][0]['crit'] + enemy[0][0]['accuracy'] = enemy[0][0]['accuracy'] + enemy[0][0]['resistance'] = enemy[0][0]['resistance'] + enemy[0][0]['luck'] = enemy[0][0]['luck'] + enemy[0][0]['block'] = enemy[0][0]['block'] + enemy[0][0]['armour'] = 0 + enemy[0][0]['unit_type'] = 'enemy' + + return enemy[0][0] diff --git a/cogs/adv_inc/Items.py b/cogs/adv_inc/Items.py new file mode 100644 index 0000000..52cc38f --- /dev/null +++ b/cogs/adv_inc/Items.py @@ -0,0 +1,245 @@ +import pymysql +import random +import math +import importlib +import utils + +import codecs +import unicodedata + +importlib.reload(utils) + + +async def generate_equipment(params, item_code): + # int_iteration = 0 + # item_name = str_rarity_spacing = '' + item_code = item_code.split(':') + + # for i in range(len(item_code)): + # if str(i).isdigit(): + # i = i + # else: + # i = random.choice(i.split(',')) + + # Generate Rarity + item_gen_rarity = await create_equipment_rarity(item_code[0]) + + # Generate Item + item_gen_equipment = await create_equipment_name(item_code[1]) + + # Generate Enchantment (Uncommon or greater) + item_gen_enchantment = await create_equipment_enchantment(item_code[2], item_gen_rarity['rarity_id']) + + # Generate Element (Rare or greater) + item_gen_element = await create_equipment_element(item_code[3], item_gen_rarity['rarity_id']) + + # Attempt creating an Artifact + item_gen_equipment = await create_equipment_artifact(params, item_code[4], item_gen_equipment) + + # print(type(item_gen_element), item_gen_equipment['permanent'], (("" if item_gen_equipment['permanent'] == 0 else "Fabled ") + + # f"{item_gen_rarity['rarity_name']}" + + # ("" if len(item_gen_rarity['rarity_name']) == 0 else " ") + + # ("" if item_gen_element is None else item_gen_element['element_name'] + " ") + + # f"{item_gen_equipment['equipment_name']} " + + # ("" if item_gen_enchantment is None else item_gen_enchantment['enchant_name'])).strip()) + + item_gen = {'equipment_colour': item_gen_rarity['rarity_colour'], + 'equipment_name': (("" if item_gen_equipment['permanent'] == 0 else "Fabled ") + + f"{item_gen_rarity['rarity_name']}" + + ("" if len(item_gen_rarity['rarity_name']) == 0 else " ") + + ("" if item_gen_element is None else item_gen_element['element_name'] + " ") + + f"{item_gen_equipment['equipment_name']} " + + ("" if item_gen_enchantment is None else item_gen_enchantment['enchant_name'])).strip(), + 'equipment_slot': item_gen_equipment['equipment_slot'], + 'equipment_type': item_gen_equipment['equipment_type'], + 'hands_req': item_gen_equipment['hands_req'], + 'strength': math.floor((item_gen_equipment['strength'] + (0 if item_gen_enchantment is None else item_gen_enchantment['strength']) + + (0 if item_gen_element is None else item_gen_element['strength'])) * item_gen_rarity['rarity_modifier']), + 'dexterity': math.floor((item_gen_equipment['dexterity'] + (0 if item_gen_enchantment is None else item_gen_enchantment['dexterity']) + + (0 if item_gen_element is None else item_gen_element['dexterity'])) * item_gen_rarity['rarity_modifier']), + 'constitution': math.floor((item_gen_equipment['constitution'] + (0 if item_gen_enchantment is None else item_gen_enchantment['constitution']) + + (0 if item_gen_element is None else item_gen_element['constitution'])) * item_gen_rarity['rarity_modifier']), + 'intelligence': math.floor((item_gen_equipment['intelligence'] + (0 if item_gen_enchantment is None else item_gen_enchantment['intelligence']) + + (0 if item_gen_element is None else item_gen_element['intelligence'])) * item_gen_rarity['rarity_modifier']), + 'dodge': math.floor((item_gen_equipment['dodge'] + (0 if item_gen_enchantment is None else item_gen_enchantment['dodge']) + + (0 if item_gen_element is None else item_gen_element['dodge'])) * item_gen_rarity['rarity_modifier']), + 'crit': math.floor((item_gen_equipment['crit'] + (0 if item_gen_enchantment is None else item_gen_enchantment['crit']) + + (0 if item_gen_element is None else item_gen_element['crit'])) * item_gen_rarity['rarity_modifier']), + 'armour': math.floor((item_gen_equipment['armour'] + (0 if item_gen_enchantment is None else item_gen_enchantment['armour']) + + (0 if item_gen_element is None else item_gen_element['armour'])) * item_gen_rarity['rarity_modifier']), + 'accuracy': math.floor((item_gen_equipment['accuracy'] + (0 if item_gen_enchantment is None else item_gen_enchantment['accuracy']) + + (0 if item_gen_element is None else item_gen_element['accuracy'])) * item_gen_rarity['rarity_modifier']), + 'resistance': math.floor((item_gen_equipment['resistance'] + (0 if item_gen_enchantment is None else item_gen_enchantment['resistance']) + + (0 if item_gen_element is None else item_gen_element['resistance'])) * item_gen_rarity['rarity_modifier']), + 'luck': math.floor((item_gen_equipment['luck'] + (0 if item_gen_enchantment is None else item_gen_enchantment['luck']) + + (0 if item_gen_element is None else item_gen_element['luck'])) * item_gen_rarity['rarity_modifier']), + 'block': math.floor((item_gen_equipment['block'] + (0 if item_gen_enchantment is None else item_gen_enchantment['block']) + + (0 if item_gen_element is None else item_gen_element['block'])) * item_gen_rarity['rarity_modifier']), + 'permanent': item_gen_equipment['permanent'], + 'cost': math.floor(item_gen_equipment['item_cost'] + (0 if item_gen_element is None else item_gen_element['element_cost']) + + (0 if item_gen_enchantment is None else item_gen_enchantment['enchant_cost']) + + (0 if item_gen_rarity is None else item_gen_rarity['rarity_cost']))} + + return item_gen + + +async def create_equipment_name(item_code): + # If item_code is specified, find the base item and return. + if int(item_code) != 0: + base_item = await utils.sql_postgres("SELECT AdventurersInc.get_item_equipment(%s)", (item_code,), True) + + # If item_code is 0, roll the standard random generation + else: + base_item = await utils.sql_postgres("SELECT AdventurersInc.get_item_equipment(%s)", ('%',), True) + + return base_item[0][0] + + +async def create_equipment_element(item_code, rarity_id): + # Get a random element from the given item_code + if int(item_code) != 0: + element = await utils.sql_postgres("SELECT AdventurersInc.get_item_elements(%s)", (item_code,), True) + return element[0][0] + + # Roll for a random enchant for any item Rare or greater + else: + if rarity_id >= 4 and random.randint(1, 3) == 1: + element = await utils.sql_postgres("SELECT AdventurersInc.get_item_elements(%s)", ('%',), True) + return element[0][0] + + +async def create_equipment_rarity(item_code): + # If item_code is specified, find the rarity and return. + if int(item_code) != 0: + # item_code = 1 if item_code <= 0 or item_code >= 7 else item_code + rarity = await utils.sql_postgres("SELECT AdventurersInc.get_item_rarities(%s)", (item_code,), True) + return rarity[0][0] + + # If item_code is 0, roll the standard random generation + elif int(item_code) == 0: + # Get all rarities + base_rarities = await utils.sql_postgres("SELECT AdventurersInc.get_item_rarities(%s)", ('%',), True) + + # Get the dice roll for this random generation cycle + rarity_dice_roll = random.randint(1, base_rarities[0][0]["total_weight"]) + + # Determine the rarity + for rarity in base_rarities: + rarity_dice_roll = rarity_dice_roll - rarity[0]["rarity_weight"] + if rarity_dice_roll <= 0: + return rarity[0] + + +async def create_equipment_enchantment(item_code, rarity_id): + # Get a random enchant from the given item_code + if int(item_code) != 0: + enchant = await utils.sql_postgres("SELECT adventurersinc.get_item_enchantment(%s)", (item_code,), True) + return enchant[0][0] + + # Roll for a random enchant for any item Uncommon or greater + else: + if rarity_id >= 3 and random.randint(1, 3) == 1: + enchant = await utils.sql_postgres("SELECT adventurersinc.get_item_enchantment(%s)", ('%',), True) + return enchant[0][0] + + +async def create_equipment_artifact(params, item_code, item_gen_equipment): + # Gen for Artifact item: + player_fabled = await utils.sql_postgres("SELECT adventurersinc.get_player_artifact_count(%s);", (params['nick'],), True) + + # 0 - Will attempt to add an artifact randomly and not exceed the standard limit + if player_fabled[0][0]['perm_can_drop']: + if random.randint(1, 100) == 1 and int(item_code) == 0: + item_gen_equipment['permanent'] = 1 + + # 1 - Will not generate item as an artifact + elif int(item_code) == 1: + item_gen_equipment['permanent'] = 0 + + else: + item_gen_equipment['permanent'] = 0 + + # 2 - Will force the item to become an artifact and exceed the limit of 2 artifacts + elif int(item_code) == 2: + item_gen_equipment['permanent'] = 1 + + return item_gen_equipment + + +# def create_item(enemy_stats, player_stats, params): +# # Get random element +# c.execute("SELECT loot_name,ItemType,Potency FROM GenLoot WHERE Locked=0 ORDER BY RAND() LIMIT 1") +# sql_rarity = c.fetchone() +# str_loot_name = sql_rarity['loot_name'] +# str_item_type = sql_rarity['ItemType'] +# int_potency = sql_rarity['Potency'] +# +# if str_item_type == 'Quantity': +# int_potency = enemy_stats['GoldCarried'] + int(random.uniform(float(enemy_stats['GoldCarried']) * -0.3, float(enemy_stats['GoldCarried']) * 0.3)) +# +# return str_loot_name, int_potency + + +async def add_to_shop(params, item): + sql = 'CALL adventurersinc.add_to_player_shop(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)' + params = (params['nick'], item['cost'], item['equipment_colour'], item['equipment_name'], item['equipment_slot'], + item['equipment_type'], bool(item['permanent']), item['hands_req'], item['strength'], item['dexterity'], + item['constitution'], item['intelligence'], item['dodge'], item['crit'], item['armour'], + item['accuracy'], item['resistance'], item['luck'], item['block'],) + await utils.sql_postgres(sql, params, False) + return + + +async def add_to_inventory(params, item): + sql = 'CALL adventurersinc.add_to_player_inventory(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)' + params = (item['equipment_colour'], item['equipment_name'], item['equipment_slot'], item['equipment_type'], bool(item['permanent']), item['hands_req'], + item['strength'], item['dexterity'], item['constitution'], item['intelligence'], item['dodge'], item['crit'], + item['armour'], item['accuracy'], item['resistance'], item['luck'], item['block'], params['nick']) + await utils.sql_postgres(sql, params, False) + return + + +def merge_item_codes(item_code1, item_code2): + str_output = "" + item_code1 = item_code1.split(':') + item_code2 = item_code2.split(':') + + for i in range(len(item_code1)): + if str(item_code1[i]) == "0" or str(item_code2[i]) == "0": + str_output = str_output + str(int(item_code1[i]) + int(item_code2[i])) + else: + str_output = str_output + random.choice([item_code1[i], item_code2[i]]) + + return str_output + + +# def unlock_items(params, unlocked_set): +# c_select.execute("SELECT equipment_name, equipment_slot, equipment_type, hands_req, Locked, strength, dexterity, constitution, intelligence, dodge, crit, armour, Requirement FROM base_items WHERE Requirement=%s", (unlocked_set,)) +# while sql_item is not None: +# c_insert.execute("INSERT INTO Items_PlayerPool(equipment_name,Nick) VALUES (%s,%s)",(sql_item['equipment_name'], params['Nick'],));db.commit(); +# return "Updated." + + +async def item_test(): + params = {'nick': 182588470135488512} + item_code = '0:0:0:0:0' + max_loops = 100 + totals = {'Ruined': 0, 'Normal': 0, 'Uncommon': 0, 'Rare': 0, 'Epic': 0, 'Legendary': 0 } + for loop in range(1, max_loops): + item = await generate_equipment(params, item_code) + if item['permanent'] == 1: + if item['equipment_colour'] == 'ā«': + rarity = 'Ruined' + elif item['equipment_colour'] == 'āŖ': + rarity = 'Normal' + elif item['equipment_colour'] == 'š¢': + rarity = 'Uncommon' + elif item['equipment_colour'] == 'šµ': + rarity = 'Rare' + elif item['equipment_colour'] == 'š£': + rarity = 'Epic' + elif item['equipment_colour'] == 'š ': + rarity = 'Legendary' + + totals[rarity] = totals[rarity] + 1 + return totals diff --git a/cogs/adv_inc/LevelUp.py b/cogs/adv_inc/LevelUp.py new file mode 100644 index 0000000..b6b73b6 --- /dev/null +++ b/cogs/adv_inc/LevelUp.py @@ -0,0 +1,41 @@ +import pymysql +import sys +import os +import importlib +import utils + +from cogs.adv_inc import PlayerStats + +importlib.reload(PlayerStats) + + +async def level_up_attributes(params): + # In the event no valid value is given, assume the points to assign will be 1 + try: + params['cmd2'] = int(params['cmd2']) + except ValueError: + params['cmd2'] = 1 + + # Get players attribute points + player_attribute_points = await utils.sql_postgres("SELECT adventurersinc.get_player_attribute_points(%s);", (params["nick"],), True) + + # Prevent over-allocation + if int(params['cmd2']) > player_attribute_points[0][0]['attribute_points']: + return "You cannot apply more points than you have." + + # Attribute allocation + else: + if params['cmd1'].lower() == 's': + await utils.sql_postgres("CALL adventurersinc.set_player_attribute_strength(%s, %s)", (params['cmd2'], params["nick"],), False) + elif params['cmd1'].lower() == 'd': + await utils.sql_postgres("CALL adventurersinc.set_player_attribute_dexterity(%s, %s)", (params['cmd2'], params["nick"],), False) + elif params['cmd1'].lower() == 'c': + await utils.sql_postgres("CALL adventurersinc.set_player_attribute_constitution(%s, %s)", (params['cmd2'], params["nick"],), False) + elif params['cmd1'].lower() == 'i': + await utils.sql_postgres("CALL adventurersinc.set_player_attribute_intelligence(%s, %s)", (params['cmd2'], params["nick"],), False) + + player_stats = await PlayerStats.refresh_stats(params) + + # await utils.sql_postgres("CALL adventurersinc.set_player_attribute_intelligence(%s, %s)", (int_attribute_points, params["nick"],), False) + # c.execute("UPDATE Players SET HP = %s WHERE Nick='%s';", (player_stats['MaxHP'], params["Nick"]));db.commit(); + return f"Attribute Points: {player_stats['attribute_points']} (S)tr:{player_stats['strength']} (D)ex:{player_stats['dexterity']} (C)on:{player_stats['constitution']} (I)nt:{player_stats['intelligence']}" diff --git a/cogs/adv_inc/PlayerCreate.py b/cogs/adv_inc/PlayerCreate.py new file mode 100644 index 0000000..17feae5 --- /dev/null +++ b/cogs/adv_inc/PlayerCreate.py @@ -0,0 +1,65 @@ +# Embedded file name: /home/bouncer/sassbot/modules/advinc/PlayerCreate.py +import pymysql +import importlib +import utils + +from cogs.adv_inc import PlayerStats +from cogs.adv_inc import Items + +importlib.reload(utils) +importlib.reload(PlayerStats) +importlib.reload(Items) + + +async def pick_character_clan(params): + if params['cmd1'] == '': + return 'Name your Clan.' + + elif len(params['cmd1']) < 3: + return 'Your Clan Name must be at least three characters.' + + else: + await utils.sql_postgres('CALL adventurersinc.set_player_character_new(%s,%s)', (params['nick'], params['msg'].strip(),), False) + return f"The adventure for the {params['msg'].strip()} clan begins." + + +async def pick_character_name(params, player_stats): + if params['cmd1'] == '': + return 'Give yourself a name.' + + elif len(params['cmd1']) < 3: + return 'Your name must be at least three characters.' + + else: + await utils.sql_postgres('CALL adventurersinc.set_player_character_name(%s, %s)', (params['cmd1'].strip(), params['nick'],), False) + return f"You are {params['cmd1'].strip()} {player_stats['clan_name']}. Pick a race: (H)uman, (O)rc, (E)lf, (D)warf, (L)izard" + + +async def pick_character_race(params, player_stats): + # Get chosen race + str_race_selected = None + if params['cmd1'].lower() == 'h': + str_race_selected = 'Human' + elif params['cmd1'].lower() == 'o': + str_race_selected = 'Orc' + elif params['cmd1'].lower() == 'e': + str_race_selected = 'Elf' + elif params['cmd1'].lower() == 'd': + str_race_selected = 'Dwarf' + elif params['cmd1'].lower() == 'l': + str_race_selected = 'Lizard' + else: + return 'Pick a race: (H)uman, (O)rc, (E)lf, (D)warf, (L)izard' + + if str_race_selected is not None: + race_stats = await utils.sql_postgres('SELECT adventurersinc.get_race_stats(%s)', (str_race_selected,), True) + await utils.sql_postgres('CALL adventurersinc.set_player_character_race(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', (race_stats[0][0]['strength'], + race_stats[0][0]['dexterity'], race_stats[0][0]['constitution'], race_stats[0][0]['intelligence'], race_stats[0][0]['dodge'], race_stats[0][0]['crit'], race_stats[0][0]['armour'], + race_stats[0][0]['accuracy'], race_stats[0][0]['resistance'], race_stats[0][0]['luck'], race_stats[0][0]['block'], params['nick'], str_race_selected), False) + + player_stats = await PlayerStats.refresh_stats(params) + await utils.sql_postgres("CALL adventurersinc.set_player_health(%s,%s)", (player_stats['max_hp'], params['nick'],), False) + + return f"{player_stats['character_name']} {player_stats['clan_name']} the {str_race_selected} begins their adventure" + else: + return diff --git a/cogs/adv_inc/PlayerDeath.py b/cogs/adv_inc/PlayerDeath.py new file mode 100644 index 0000000..29fc34f --- /dev/null +++ b/cogs/adv_inc/PlayerDeath.py @@ -0,0 +1,41 @@ +import time +import pymysql +import importlib +import utils + +from cogs.adv_inc import Calculate + +importlib.reload(utils) +importlib.reload(Calculate) + + +async def character_death(player_stats, params): + # Create death entry + sql = 'CALL adventurersinc.add_player_graveyard_death(%s, %s, %s, %s, %s, %s);' + query_params = (params['nick'], player_stats['character_name'], player_stats['clan_name'], player_stats["total_items"], player_stats['challenge_rating'], str(params['game_version']),) + # print(f"1 {sql % query_params}") + await utils.sql_postgres(sql, query_params, False) + + # Delete players Inventory + sql = 'CALL adventurersinc.del_player_inventory(%s);' + query_params = (params['nick'],) + # print(f"2 {sql % query_params}") + await utils.sql_postgres(sql, query_params, False) + + # Delete players opponent + sql = 'CALL adventurersinc.del_player_enemies(%s);' + query_params = (params['nick'],) + # print(f"3 {sql % query_params}") + await utils.sql_postgres(sql, query_params, False) + + # Delete players shop + sql = 'CALL adventurersinc.del_player_shop(%s);' + query_params = (params['nick'],) + # print(f"4 {sql % query_params}") + await utils.sql_postgres(sql, query_params, False) + + # Update player record for new character + lose gold on death + sql = 'CALL adventurersinc.set_player_death(%s);' + query_params = (params['nick'],) + # print(f"5 {sql % query_params}") + await utils.sql_postgres(sql, query_params, False) diff --git a/cogs/adv_inc/PlayerStats.py b/cogs/adv_inc/PlayerStats.py new file mode 100644 index 0000000..2416ff3 --- /dev/null +++ b/cogs/adv_inc/PlayerStats.py @@ -0,0 +1,79 @@ +import sys +import math +import os +import importlib +import utils + +from cogs.adv_inc import Calculate + +importlib.reload(utils) +importlib.reload(Calculate) + + +async def print_stats(params): + player_stats = await refresh_stats(params) + + dodge_perc = await Calculate.get_dodge_chance(player_stats['dexterity'], player_stats['dodge']) + luck_chance = await Calculate.get_luck_chance(player_stats['luck']) + armour_perc = await Calculate.get_armour_percentage(player_stats['armour'], player_stats['strength'], player_stats['constitution']) + crit_perc = await Calculate.get_crit_percentage(player_stats['dexterity'], player_stats['crit']) + block_perc = await Calculate.get_block_chance(player_stats['strength'], player_stats['block']) + + emb = await utils.embed(params["ctx"], f"Stats of {player_stats['character_name']} {player_stats['clan_name']}", "") + emb = await utils.field(emb, "Race", f"{player_stats['race']}", True) + emb = await utils.field(emb, "HP", f"{player_stats['hp']}/{player_stats['max_hp']}", True) + emb = await utils.field(emb, "STR", f"{player_stats['strength']}", True) + emb = await utils.field(emb, "Challenge Rating", f"{player_stats['challenge_rating']}", True) + emb = await utils.field(emb, "DEX", f"{player_stats['dexterity']}", True) + emb = await utils.field(emb, "CON", f"{player_stats['constitution']}", True) + emb = await utils.field(emb, "INT", f"{player_stats['intelligence']}", True) + emb = await utils.field(emb, "Gold", f"{player_stats['currency']}", True) + emb = await utils.field(emb, "Dodge", f"{player_stats['dodge']} / ({math.floor(dodge_perc * 100)}%)", True) + emb = await utils.field(emb, "Crit", f"{player_stats['crit']} / ({math.floor(crit_perc * 100)}%)", True) + emb = await utils.field(emb, "Armour", f"{player_stats['armour']} / ({math.floor(armour_perc * 100)}%)", True) + emb = await utils.field(emb, "Accuracy", f"{player_stats['accuracy']}", True) + emb = await utils.field(emb, "Resistance", f"{player_stats['resistance']}", True) + emb = await utils.field(emb, "Luck", f"{player_stats['luck']} / ({luck_chance})", True) + emb = await utils.field(emb, "Block", f"{player_stats['block']} / ({math.floor(block_perc * 100)}%)", True) + emb = await utils.field(emb, "Items", f"{player_stats['total_items']}", True) + + return emb + + +async def refresh_stats(params): + sql_player_info = await utils.sql_postgres("SELECT adventurersinc.get_player_info(%s);", (params['nick'],), True) + sql_player_stats = await utils.sql_postgres("SELECT adventurersinc.get_player_stats(%s);", (params['nick'],), True) + + # print(f"sql_player_info: {sql_player_info}") + # print(f"sql_player_info[0][0]: {sql_player_info[0][0]}") + + if sql_player_info[0][0] is None: + return None + else: + player_stats = {'nick': sql_player_info[0][0]['nick'], + 'currency': sql_player_info[0][0]['currency'], + 'clan_name': sql_player_info[0][0]['clan_name'], + 'character_name': sql_player_info[0][0]['character_name'], + 'player_state': sql_player_info[0][0]['player_state'], + 'alive': sql_player_info[0][0]['alive'], + 'challenge_rating': sql_player_info[0][0]['challenge_rating'], + 'rested_heal': sql_player_info[0][0]['rested_heal'], + 'hp': sql_player_info[0][0]['hp'], + 'max_hp': int(sql_player_stats[0][0]['constitution'] * 2), + 'attribute_points': sql_player_info[0][0]['attribute_points'], + 'hands_req': sql_player_stats[0][0]['hands_req'], + 'unit_type': 'player', + 'strength': sql_player_stats[0][0]['strength'], + 'dexterity': sql_player_stats[0][0]['dexterity'], + 'constitution': sql_player_stats[0][0]['constitution'], + 'intelligence': sql_player_stats[0][0]['intelligence'], + 'dodge': sql_player_stats[0][0]['intelligence'], + 'crit': sql_player_stats[0][0]['crit'], + 'armour': sql_player_stats[0][0]['armour'], + 'accuracy': sql_player_stats[0][0]['accuracy'], + 'resistance': sql_player_stats[0][0]['resistance'], + 'luck': sql_player_stats[0][0]['luck'], + 'block': sql_player_stats[0][0]['block'], + 'total_items': sql_player_info[0][0]['total_items'], + 'race': sql_player_info[0][0]['race']} + return player_stats diff --git a/cogs/adv_inc/Resting.py b/cogs/adv_inc/Resting.py new file mode 100644 index 0000000..b425abb --- /dev/null +++ b/cogs/adv_inc/Resting.py @@ -0,0 +1,204 @@ +#Python modules +import math +import re +import sys +import os +import importlib +import utils + +from cogs.adv_inc import PlayerStats +from cogs.adv_inc import Enemy +from cogs.adv_inc import Items + +importlib.reload(utils) +importlib.reload(PlayerStats) +importlib.reload(Enemy) +importlib.reload(Items) + + +async def player_resting(params, player_stats): + # Inventory + if params["cmd1"].lower() == 'i' or params["cmd1"].lower() == 'inventory': + try: + params["cmd2"] = int(params["cmd2"]) + except ValueError: + params["cmd2"] = 1 + + obj_player_inventory = await utils.sql_postgres("SELECT adventurersinc.get_player_inventory(%s, %s);", (params["nick"], (int(params["cmd2"]) * 5) - 5,), True) + # print(f"obj_player_inventory {obj_player_inventory}") + if not obj_player_inventory: + return "You have no items." + int_total_pages = int(math.ceil(obj_player_inventory[0][0]["total_items"] / 5)) + + str_output = "" + # print("#total pages", int_total_pages) + if 0 < params["cmd2"] <= int_total_pages: + str_output = f'Page {params["cmd2"]} of {int_total_pages}. (http://adventurersinc.lelong.uk/inventory/{params["nick"]})\n' + # print(str_output) + + for item in obj_player_inventory: + str_equipped = 'Equipped ' if item[0]["equipped"] == 1 else 'Unequipped' + str_hands = "--" if str(item[0]["hands_req"]) == '0' else str(item[0]["hands_req"]) + "H" + + str_output = f"{str_output}{item[0]['item_id']} {str_equipped} {str_hands} {item[0]['equipment_colour']} {item[0]['equipment_name']}\n" + return str_output + + # Equip WIP + elif params["cmd1"].lower() == 'e' or params["cmd1"].lower() == 'equip': + # Check to un-equip + if params["cmd2"] == 'u' or params["cmd2"] == 'unequip': + await utils.sql_postgres("CALL adventurersinc.set_player_unequip_all(%s)", (params["nick"],), False) + return "All items have been unequipped." + + elif params["cmd2"].isdigit(): + # Check to see if an ID was supplied + sql_item = await utils.sql_postgres("SELECT adventurersinc.get_player_inventory_item(%s,%s);", (params["nick"], params["cmd2"],), True) + if sql_item[0][0] is not None: + # If selected item is weapon + if sql_item[0][0]['equipment_type'] == 'weapon': + sql_hands_used = await utils.sql_postgres("SELECT adventurersinc.get_player_equip_hands_used(%s)", (params["nick"],), True) + if sql_hands_used[0][0] is None: + sql_hands_used[0][0]["hands_req"] = 0 + + if sql_hands_used[0][0]["hands_req"] + sql_item[0][0]['hands_req'] <= 2 and sql_item[0][0]['equipped'] == 0: + await utils.sql_postgres("CALL adventurersinc.set_player_equipped_item(%s, %s, %s);", (params["cmd2"], True, params["nick"],), False) + return f"Equipping your {sql_item[0][0]['equipment_colour']}{sql_item[0][0]['equipment_name']}." + + elif sql_item[0][0]['equipped'] == 1: + await utils.sql_postgres("CALL adventurersinc.set_player_equipped_item(%s, %s, %s);", (params["cmd2"], False, params["nick"],), False) + return f"Unequipping your {sql_item[0][0]['equipment_colour']}{sql_item[0][0]['equipment_name']}." + + else: + return "You can only wield one two-handed weapon, or two one-handed weapons." + + # If selected item is Armor + elif sql_item[0][0]['equipment_type'] == 'armour': + sql_armour = await utils.sql_postgres("SELECT adventurersinc.get_player_equip_armour_slot(%s, %s)", (params["nick"], sql_item[0][0]['equipment_slot'],), True) + + # print(sql_armour) + if sql_item[0][0]['equipped'] is False and sql_armour[0][0] is None: + await utils.sql_postgres("CALL adventurersinc.set_player_equipped_item(%s, %s, %s);", (params["cmd2"], True, params["nick"],), False) + return f"Equipping your {sql_item[0][0]['equipment_colour']}{sql_item[0][0]['equipment_name']}." + + elif sql_item[0][0]['equipped'] is True: + await utils.sql_postgres("CALL adventurersinc.set_player_equipped_item(%s, %s, %s);", (params["cmd2"], False, params["nick"],), False) + return f"Unequipping your {sql_item[0][0]['equipment_colour']}{sql_item[0][0]['equipment_name']}." + + else: + return "You already have an item in this slot." + else: + return "This item does not exist." + + # All other checks failed, print help message + else: + return "Available commands: e (u)nequip all, e <ID to equip/unequip>" + + # Destroy WIP + elif params["cmd1"].lower() == 'd' or params["cmd1"].lower() == 'destroy': + if re.match("^[0-9]+$", params["cmd2"]): + c.execute("SELECT ID,nick,EquipmentColour,EquipmentSlot,equipment_type,EquipmentName,equipped,hands_req FROM Items_PlayerInventory WHERE nick='%s' AND ID=%s",(params["nick"], params["cmd2"],)) + sql_item = c.fetchone() + item_name = sql_item['EquipmentName'] + item_colour = sql_item['EquipmentColour'] + if sql_item is not None: + c.execute("DELETE FROM Items_PlayerInventory WHERE nick='%s' AND ID=%s",(params["nick"], params["cmd2"]));db.commit(); + return f"Your {item_name} has been destroyed." + + # Battle + elif params["cmd1"].lower() == 'b' or params["cmd1"].lower() == 'battle': + enemy = {} + if player_stats['challenge_rating'] == int(math.ceil(player_stats['challenge_rating'] / 4) * 4): + enemy = await Enemy.create_enemy(enemy, player_stats, params) + return f"Your fighting has caught the attention of the {enemy['enemy_name']}." + else: + enemy = await Enemy.create_enemy(enemy, player_stats, params) + return f"You've been attacked by {enemy['enemy_name']}." + + # Character + elif params["cmd1"].lower() == 'c' or params["cmd1"].lower() == 'character': + return await PlayerStats.print_stats(params) + + # Shop + elif params["cmd1"].lower() == 's' or params["cmd1"].lower() == 'shop': + if params["cmd2"] is '': + sql_shop_inventory = await utils.sql_postgres("SELECT adventurersinc.get_player_shop_all(%s, %s);", (params["nick"], '%'), True) + str_output = f"You have {player_stats['currency']} gold.\n" + for sql_itm in sql_shop_inventory: + str_output = f"{str_output}" + \ + f"{sql_itm[0]['shop_id']} " + \ + f"{sql_itm[0]['equipment_colour']} " + \ + f"{sql_itm[0]['equipment_name']} " + \ + f"{sql_itm[0]['shop_cost']} gold\n" + return str_output + else: + sql_shop_items = await utils.sql_postgres("SELECT adventurersinc.get_player_shop_all(%s, %s);", (params["nick"], params["cmd2"],), True) + # Check is sql_shop_items returns None + if not sql_shop_items: + return "The shopkeep doesn't know what item you ask for." + else: + chosen_item = None + for item in sql_shop_items: + if int(item[0]['shop_id']) == int(params['cmd2']): + chosen_item = item[0] + + # Check if chosen item cost can be purchased + if player_stats['currency'] < chosen_item['shop_cost']: + return "You cannot afford this item." + + # Proceed with purchase + await Items.add_to_inventory(params, chosen_item) + await utils.sql_postgres("CALL adventurersinc.del_player_shop_item(%s, %s);", (str(params["nick"]), params["cmd2"],), False) + await utils.sql_postgres("CALL adventurersinc.set_player_gold(%s, %s);", (chosen_item['shop_cost'], params["nick"],), False) + return f"The {chosen_item['equipment_colour']}{chosen_item['equipment_name']} has been added to your inventory." + + # Heal + elif params["cmd1"].lower() == 'r' or params["cmd1"].lower() == 'rest': + player_stats = await PlayerStats.refresh_stats(params) + if player_stats['rested_heal'] == 0: + if player_stats['hp'] >= player_stats['max_hp']: + await utils.sql_postgres("CALL adventurersinc.set_player_health(%s, %s)", (player_stats['hp'], params["nick"],), False) + return "You rest. You are already at max HP." + + # If heal is an over-heal, heal to max instead + elif round(player_stats['max_hp']/2 + player_stats['hp']) > player_stats['max_hp']: + int_hp_gained = player_stats['max_hp'] + await utils.sql_postgres("CALL adventurersinc.set_player_health(%s, %s)", (int_hp_gained, params["nick"],), False) + return "You rest and your wounds heal completely." + + # Otherwise heal 50% + elif player_stats['hp'] < player_stats['max_hp']: + int_hp_gained = round(player_stats['max_hp']/2 + player_stats['hp']) + await utils.sql_postgres("CALL adventurersinc.set_player_health(%s, %s)", (int_hp_gained, params["nick"],), False) + return f"You rest and you recover {round(player_stats['max_hp']/2)}HP." + + else: + return "You rest." + + # DEBUG - CREATE WEAPON + elif params["cmd1"].lower() == '_viewitem': + return await Items.generate_equipment(params, params["cmd2"]) + + # DEBUG - TEST ITEM GEN WEAPON + elif params["cmd1"].lower() == '_fabled': + return await Items.item_test() + + # DEBUG - Resolve an itemcode + elif params["cmd1"].lower() == '_mergeitemcodes': + item_codes = params["cmd2"].split('_') + return Items.MergeItemCodes(item_codes[0], item_codes[1]) + + # Version + elif params["cmd1"].lower() == 'v' or params["cmd1"].lower() == 'version': + return "Version 1.3 - Notes can be found at: http://www.lexicade.uk/dev.php?view=patchnotes" + + # Admin commands + elif params["cmd1"].lower() == 'genitem' and params["nick"] == 182588470135488512: + await Items.add_to_inventory(params, await Items.generate_equipment(params, '0:0:0:0:1')) + + # Death + elif params["cmd1"].lower() == 'suicide': + CharacterDeath(player_stats, params) + return "You committed suicide." + + else: + return "Available commands: (i)nventory, (e)quip, (b)attle, (c)haracter, (s)hop, (r)est, (v)ersion, (d)estroy." diff --git a/cogs/adv_inc/__init__.py b/cogs/adv_inc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cogs/adv_inc/__init__.py |