Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[settings] making the biggest defense/attack stat bonus configurable #383

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_defense_bonus, settings.max_defense_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 @@ -91,8 +91,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_defense_bonus, settings.max_defense_bonus)
shiny = random.randint(1, 2048) == 1

# check if we can spawn cards with a special background
Expand Down
32 changes: 32 additions & 0 deletions ballsdex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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_defense_bonus:
imtherealF1 marked this conversation as resolved.
Show resolved Hide resolved
Set the biggest/smallest defense bonus that a spawned countryball can have.
about_description: str
Used in the /about command
github_link: str
Expand Down Expand Up @@ -62,6 +66,8 @@ class Settings:
players_group_cog_name: str = "balls"

max_favorites: int = 50
max_attack_bonus: int = 20
max_defense_bonus: int = 20

# /about
about_description: str = ""
Expand Down Expand Up @@ -120,6 +126,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_defense_bonus = content.get("max-defense-bonus", 20)
log.info("Settings loaded.")


Expand Down Expand Up @@ -165,6 +173,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 defense bonus, do not leave empty
# this cannot be smaller than 0, enter a positive number
max-defense-bonus: 20

# enables the /admin command
admin-command:

Expand Down Expand Up @@ -208,6 +224,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_defense = "max-defense-bonus" not in content

for line in content.splitlines():
if line.startswith("owners:"):
Expand All @@ -234,6 +252,20 @@ def update_settings(path: "Path"):
content += """
# maximum amount of favorites that are allowed
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_defense:
content += """
# the highest/lowest possible defense bonus, do not leave empty
# this cannot be smaller than 0, enter a positive number
max-defense-bonus: 20
"""

if any((add_owners, add_config_ref)):
Expand Down
36 changes: 28 additions & 8 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. An 's' is appended to the end of this string for pluralization",
"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-defense-bonus": {
"type": "integer",
"description": "The biggest/smallest defense bonus that a spawned countryball can have.",
"example": "20"
},
"bot-name": {
"type": "string",
"description": "The name of the bot, used in places such as the /completion command",
Expand Down Expand Up @@ -143,12 +169,6 @@
}
}
}
},
"max-favorites": {
"type": "integer",
"default": 50,
"description": "Maximum number of favorite countryballs allowed per player",
"minimum": 0
}
}
}
}
Loading