summaryrefslogtreecommitdiff
path: root/cogs/adv_inc/LevelUp.py
blob: b6b73b6f90c69e116c765501dabbf3740fbc6686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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']}"