Skip to content

Commit

Permalink
Refactor mob difficulty to be based off pickaxe level
Browse files Browse the repository at this point in the history
  • Loading branch information
Iapetus-11 committed Jul 10, 2024
1 parent 2cc10d5 commit 01a632c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
22 changes: 0 additions & 22 deletions bot/cogs/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,6 @@ async def config_replies(self, ctx: Ctx, replies: str = None):
else:
await ctx.reply_embed(ctx.l.config.invalid.format("`on`, `off`"))

@config.command(name="difficulty", aliases=["diff"])
@commands.guild_only()
@commands.has_permissions(administrator=True)
@commands.cooldown(1, 10, commands.BucketType.user)
async def config_difficulty(self, ctx: Ctx, diff: str = None):
if diff is None:
guild = await self.db.fetch_guild(ctx.guild.id)
await ctx.reply_embed(ctx.l.config.diff.this_server.format(guild.difficulty))
return

if diff.lower() == "peaceful":
await self.db.set_guild_attr(ctx.guild.id, "difficulty", "peaceful")
await ctx.reply_embed(ctx.l.config.diff.set.format("peaceful"))
elif diff.lower() == "easy":
await self.db.set_guild_attr(ctx.guild.id, "difficulty", "easy")
await ctx.reply_embed(ctx.l.config.diff.set.format("easy"))
elif diff.lower() == "hard":
await self.db.set_guild_attr(ctx.guild.id, "difficulty", "hard")
await ctx.reply_embed(ctx.l.config.diff.set.format("hard"))
else:
await ctx.reply_embed(ctx.l.config.invalid.format("`peaceful`, `easy`, `hard`"))

@config.command(name="language", aliases=["lang"])
@commands.guild_only()
@commands.has_permissions(administrator=True)
Expand Down
3 changes: 1 addition & 2 deletions bot/cogs/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ async def fetch_guild(self, guild_id: int) -> Guild:

if g is None:
g = await self.db.fetchrow(
"INSERT INTO guilds (guild_id, prefix, difficulty, language) VALUES ($1, $2, $3, $4) RETURNING *",
"INSERT INTO guilds (guild_id, prefix, language) VALUES ($1, $2, $3) RETURNING *",
guild_id,
self.k.default_prefix,
"easy",
"en",
)

Expand Down
15 changes: 10 additions & 5 deletions bot/cogs/core/mobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@ async def _spawn_event(self, ctx: Ctx):
if ctx.guild is None: # ignore dms
return

db_guild = await self.db.fetch_guild(ctx.guild.id)
difficulty = db_guild.difficulty

if difficulty == "peaceful":
return
# The difficulty of the mob spawned is based off who triggered the action, rather
# than the person who actually engages the mob
ctx_user_pickaxe_lvl = len(self.d.mining.pickaxes) - self.d.mining.pickaxes.index(
await self.db.fetch_pickaxe(ctx.author.id)
)
difficulty: typing.Literal["easy", "hard"]
if ctx_user_pickaxe_lvl >= 3: # Gold pick
difficulty = "hard"
else:
difficulty = "easy"

difficulty_multi = {"easy": 1, "hard": 1.5}[difficulty]

Expand Down
1 change: 0 additions & 1 deletion setup.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CREATE TABLE IF NOT EXISTS guilds (
guild_id BIGINT PRIMARY KEY, -- the discord guild id / snowflake
prefix VARCHAR(15) NOT NULL, -- the prefix of the guild
difficulty VARCHAR NOT NULL, -- the difficulty the server is on peaceful, easy, hard
language VARCHAR(6) NOT NULL, -- the language the bot will speak in
mc_server VARCHAR(100), -- the minecraft server of the guild
do_replies BOOLEAN NOT NULL DEFAULT true -- whether to do funny replies to certain messages
Expand Down

0 comments on commit 01a632c

Please sign in to comment.