Skip to content

Commit

Permalink
Adventure 4.0.5 The Negaverse punishment (#456)
Browse files Browse the repository at this point in the history
* Adventure 4.0.5 The Negaverse punishment
- Update negaverse to steal more items on average and adjust what rarities are excluded.
 - Pagify lost items from negaverse.
- Fix an issue where some backpack displays weren't showing degrade properly.
- LUC -> LUCK for backpack display, the column is always longer anyway so why shorten it?
- Fix an issue where some 2h weapons were duplicated after rebirth.
- Some typehinting fixes.
- Fix issues with special action button for psychic users.
- Update `[p]give item` command to use FlagConverters instead so it's more explicit on what stats are where when using the command.
- Fix extra space on Transcended creatures.

* formatting
  • Loading branch information
TrustyJAID authored Feb 29, 2024
1 parent 72d7d7a commit f28512e
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 206 deletions.
2 changes: 2 additions & 0 deletions adventure/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
from abc import ABC, abstractmethod
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any, Dict, List, Literal, MutableMapping, Optional, Union

import discord
Expand Down Expand Up @@ -39,6 +40,7 @@ def __init__(self, *_args):
self.config: Config
self.bot: Red
self.settings: Dict[Any, Any]
self.emojis: SimpleNamespace
self._ready: asyncio.Event
self._adventure_countdown: dict
self._rewards: dict
Expand Down
4 changes: 2 additions & 2 deletions adventure/adventure.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def red_delete_data_for_user(
user_id
).clear() # This will only ever touch the separate currency, leaving bot economy to be handled by core.

__version__ = "4.0.4"
__version__ = "4.0.5"

def __init__(self, bot: Red):
self.bot = bot
Expand Down Expand Up @@ -871,7 +871,7 @@ async def _simple(self, ctx: commands.Context, adventure_msg, challenge: str = N
if easy_mode:
if transcended:
# Shows Transcended on Easy mode
new_challenge = _("Transcended {}").format(challenge.replace("Ascended", ""))
new_challenge = _("Transcended {}").format(challenge.replace("Ascended ", ""))
no_monster = False
if monster_roster[challenge]["boss"]:
timer = 60 * 5
Expand Down
68 changes: 45 additions & 23 deletions adventure/charsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ def __init__(self, **kwargs):
def __str__(self):
return self.rarity.as_str(self.name)

def __eq__(self, other: object) -> bool:
if not isinstance(other, Item):
return False
return (
other.name == self.name
and other.rarity is self.rarity
and other.dex == self.dex
and other.luck == self.luck
and other.att == self.att
and other.int == self.int
and other.cha == self.cha
and other.slot is self.slot
)

@property
def ansi(self) -> str:
return self.rarity.as_ansi(self.name)
Expand All @@ -88,7 +102,9 @@ def row(self, player_level: int) -> Tuple[Any, ...]:
self.luck * (1 if self.slot is not Slot.two_handed else 2),
f"{ANSITextColours.red.as_str(str(self.lvl))}" if not can_equip else f"{self.lvl}",
self.owned,
f"[{self.degrade}]" if self.rarity in ["legendary", "event", "ascended"] and self.degrade >= 0 else "N/A",
f"[{self.degrade}]"
if self.rarity in [Rarities.legendary, Rarities.event, Rarities.ascended] and self.degrade >= 0
else "N/A",
self.set or "N/A",
)

Expand Down Expand Up @@ -150,7 +166,6 @@ def remove_markdowns(item):
def from_json(cls, ctx: commands.Context, data: dict):
name = "".join(data.keys())
data = data[name]
rarity = "normal"
if name.startswith("."):
name = name.replace("_", " ").replace(".", "")
rarity = "rare"
Expand Down Expand Up @@ -190,7 +205,7 @@ def from_json(cls, ctx: commands.Context, data: dict):
elif name.startswith("{Event:'"):
name = name.replace("{Event:'", "").replace("''}", "")
rarity = "event"
rarity = data["rarity"] if "rarity" in data else rarity
rarity = data.get("rarity", "normal")
att = data["att"] if "att" in data else 0
dex = data["dex"] if "dex" in data else 0
inter = data["int"] if "int" in data else 0
Expand Down Expand Up @@ -728,17 +743,12 @@ def _sort(item):
final.append(sorted(tmp[slot_name], key=_sort))
return final

async def looted(self, how_many: int = 1, exclude: Set[Union[str, Rarities]] = set()) -> List[Tuple[str, int]]:
if not exclude:
exclude = {Rarities.normal, Rarities.rare, Rarities.epic, Rarities.forged}
else:
for rarity in exclude:
if isinstance(rarity, Rarities):
exclude.add(rarity)
else:
exclude.add(Rarities.get_from_name(rarity))
async def looted(self, how_many: int = 1, exclude: Optional[Set[Rarities]] = None) -> List[Tuple[str, int]]:
if exclude is None:
exclude = {Rarities.forged, Rarities.event}
exclude.add(Rarities.forged)
items = [i for n, i in self.backpack.items() if i.rarity not in exclude]
exclude.add(Rarities.event)
items = [i for i in self.backpack.values() if i.rarity not in exclude]
looted_so_far = 0
looted = []
if not items:
Expand All @@ -747,7 +757,8 @@ async def looted(self, how_many: int = 1, exclude: Set[Union[str, Rarities]] = s
while how_many > looted_so_far:
if looted_so_far >= how_many:
break
if count >= 5:
if count >= 10:
# Our max items stolen is 10 now
break
item = random.choice(items)
if not bool(random.getrandbits(1)):
Expand Down Expand Up @@ -776,7 +787,7 @@ async def make_backpack_tables(self, items: List[List[str]], title: str = "") ->
"CHA",
"INT",
"DEX",
"LUC",
"LUCK",
"LVL",
"QTY",
"DEG",
Expand Down Expand Up @@ -1534,14 +1545,19 @@ async def rebirth(self, dev_val: int = None) -> dict:
self.belt,
self.legs,
self.boots,
self.left,
self.right,
self.ring,
self.charm,
self.neck,
]:
if item and item.to_json() not in list(self.pieces_to_keep.values()):
await self.add_to_backpack(item)
if (self.left and self.left.slot is Slot.two_handed) or (self.right and self.right.slot is Slot.two_handed):
if self.left.to_json() not in list(self.pieces_to_keep.values()):
await self.add_to_backpack(self.left)
else:
for item in [self.left, self.right]:
if item and item.to_json() not in list(self.pieces_to_keep.values()):
await self.add_to_backpack(item)
forged = 0
for k, v in self.backpack.items():
for n, i in v.to_json().items():
Expand Down Expand Up @@ -1606,15 +1622,21 @@ async def rebirth(self, dev_val: int = None) -> dict:

def keep_equipped(self):
items_to_keep = {}
last_slot = ""
for slots in Slot:
if slots is Slot.two_handed:
continue
if last_slot == "two handed":
last_slot = slots
if slots in [Slot.two_handed, Slot.left, Slot.right]:
continue
items_to_keep[slots.name] = {}
item = getattr(self, slots.name)
items_to_keep[slots] = item.to_json() if self.rebirths >= 30 and item and item.set else {}
if item and item.set and self.rebirths >= 30:
items_to_keep[slots.name] = item.to_json()
if self.left == self.right and self.right is not None:
if self.right.set and self.rebirths >= 30:
items_to_keep["right"] = self.right.to_json()
else:
if self.left and self.left.set and self.rebirths >= 30:
items_to_keep["left"] = self.left.to_json()
if self.right and self.right.set and self.rebirths >= 30:
items_to_keep["right"] = self.right.to_json()
self.pieces_to_keep = items_to_keep


Expand Down
38 changes: 13 additions & 25 deletions adventure/class_abilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def heroclass(
if clz is None:
ctx.command.reset_cooldown(ctx)
classes = box(
"\n".join(c.class_colour.as_str(c.class_name) for c in HeroClasses),
"\n".join(c.class_colour.as_str(c.class_name) for c in HeroClasses if c is not HeroClasses.hero),
lang="ansi",
)
await smart_embed(
Expand Down Expand Up @@ -440,12 +440,10 @@ async def _forage(self, ctx: commands.Context):
c.heroclass["cooldown"] = time.time() + cooldown_time
await self.config.user(ctx.author).set(await c.to_json(ctx, self.config))
else:
cooldown_time = c.heroclass["cooldown"] - time.time()
cooldown_time = c.heroclass["cooldown"]
return await smart_embed(
ctx,
_("This command is on cooldown. Try again in {}.").format(
humanize_timedelta(seconds=int(cooldown_time)) if int(cooldown_time) >= 1 else _("1 second")
),
_("This command is on cooldown. Try again in {}.").format(f"<t:{cooldown_time}:R>"),
)

@pet.command(name="free")
Expand Down Expand Up @@ -513,16 +511,14 @@ async def bless(self, ctx: commands.Context):
),
)
else:
cooldown_time = c.heroclass["cooldown"] - time.time()
cooldown_time = c.heroclass["cooldown"]
return await smart_embed(
ctx,
_(
"Your hero is currently recovering from the last time "
"they used this skill or they have just changed their heroclass. "
"Try again in {}."
).format(
humanize_timedelta(seconds=int(cooldown_time)) if int(cooldown_time) >= 1 else _("1 second")
),
).format(f"<t:{cooldown_time}:R>"),
)

@commands.hybrid_command()
Expand Down Expand Up @@ -714,9 +710,7 @@ async def insight(self, ctx: commands.Context):
"Your hero is currently recovering from the last time "
"they used this skill or they have just changed their heroclass. "
"Try again in {}."
).format(
humanize_timedelta(seconds=int(cooldown_time)) if int(cooldown_time) >= 1 else _("1 second")
),
).format(f"<t:{cooldown_time}:R>"),
)

@commands.hybrid_command()
Expand Down Expand Up @@ -758,16 +752,14 @@ async def rage(self, ctx: commands.Context):
),
)
else:
cooldown_time = c.heroclass["cooldown"] - time.time()
cooldown_time = c.heroclass["cooldown"]
return await smart_embed(
ctx,
_(
"Your hero is currently recovering from the last time "
"they used this skill or they have just changed their heroclass. "
"Try again in {}."
).format(
humanize_timedelta(seconds=int(cooldown_time)) if int(cooldown_time) >= 1 else _("1 second")
),
).format(f"<t:{cooldown_time}:R>"),
)

@commands.hybrid_command()
Expand Down Expand Up @@ -810,15 +802,13 @@ async def focus(self, ctx: commands.Context):
),
)
else:
cooldown_time = c.heroclass["cooldown"] - time.time()
cooldown_time = c.heroclass["cooldown"]
return await smart_embed(
ctx,
_(
"Your hero is currently recovering from the "
"last time they used this skill. Try again in {}."
).format(
humanize_timedelta(seconds=int(cooldown_time)) if int(cooldown_time) >= 1 else _("1 second")
),
).format(f"<t:{cooldown_time}:R>"),
)

@commands.hybrid_command()
Expand Down Expand Up @@ -859,16 +849,14 @@ async def music(self, ctx: commands.Context):
),
)
else:
cooldown_time = c.heroclass["cooldown"] - time.time()
cooldown_time = c.heroclass["cooldown"]
return await smart_embed(
ctx,
_(
"Your hero is currently recovering from the last time "
"they used this skill or they have just changed their heroclass. "
"Try again in {}."
).format(
humanize_timedelta(seconds=int(cooldown_time)) if int(cooldown_time) >= 1 else _("1 second")
),
).format(f"<t:{cooldown_time}:R>"),
)

@commands.max_concurrency(1, per=commands.BucketType.user)
Expand Down Expand Up @@ -899,7 +887,7 @@ async def forge(self, ctx: commands.Context):
if "cooldown" not in c.heroclass:
c.heroclass["cooldown"] = cooldown_time + 1
if c.heroclass["cooldown"] > time.time():
cooldown_time = c.heroclass["cooldown"] - time.time()
cooldown_time = c.heroclass["cooldown"]
return await smart_embed(
ctx,
_("This command is on cooldown. Try again in {}").format(
Expand Down
2 changes: 2 additions & 0 deletions adventure/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def char_slot(self):

@classmethod
def get_from_name(cls, name: str) -> Slot:
if name.lower() == "twohanded":
return Slot.two_handed
for i in cls:
if " " in name:
name = name.replace(" ", "_")
Expand Down
Loading

0 comments on commit f28512e

Please sign in to comment.