Skip to content

Commit

Permalink
[settings] making the biggest defense/attack stat bonus configurable (B…
Browse files Browse the repository at this point in the history
…allsdex-Team#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 <[email protected]>
  • Loading branch information
imtherealF1 and flaree authored Sep 6, 2024
1 parent 9e8f318 commit 07515fd
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 22 deletions.
36 changes: 23 additions & 13 deletions ballsdex/packages/admin/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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():
Expand All @@ -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,
)

Expand Down
4 changes: 2 additions & 2 deletions ballsdex/packages/countryballs/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions ballsdex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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.")


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions json-config-ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -148,12 +174,6 @@
}
}
}
},
"max-favorites": {
"type": "integer",
"default": 50,
"description": "Maximum number of favorite countryballs allowed per player",
"minimum": 0
}
}
}

0 comments on commit 07515fd

Please sign in to comment.