Skip to content

Commit

Permalink
Fix documentation about game seed
Browse files Browse the repository at this point in the history
restrict min and max stats to the limits allowed by the game seed
Allow the hex game seed to be used for starting adventures (it was annoying every time I had to convert to an int)
  • Loading branch information
TrustyJAID committed Mar 10, 2024
1 parent f5af095 commit 7bc4e62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions adventure/adventureresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class GameSeed:
This seed encodes the min and max stat range to reduce the pool size of monsters
which is critical to making the monster RNG deterministic based on some seed.
The premise is similar to discord unique ID's. Encoding a timestamp after 26 bits.
The premise is similar to discord unique ID's. Encoding a timestamp after 30 bits.
The 21st bit contains whether to prefer hp or diplomacy for the monster stats.
The next 20 bits contain the min and max. These are limited to 4095 bits.
The next 20 bits contain the min and max. These are limited to 16383 bits.
Since the base monsters cap at 560 stat this should be good enough.
Custom monsters with higher stats will break this if they go above 4095.
Custom monsters with higher stats will break this if they go above 16383.
"""

TIMESTAMP_SHIFT = 30
Expand Down Expand Up @@ -69,10 +69,10 @@ def hp_or_diplo(self):
return 1 if self.stat_range.stat_type == "hp" else 0

def min_stat(self):
return int(self.stat_range.min_stat)
return max(int(self.stat_range.min_stat), 0)

def max_stat(self):
return int(self.stat_range.max_stat)
return min(int(self.stat_range.max_stat), 16383)

def timestamp(self):
# Strip the timestamp from the message ID
Expand Down
4 changes: 2 additions & 2 deletions adventure/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,15 @@ async def autocomplete(self, interaction: discord.Interaction, current: str) ->

class ChallengeConverter(Transformer):
@classmethod
async def convert(cls, ctx: commands.Context, argument: str) -> str:
async def convert(cls, ctx: commands.Context, argument: str) -> Union[str, int]:
if ctx.author.id not in (*ctx.bot.owner_ids, *DEV_LIST):
return ""
if argument.isnumeric():
return int(argument)
cog = ctx.bot.get_cog("Adventure")
monsters, monster_stats, transcended = await cog.update_monster_roster()
if argument not in monsters:
return ""
return int(argument, 16)
return argument

@classmethod
Expand Down

0 comments on commit 7bc4e62

Please sign in to comment.