Skip to content

Commit

Permalink
Refactor mob difficulty to be based off pickaxe level (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iapetus-11 committed Jul 11, 2024
1 parent 2cc10d5 commit 8b740b2
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 56 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: 0 additions & 3 deletions bot/cogs/commands/useful.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ async def server_info(self, ctx: Ctx, *, guild: int | discord.Guild | None = Non
elif guild is None:
guild = ctx.guild

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

age = arrow.get(discord.utils.snowflake_time(guild.id))
display_age = (
age.format("MMM D, YYYY", locale=ctx.l.lang) + ", " + age.humanize(locale=ctx.l.lang)
Expand Down Expand Up @@ -526,7 +524,6 @@ async def server_info(self, ctx: Ctx, *, guild: int | discord.Guild | None = Non

villager = (
f"{ctx.l.useful.ginf.lang}: `{ctx.l.name}`\n"
f"{ctx.l.useful.ginf.diff}: `{db_guild.difficulty}`\n"
f"{ctx.l.useful.ginf.cmd_prefix}: `{self.bot.prefix_cache.get(guild.id, self.bot.k.default_prefix)}`\n" # noqa: E501
f"{ctx.l.useful.ginf.joined_at}: `{arrow.get(ctx.me.joined_at).humanize(locale=ctx.l.lang)}`\n" # noqa: E501
)
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
5 changes: 0 additions & 5 deletions bot/data/text/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1608,10 +1608,6 @@
"this_server": "Message replies are **{}**.",
"set": "Turned message replies **{}**."
},
"diff": {
"this_server": "The server difficulty is currently set to **{}**.",
"set": "Set the server difficulty to **{}**."
},
"lang": {
"this_server": "The server language is currently set to **{}**.\n\nAvailable languages are: {}",
"set": "Set the server language to **{}**."
Expand Down Expand Up @@ -1684,7 +1680,6 @@
"bans": "Bans",
"cmd_prefix": "Prefix",
"lang": "Language",
"diff": "Difficulty",
"joined_at": "Joined",
"not_found": "Not Found"
},
Expand Down
5 changes: 0 additions & 5 deletions bot/data/text/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1608,10 +1608,6 @@
"this_server": "Las respuestas a los mensajes están **{}**.",
"set": "Las respuestas de los mensajes fue establecida a **{}**."
},
"diff": {
"this_server": "La dificultad del servidor actualmente está establecida en **{}**.",
"set": "Se ha establecido la dificultad del servidor a **{}**."
},
"lang": {
"this_server": "El lenguaje del servidor actualmente está establecido en **{}**\n\nLos idiomas disponibles son: {}",
"set": "Se ha establecido el idioma del servidor a **{}**."
Expand Down Expand Up @@ -1684,7 +1680,6 @@
"bans": "Baneos",
"cmd_prefix": "Prefijo",
"lang": "Idioma",
"diff": "Dificultad",
"joined_at": "Unido",
"not_found": "No se ha encontrado"
},
Expand Down
5 changes: 0 additions & 5 deletions bot/data/text/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1608,10 +1608,6 @@
"this_server": "Les réponses aux messages sont **{}**",
"set": "Passage des réponses aux messages sur **{}**"
},
"diff": {
"this_server": "La difficulté du serveur est actuellement réglée sur **{}**",
"set": "Réglage de la difficulté du serveur sur **{}**"
},
"lang": {
"this_server": "La langue du serveur est actuellement réglée sur **{}**\n\nLes langues disponibles sont : {}",
"set": "Réglage de la langue du serveur sur **{}**"
Expand Down Expand Up @@ -1684,7 +1680,6 @@
"bans": "Bans",
"cmd_prefix": "Préfixe",
"lang": "Langue",
"diff": "Difficulté",
"joined_at": "A Rejoint",
"not_found": "Non trouvé"
},
Expand Down
5 changes: 0 additions & 5 deletions bot/data/text/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -1608,10 +1608,6 @@
"this_server": "As respostas das mensagens são **{}**.",
"set": "Respostas de mensagens definidas como **{}**."
},
"diff": {
"this_server": "A dificuldade do servidor está atualmente definida como **{}**.",
"set": "Dificuldade do servidor definida para **{}**."
},
"lang": {
"this_server": "O idioma do servidor está atualmente definido como **{}**.\n\nOs idiomas disponíveis são: {}",
"set": "Idioma do servidor definido para **{}**."
Expand Down Expand Up @@ -1684,7 +1680,6 @@
"bans": "Banimentos",
"cmd_prefix": "Prefixo",
"lang": "Idioma",
"diff": "Dificuldade",
"joined_at": "Juntou-se",
"not_found": "Não encontrado"
},
Expand Down
2 changes: 0 additions & 2 deletions bot/models/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ class VbConfig(ImmutableBaseModel):
main: VbConfig_Main
prefix: VbConfig_Prefix
replies: VbConfig_Replies
diff: VbConfig_Diff
lang: VbConfig_Lang
mcs: VbConfig_Mcs
gift: VbConfig_Gift
Expand Down Expand Up @@ -400,7 +399,6 @@ class Useful_Ginf(ImmutableBaseModel):
bans: str
cmd_prefix: str
lang: str
diff: str
joined_at: str
not_found: str

Expand Down
1 change: 0 additions & 1 deletion common/models/db/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
class Guild(BaseModel):
guild_id: int
prefix: str
difficulty: str
language: str
mc_server: str | None
do_replies: bool
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 8b740b2

Please sign in to comment.