From 07515fd9da3cf7d9b52118eead9ba076443ad916 Mon Sep 17 00:00:00 2001 From: imtherealF1 <168587794+imtherealF1@users.noreply.github.com> Date: Fri, 6 Sep 2024 17:33:52 +0300 Subject: [PATCH] [settings] making the biggest defense/attack stat bonus configurable (#383) * making max stat bonuses configurable in settings * adding the configurable stats to config-ref.json * adjusting the stat generation logic when a ball is spawned * adding the new configurable stat logic to admin give * making the descriptions more clear in settings * making descriptions more clear again * changing the descriptions in config-ref.json too * 2 lines into 3 for code formatting checks to pass * removing some required properties * improving the comments even more and giving warnings * changing to max health bonus * changing to max health bonus * changing to max health bonus in admin cog * changing to max health bonus * small change, changing _ to - * changing _ to - * same change again * solving the first conflict * reverting last commit --------- Co-authored-by: flaree --- ballsdex/packages/admin/cog.py | 36 +++++++++++++------- ballsdex/packages/countryballs/components.py | 4 +-- ballsdex/settings.py | 31 +++++++++++++++++ json-config-ref.json | 34 ++++++++++++++---- 4 files changed, 83 insertions(+), 22 deletions(-) diff --git a/ballsdex/packages/admin/cog.py b/ballsdex/packages/admin/cog.py index f43b32dd..fa4cd285 100644 --- a/ballsdex/packages/admin/cog.py +++ b/ballsdex/packages/admin/cog.py @@ -543,7 +543,7 @@ async def spawn( async def give( self, interaction: discord.Interaction, - ball: BallTransform, + countryball: BallTransform, user: discord.User, special: SpecialTransform | None = None, shiny: bool | None = None, @@ -555,15 +555,15 @@ async def give( Parameters ---------- - ball: Ball + countryball: Ball user: discord.User special: Special | None shiny: bool Omit this to make it random. health_bonus: int | None - Omit this to make it random (-20/+20%). + Omit this to make it random. attack_bonus: int | None - Omit this to make it random (-20/+20%). + Omit this to make it random. """ # the transformers triggered a response, meaning user tried an incorrect input if interaction.response.is_done(): @@ -572,22 +572,32 @@ async def give( player, created = await Player.get_or_create(discord_id=user.id) instance = await BallInstance.create( - ball=ball, + ball=countryball, player=player, shiny=(shiny if shiny is not None else random.randint(1, 2048) == 1), - attack_bonus=(attack_bonus if attack_bonus is not None else random.randint(-20, 20)), - health_bonus=(health_bonus if health_bonus is not None else random.randint(-20, 20)), + attack_bonus=( + attack_bonus + if attack_bonus is not None + else random.randint(-settings.max_attack_bonus, settings.max_attack_bonus) + ), + health_bonus=( + health_bonus + if health_bonus is not None + else random.randint(-settings.max_health_bonus, settings.max_health_bonus) + ), special=special, ) await interaction.followup.send( - f"`{ball.country}` {settings.collectible_name} was successfully given to `{user}`.\n" - f"Special: `{special.name if special else None}` • ATK:`{instance.attack_bonus:+d}` • " - f"HP:`{instance.health_bonus:+d}` • Shiny: `{instance.shiny}`" + f"`{countryball.country}` {settings.collectible_name} was successfully given to " + f"`{user}`.\nSpecial: `{special.name if special else None}` • ATK: " + f"`{instance.attack_bonus:+d}` • HP:`{instance.health_bonus:+d}` " + f"• Shiny: `{instance.shiny}`" ) await log_action( - f"{interaction.user} gave {settings.collectible_name} {ball.country} to {user}. " - f"(Special={special.name if special else None} ATK={instance.attack_bonus:+d} " - f"HP={instance.health_bonus:+d} shiny={instance.shiny}).", + f"{interaction.user} gave {settings.collectible_name} " + f"{countryball.country} to {user}. (Special={special.name if special else None} " + f"ATK={instance.attack_bonus:+d} HP={instance.health_bonus:+d} " + f"shiny={instance.shiny}).", self.bot, ) diff --git a/ballsdex/packages/countryballs/components.py b/ballsdex/packages/countryballs/components.py index c0fa64ab..f6abed7f 100755 --- a/ballsdex/packages/countryballs/components.py +++ b/ballsdex/packages/countryballs/components.py @@ -100,8 +100,8 @@ async def catch_ball( player, created = await Player.get_or_create(discord_id=user.id) # stat may vary by +/- 20% of base stat - bonus_attack = random.randint(-20, 20) - bonus_health = random.randint(-20, 20) + bonus_attack = random.randint(-settings.max_attack_bonus, settings.max_attack_bonus) + bonus_health = random.randint(-settings.max_health_bonus, settings.max_health_bonus) shiny = random.randint(1, 2048) == 1 # check if we can spawn cards with a special background diff --git a/ballsdex/settings.py b/ballsdex/settings.py index ec74105c..86f9acce 100644 --- a/ballsdex/settings.py +++ b/ballsdex/settings.py @@ -36,6 +36,10 @@ class Settings: Set the name of the base command of the "players" cog, /balls by default max_favorites: Set the maximum amount of favorited countryballs a user can have, 50 by default. + max_attack_bonus: + Set the biggest/smallest attack bonus that a spawned countryball can have. + max_health_bonus: + Set the biggest/smallest health bonus that a spawned countryball can have. about_description: str Used in the /about command github_link: str @@ -65,6 +69,8 @@ class Settings: players_group_cog_name: str = "balls" max_favorites: int = 50 + max_attack_bonus: int = 20 + max_health_bonus: int = 20 # /about about_description: str = "" @@ -126,6 +132,8 @@ def read_settings(path: "Path"): settings.prometheus_port = content["prometheus"]["port"] settings.max_favorites = content.get("max-favorites", 50) + settings.max_attack_bonus = content.get("max-attack-bonus", 20) + settings.max_health_bonus = content.get("max-health-bonus", 20) log.info("Settings loaded.") @@ -175,6 +183,14 @@ def write_default_settings(path: "Path"): # maximum amount of favorites that are allowed max-favorites: 50 +# the highest/lowest possible attack bonus, do not leave empty +# this cannot be smaller than 0, enter a positive number +max-attack-bonus: 20 + +# the highest/lowest possible health bonus, do not leave empty +# this cannot be smaller than 0, enter a positive number +max-health-bonus: 20 + # enables the /admin command admin-command: @@ -218,6 +234,8 @@ def update_settings(path: "Path"): add_owners = True add_config_ref = "# yaml-language-server: $schema=json-config-ref.json" not in content add_max_favorites = "max-favorites:" not in content + add_max_attack = "max-attack-bonus" not in content + add_max_health = "max-health-bonus" not in content add_plural_collectible = "plural-collectible-name" not in content for line in content.splitlines(): @@ -247,6 +265,19 @@ def update_settings(path: "Path"): max-favorites: 50 """ + if add_max_attack: + content += """ +# the highest/lowest possible attack bonus, do not leave empty +# this cannot be smaller than 0, enter a positive number +max-attack-bonus: 20 +""" + + if add_max_health: + content += """ +# the highest/lowest possible health bonus, do not leave empty +# this cannot be smaller than 0, enter a positive number +max-health-bonus: 20 +""" if add_plural_collectible: content += """ # WORK IN PROGRESS, DOES NOT FULLY WORK diff --git a/json-config-ref.json b/json-config-ref.json index cc00db8d..202bab1d 100644 --- a/json-config-ref.json +++ b/json-config-ref.json @@ -3,7 +3,17 @@ "title": "Ballsdex configuration", "description": "Core settings for the Ballsdex Discord bot", "type": "object", - "required": ["discord-token", "text-prefix", "about", "collectible-name", "bot-name", "players-group-cog-name", "admin-command", "prometheus", "owners"], + "required": [ + "discord-token", + "text-prefix", + "about", + "collectible-name", + "bot-name", + "players-group-cog-name", + "admin-command", + "prometheus", + "owners", + ], "properties": { "discord-token": { "description": "The Discord bot token", @@ -53,6 +63,22 @@ "description": "The name of the collectible, used everywhere except command descriptions.", "example": "ball" }, + "max-favorites": { + "type": "integer", + "default": 50, + "description": "Maximum number of favorite countryballs allowed per player", + "minimum": 0 + }, + "max-attack-bonus": { + "type": "integer", + "description": "The biggest/smallest attack bonus that a spawned countryball can have.", + "example": "20" + }, + "max-health-bonus": { + "type": "integer", + "description": "The biggest/smallest health bonus that a spawned countryball can have.", + "example": "20" + }, "plural-collectible-name": { "type": "string", "description": "The plural name of the collectible, used everywhere except command descriptions.", @@ -148,12 +174,6 @@ } } } - }, - "max-favorites": { - "type": "integer", - "default": 50, - "description": "Maximum number of favorite countryballs allowed per player", - "minimum": 0 } } }