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

Set a static last know balance to avoid workarounds around rebirth #412

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions adventure/adventure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,8 @@ async def _add_rewards(self, ctx: commands.Context, user, exp, cp, special):
rebirth_emoji = self.emojis.rebirth
if lvl_end >= c.maxlevel:
rebirthextra = _("{} You can now rebirth {}").format(rebirth_emoji, user.mention)
if c.static_last_known_currency is None:
c.static_last_known_currency = c.bal
if lvl_start < lvl_end:
# recalculate free skillpoint pool based on new level and already spent points.
c.lvl = lvl_end
Expand Down
4 changes: 4 additions & 0 deletions adventure/charsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def __init__(self, **kwargs):
self.rebirths = kwargs.pop("rebirths", 0)
self.last_known_currency = kwargs.get("last_known_currency")
self.last_currency_check = kwargs.get("last_currency_check")
self.static_last_known_currency = kwargs.get("static_last_known_currency")
self.gear_set_bonus = {}
self.get_set_bonus()
self.maxlevel = self.get_max_level()
Expand Down Expand Up @@ -1392,6 +1393,7 @@ async def from_json(
hero_data[k] = v
hero_data["last_skill_reset"] = data.get("last_skill_reset", 0)
hero_data["last_known_currency"] = data.get("last_known_currency", 0)
hero_data["static_last_known_currency"] = data.get("static_last_known_currency")
hero_data["last_currency_check"] = data.get("last_currency_check", 0)
return cls(**hero_data, ctx=ctx, daily_bonus_mapping=daily_bonus_mapping)

Expand Down Expand Up @@ -1459,6 +1461,7 @@ async def to_json(self, ctx: commands.Context, config: Config) -> dict:
"set_items": self.set_items,
"last_skill_reset": self.last_skill_reset,
"last_known_currency": self.last_known_currency,
"static_last_known_currency": self.static_last_known_currency,
}

async def rebirth(self, dev_val: int = None) -> dict:
Expand Down Expand Up @@ -1542,6 +1545,7 @@ async def rebirth(self, dev_val: int = None) -> dict:
"rebirths": self.rebirths,
"set_items": self.set_items,
"last_known_currency": 0,
"static_last_known_currency": None,
"last_currency_check": 0,
}

Expand Down
1 change: 1 addition & 0 deletions adventure/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"last_skill_reset": 0,
"last_known_currency": 0,
"last_currency_check": 0,
"static_last_known_currency": None,
"treasure": [0, 0, 0, 0, 0, 0],
"items": {
"head": {},
Expand Down
1 change: 0 additions & 1 deletion adventure/negaverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,5 @@ async def _negaverse(
current_loses_value = character.nega.get("loses", 0)
character.nega.update({"loses": current_loses_value + 1})
changed = True

if changed:
await self.config.user(ctx.author).set(await character.to_json(ctx, self.config))
11 changes: 10 additions & 1 deletion adventure/rebirth.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ async def rebirth(self, ctx: commands.Context):
rebirthcost = 1000 * c.rebirths
current_balance = c.bal
last_known_currency = c.last_known_currency
if last_known_currency and current_balance / last_known_currency < 0.25:
if (
c.static_last_known_currency is None
and last_known_currency
and (current_balance / last_known_currency) < 0.5
) or (c.static_last_known_currency is not None and (current_balance / c.static_last_known_currency) < 0.5):
if c.static_last_known_currency is None:
c.static_last_known_currency = last_known_currency
await self.config.user(ctx.author).set(await c.to_json(ctx, self.config))
if c.static_last_known_currency is not None:
last_known_currency = c.static_last_known_currency
currency_name = await bank.get_currency_name(
ctx.guild,
)
Expand Down