Jelajahi Sumber

Ability points & coin

root 3 tahun lalu
induk
melakukan
be9fe4eb35
4 mengubah file dengan 34 tambahan dan 10 penghapusan
  1. 19 6
      bot/commands/games.py
  2. 3 3
      bot/events/general.py
  3. 2 0
      bot/query/initialise_database.py
  4. 10 1
      bot/query/user.py

+ 19 - 6
bot/commands/games.py

@@ -3,7 +3,7 @@ import discord
 import random
 from typing import Optional
 from query.channel import get_games
-from query.user import is_ignored, get_level, get_xp, level_up
+from query.user import is_ignored, get_level, get_xp, level_up, get_ability_points_spent, increment_all_coin, get_coin
 from local_settings import COMMAND_PREFIX
 
 def setup(bot: commands.Bot):
@@ -42,10 +42,12 @@ class Games(commands.Cog):
 				await ctx.send(f"`{user}` is not playing.")
 		else:
 			xp_spent, total_xp = await get_xp(self.bot.pg, user.id)
+			ability_points_spent = await get_ability_points_spent(self.bot.pg, user.id)
+			coin = await get_coin(self.bot.pg, user.id)
 			if ctx.author == user:
-				await ctx.send(f"You rank at level {level}. ({xp_spent}/{total_xp})")
+				await ctx.send(f"You rank at level {level}. (exp {xp_spent}/{total_xp} | abp {ability_points_spent}/{level * 3} | coin {coin})")
 			else:
-				await ctx.send(f"`{user}` ranks at level {level}. ({xp_spent}/{total_xp})")
+				await ctx.send(f"`{user}` ranks at level **{level}**. (**{xp_spent}**/{total_xp} | abp {ability_points_spent}/{level * 3}) | coin {coin}")
 
 	@commands.command(
 		description="Check the experience points for a player.",
@@ -64,10 +66,20 @@ class Games(commands.Cog):
 
 		if not user:
 			xp_spent, total_xp = await get_xp(self.bot.pg, ctx.author.id)
-			await ctx.send(f"You have spent {xp_spent} experience points of your {total_xp} total.")
+			level = await get_level(self.bot.pg, ctx.author.id)
+			threshold = (level + 1) * 50 + xp_spent
+			if threshold < total_xp - xp_spent:
+				await ctx.send(f"You have spent {xp_spent} experience points of your {total_xp} total and can gain 3 ability points for {threshold} xp.")
+			else:
+				await ctx.send(f"You have spent {xp_spent} experience points of your {total_xp} total and require {threshold - (total_xp - xp_spent)} xp to `{COMMAND_PREFIX}levelup`.")
 		else:
 			xp_spent, total_xp = await get_xp(self.bot.pg, user.id)
-			await ctx.send(f"`{user}` has spent {xp_spent} of {total_xp} experience points.")
+			level = await get_level(self.bot.pg, user.id)
+			threshold = (level + 1) * 50 + xp_spent
+			if threshold < total_xp - xp_spent:
+				await ctx.send(f"`{user}` has spent {xp_spent} of {total_xp} experience points and can level up for {threshold} xp.")
+			else:
+				await ctx.send(f"`{user}` has spent {xp_spent} of {total_xp} experience points and requires {threshold - (total_xp - xp_spent)} xp to level up.")
 
 	@commands.command(
 		description="Attempt to gain a level.",
@@ -92,7 +104,8 @@ class Games(commands.Cog):
 			await ctx.send(f"Not yet, you require {threshold - xp_available} more XP to level up.")
 		else:
 			await level_up(self.bot.pg, ctx.author.id, threshold)
-			await ctx.send(f"You have climbed the ranks for {threshold} XP, leaving you {xp_available - threshold} remaining.")
+			await ctx.send(f"You have gained three ability points climbed the ranks for {threshold} XP, leaving you {xp_available - threshold} remaining.")
+			await increment_all_coin(self.bot.pg)
 
 
 	@commands.command(

+ 3 - 3
bot/events/general.py

@@ -201,15 +201,15 @@ class General(commands.Cog):
 		reacted(self.bot.pg, user.id)
 
 	@commands.Cog.listener()
-	async def on_scheduled_event_create(self, event: discord.ScheduledEvent):
+	async def on_scheduled_event_create(self, event):
 		event_created(self.bot.pg, event.creator.id)
 
 	@commands.Cog.listener()
-	async def on_scheduled_event_user_add(self, event: discord.ScheduledEvent, user):
+	async def on_scheduled_event_user_add(self, event, user):
 		event_joined(self.bot.pg, user.id)
 
 	@commands.Cog.listener()
-	async def on_thread_create(self, thread: discord.Thread):
+	async def on_thread_create(self, thread):
 		thread_created(self.bot.pg, thread.owner.id)
 
 	@commands.Cog.listener()

+ 2 - 0
bot/query/initialise_database.py

@@ -52,6 +52,8 @@ async def init_db(pg):
                 events_joined INT DEFAULT 0, \
                 threads_created INT DEFAULT 0, \
                 threads_joined INT DEFAULT 0, \
+                ability_points_spent INT DEFAULT 0, \
+                coin INT DEFAULT 0, \
                 created TIMESTAMP NOT NULL DEFAULT now()\
             )\
         ",

+ 10 - 1
bot/query/user.py

@@ -87,4 +87,13 @@ async def thread_created(pg, user_id):
 	await pg.execute("UPDATE \"user\" SET (threads_created) = (+ 1) WHERE user_id = $1", user_id)
 
 async def thread_joined(pg, user_id):
-	await pg.execute("UPDATE \"user\" SET (threads_joined) = (+ 1) WHERE user_id = $1", user_id)
+	await pg.execute("UPDATE \"user\" SET (threads_joined) = (+ 1) WHERE user_id = $1", user_id)
+
+async def get_ability_points_spent(pg, user_id):
+	return await pg.fetchval("SELECT ability_points_spent FROM \"user\" WHERE user_id = $1", user_id)
+
+async def increment_all_coin(pg):
+	await pg.execute("UPDATE \"user\" SET (coin) = (+ 1) WHERE level > 0")
+
+async def get_coin(pg, user_id):
+	return await pg.fetchval("SELECT coin FROM \"user\" WHERE user_id = $1", user_id)