Skip to content

Commit

Permalink
feat(megawalls): add new megawalls kits and update class points (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobk999 committed Jun 22, 2024
1 parent 82f095e commit 35f0131
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 127 deletions.
11 changes: 7 additions & 4 deletions apps/discord-bot/src/commands/historical/historical.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { CopsAndCrimsProfile } from "../copsandcrims/copsandcrims.profile.js";
import { DuelsProfile } from "../duels/duels.profile.js";
import { GamesWithBackgrounds } from "#constants";
import { HistoricalGeneralProfile } from "../general/historical-general.profile.js";
import { MegaWallsProfile } from "../megawalls/megawalls.profile.js";
import { MegaWallsProfile, filterMegaWallsKits } from "../megawalls/megawalls.profile.js";
import { MurderMysteryProfile } from "../murdermystery/murdermystery.profile.js";
import { PaintballProfile } from "../paintball/paintball.profile.js";
import { PitProfile } from "../pit/pit.profile.js";
Expand Down Expand Up @@ -161,9 +161,12 @@ export class HistoricalBase {

@SubCommand({ description: (t) => t("commands.historical-megawalls"), args })
public megawalls(context: CommandContext) {
return this.run(context, MEGAWALLS_MODES, (base, mode) => (
<MegaWallsProfile {...base} mode={mode} />
));
return this.run(
context,
MEGAWALLS_MODES,
(base, mode) => <MegaWallsProfile {...base} mode={mode} />,
filterMegaWallsKits
);
}

@SubCommand({ description: (t) => t("commands.historical-murdermystery"), args })
Expand Down
41 changes: 22 additions & 19 deletions apps/discord-bot/src/commands/historical/session.command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
MURDER_MYSTERY_MODES,
PAINTBALL_MODES,
PIT_MODES,
Player,
type Player,
QUAKE_MODES,
SKYWARS_MODES,
SMASH_HEROES_MODES,
Expand Down Expand Up @@ -53,10 +53,10 @@ import { BuildBattleProfile } from "../buildbattle/buildbattle.profile.js";
import { CopsAndCrimsProfile } from "../copsandcrims/copsandcrims.profile.js";
import { DateTime } from "luxon";
import { DuelsProfile } from "../duels/duels.profile.js";
import { GamesWithBackgrounds, mapBackground } from "#constants";
import { type GamesWithBackgrounds, mapBackground } from "#constants";
import { HistoricalGeneralProfile } from "../general/historical-general.profile.js";
import { HistoricalTimes } from "@statsify/api-client";
import { MegaWallsProfile } from "../megawalls/megawalls.profile.js";
import { MegaWallsProfile, filterMegaWallsKits } from "../megawalls/megawalls.profile.js";
import { MurderMysteryProfile } from "../murdermystery/murdermystery.profile.js";
import { PaintballProfile } from "../paintball/paintball.profile.js";
import { PitProfile } from "../pit/pit.profile.js";
Expand All @@ -83,7 +83,7 @@ export class SessionCommand {
private readonly paginateService: PaginateService
) {}

@SubCommand({ description: (t) => t("commands.session-arcade"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-arcade"), args: [PlayerArgument] })
public arcade(context: CommandContext) {
return this.run(context, ARCADE_MODES, (base, mode) => (
<ArcadeProfile {...base} mode={mode} />
Expand All @@ -101,14 +101,14 @@ export class SessionCommand {
));
}

@SubCommand({ description: (t) => t("commands.session-bedwars"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-bedwars"), args: [PlayerArgument] })
public bedwars(context: CommandContext) {
return this.run(context, BEDWARS_MODES, (base, mode) => (
<BedWarsProfile {...base} mode={mode} />
));
}

@SubCommand({ description: (t) => t("commands.session-bridge"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-bridge"), args: [PlayerArgument] })
public bridge(context: CommandContext) {
return this.run(context, BRIDGE_MODES, (base, mode) => (
<BridgeProfile {...base} mode={mode} />
Expand All @@ -125,14 +125,14 @@ export class SessionCommand {
);
}

@SubCommand({ description: (t) => t("commands.session-buildbattle"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-buildbattle"), args: [PlayerArgument] })
public buildbattle(context: CommandContext) {
return this.run(context, BUILD_BATTLE_MODES, (base) => (
<BuildBattleProfile {...base} />
));
}

@SubCommand({ description: (t) => t("commands.session-copsandcrims"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-copsandcrims"), args: [PlayerArgument] })
public copsandcrims(context: CommandContext) {
return this.run(context, COPS_AND_CRIMS_MODES, (base, mode) => (
<CopsAndCrimsProfile {...base} mode={mode} />
Expand All @@ -153,14 +153,17 @@ export class SessionCommand {
));
}

@SubCommand({ description: (t) => t("commands.session-megawalls"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-megawalls"), args: [PlayerArgument] })
public megawalls(context: CommandContext) {
return this.run(context, MEGAWALLS_MODES, (base, mode) => (
<MegaWallsProfile {...base} mode={mode} />
));
return this.run(
context,
MEGAWALLS_MODES,
(base, mode) => <MegaWallsProfile {...base} mode={mode} />,
filterMegaWallsKits
);
}

@SubCommand({ description: (t) => t("commands.session-murdermystery"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-murdermystery"), args: [PlayerArgument] })
public murdermystery(context: CommandContext) {
return this.run(context, MURDER_MYSTERY_MODES, (base, mode) => (
<MurderMysteryProfile {...base} mode={mode} />
Expand All @@ -176,7 +179,7 @@ export class SessionCommand {
return this.run(context, PAINTBALL_MODES, (base) => <PaintballProfile {...base} />);
}

@SubCommand({ description: (t) => t("commands.session-pit"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-pit"), args: [PlayerArgument] })
public pit(context: CommandContext) {
return this.run(context, PIT_MODES, (base) => <PitProfile {...base} />);
}
Expand All @@ -192,28 +195,28 @@ export class SessionCommand {
));
}

@SubCommand({ description: (t) => t("commands.session-skywars"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-skywars"), args: [PlayerArgument] })
public skywars(context: CommandContext) {
return this.run(context, SKYWARS_MODES, (base, mode) => (
<SkyWarsProfile {...base} mode={mode} />
));
}

@SubCommand({ description: (t) => t("commands.session-smashheroes"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-smashheroes"), args: [PlayerArgument] })
public smashheroes(context: CommandContext) {
return this.run(context, SMASH_HEROES_MODES, (base, mode) => (
<SmashHeroesProfile {...base} mode={mode} />
));
}

@SubCommand({ description: (t) => t("commands.session-speeduhc"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-speeduhc"), args: [PlayerArgument] })
public speeduhc(context: CommandContext) {
return this.run(context, SPEED_UHC_MODES, (base, mode) => (
<SpeedUHCProfile {...base} mode={mode} />
));
}

@SubCommand({ description: (t) => t("commands.session-tntgames"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-tntgames"), args: [PlayerArgument] })
public tntgames(context: CommandContext) {
return this.run(context, TNT_GAMES_MODES, (base) => <TNTGamesProfile {...base} />);
}
Expand Down Expand Up @@ -256,7 +259,7 @@ export class SessionCommand {
return this.run(context, WALLS_MODES, (base) => <WallsProfile {...base} />);
}

@SubCommand({ description: (t) => t("commands.session-warlords"), args: [PlayerArgument] })
@SubCommand({ description: (t) => t("commands.session-warlords"), args: [PlayerArgument] })
public warlords(context: CommandContext) {
return this.run(context, WARLORDS_MODES, (base, mode) => (
<WarlordsProfile {...base} mode={mode} />
Expand Down
11 changes: 9 additions & 2 deletions apps/discord-bot/src/commands/megawalls/megawalls.command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ import {
ProfileData,
} from "#commands/base.hypixel-command";
import { Command } from "@statsify/discord";
import { MEGAWALLS_MODES, MegaWallsModes } from "@statsify/schemas";
import { MegaWallsProfile } from "./megawalls.profile.js";
import { GameMode, MEGAWALLS_MODES, MegaWallsModes, Player } from "@statsify/schemas";
import { MegaWallsProfile, filterMegaWallsKits } from "./megawalls.profile.js";

@Command({ description: (t) => t("commands.megawalls") })
export class MegaWallsCommand extends BaseHypixelCommand<MegaWallsModes> {
public constructor() {
super(MEGAWALLS_MODES);
}

public filterModes(
player: Player,
modes: GameMode<MegaWallsModes>[]
): GameMode<MegaWallsModes>[] {
return filterMegaWallsKits(player, modes);
}

public getProfile(
base: BaseProfileProps,
{ mode }: ProfileData<MegaWallsModes, never>
Expand Down
16 changes: 15 additions & 1 deletion apps/discord-bot/src/commands/megawalls/megawalls.profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Container, Footer, Header, SidebarItem, Table } from "#components";
import { FormattedGame, GameMode, MegaWallsModes } from "@statsify/schemas";
import { FormattedGame, GameMode, MegaWallsModes, Player } from "@statsify/schemas";
import { formatTime, prettify } from "@statsify/util";
import type { BaseProfileProps } from "#commands/base.hypixel-command";

Expand Down Expand Up @@ -98,3 +98,17 @@ export const MegaWallsProfile = ({
</Container>
);
};

export function filterMegaWallsKits(
player: Player,
modes: GameMode<MegaWallsModes>[]
): GameMode<MegaWallsModes>[] {
const { megawalls } = player.stats;
const [overall, ...kits] = modes;

const filteredKits = [...kits]
.sort((a, b) => megawalls[b.api].points - megawalls[a.api].points)
.slice(0, 24);

return [overall, ...filteredKits];
}
2 changes: 1 addition & 1 deletion apps/discord-bot/src/commands/minecraft/text.command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class TextCommand {
const size = Math.min(context.option<number>("size", 2), 9);
const alignment = context.option<StyleLocation>("alignment", "left");

const text = convertColorCodes(content).replaceAll("\\n", "\n");
const text = convertColorCodes(content).replaceAll(String.raw`\n`, "\n");

const canvas = render(
<div direction="column">
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot/src/lib/convert-color-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

export const convertColorCodes = (content: string) =>
content
.replaceAll("\\&", "󰀀")
.replaceAll(String.raw`\&`, "󰀀")
.replace(/&\S/g, (m) => m.replace("&", "§"))
.replaceAll("󰀀", "&");
2 changes: 1 addition & 1 deletion apps/support-bot/src/commands/tags.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class TagsCommand {
})
public async create(context: CommandContext): Promise<IMessage> {
const name = context.option<string>("name");
const content = context.option<string>("content").replaceAll("\\n", "\n");
const content = context.option<string>("content").replaceAll(String.raw`\n`, "\n");
const attachment = context.option<APIAttachment | null>("attachment");

if (
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"chokidar": "^3.5.3",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.47.0",
"eslint": "^8.56.0",
"eslint-plugin-license-header": "^0.6.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"eslint-plugin-unicorn": "^54.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/discord/src/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class ApiService extends StatsifyApiService {
}

public emojiDisplayName(t: LocalizeFunction, displayName: string, space = true) {
displayName = displayName.replaceAll("_", "\\_");
displayName = displayName.replaceAll("_", String.raw`\_`);

const [rank, name] = displayName.replace(/\[|\]/g, "").split(" ");

Expand Down
5 changes: 2 additions & 3 deletions packages/schemas/src/metadata/metadata-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ if (import.meta.vitest) {
const { prettify } = await import("@statsify/util");

const stringMetadata = (name: string): FieldMetadata => {
const fieldName = prettify(
name.slice(Math.max(0, name.lastIndexOf(".") > -1 ? name.lastIndexOf(".") + 1 : 0))
);
const lastIndexOfDot = name.lastIndexOf(".");
const fieldName = prettify(name.slice(Math.max(0, lastIndexOfDot > -1 ? lastIndexOfDot + 1 : 0)));

return {
leaderboard: {
Expand Down
44 changes: 15 additions & 29 deletions packages/schemas/src/player/gamemodes/megawalls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
import { Field } from "#metadata";
import { GameModes, type IGameModes } from "#game";
import { MegaWallsKit, MegaWallsOverall } from "./kit.js";
import { add } from "@statsify/math";
import type { APIData } from "@statsify/util";

export const MEGAWALLS_MODES = new GameModes([
{ api: "overall" },
{ api: "angel" },
{ api: "arcanist" },
{ api: "assassin" },
{ api: "automaton" },
{ api: "blaze" },
{ api: "cow" },
{ api: "creeper" },
{ api: "dragon" },
{ api: "dreadlord" },
{ api: "enderman" },
{ api: "golem" },
Expand All @@ -32,6 +33,7 @@ export const MEGAWALLS_MODES = new GameModes([
{ api: "renegade" },
{ api: "shaman" },
{ api: "shark" },
{ api: "sheep" },
{ api: "skeleton" },
{ api: "snowman" },
{ api: "spider" },
Expand All @@ -55,6 +57,9 @@ export class MegaWalls {
@Field()
public overall: MegaWallsOverall;

@Field({ store: { required: false } })
public angel: MegaWallsKit;

@Field({ store: { required: false } })
public arcanist: MegaWallsKit;

Expand All @@ -73,6 +78,9 @@ export class MegaWalls {
@Field({ store: { required: false } })
public creeper: MegaWallsKit;

@Field({ store: { required: false } })
public dragon: MegaWallsKit;

@Field({ store: { required: false } })
public dreadlord: MegaWallsKit;

Expand Down Expand Up @@ -109,6 +117,9 @@ export class MegaWalls {
@Field({ store: { required: false } })
public shark: MegaWallsKit;

@Field({ store: { required: false } })
public sheep: MegaWallsKit;

@Field({ store: { required: false } })
public skeleton: MegaWallsKit;

Expand All @@ -132,12 +143,14 @@ export class MegaWalls {
this.mythicFavor = data.mythic_favor;
this.class = data.chosen_class ?? "none";

this.angel = new MegaWallsKit(data, "angel");
this.arcanist = new MegaWallsKit(data, "arcanist");
this.assassin = new MegaWallsKit(data, "assassin");
this.automaton = new MegaWallsKit(data, "automaton");
this.blaze = new MegaWallsKit(data, "blaze");
this.cow = new MegaWallsKit(data, "cow");
this.creeper = new MegaWallsKit(data, "creeper");
this.dragon = new MegaWallsKit(data, "dragon");
this.dreadlord = new MegaWallsKit(data, "dreadlord");
this.enderman = new MegaWallsKit(data, "enderman");
this.golem = new MegaWallsKit(data, "golem");
Expand All @@ -150,41 +163,14 @@ export class MegaWalls {
this.renegade = new MegaWallsKit(data, "renegade");
this.shaman = new MegaWallsKit(data, "shaman");
this.shark = new MegaWallsKit(data, "shark");
this.sheep = new MegaWallsKit(data, "sheep");
this.skeleton = new MegaWallsKit(data, "skeleton");
this.snowman = new MegaWallsKit(data, "snowman");
this.spider = new MegaWallsKit(data, "spider");
this.squid = new MegaWallsKit(data, "squid");
this.werewolf = new MegaWallsKit(data, "werewolf");
this.zombie = new MegaWallsKit(data, "zombie");

this.overall = new MegaWallsOverall(data);

this.overall.points = add(
this.arcanist.points,
this.assassin.points,
this.automaton.points,
this.blaze.points,
this.cow.points,
this.creeper.points,
this.dreadlord.points,
this.enderman.points,
this.golem.points,
this.herobrine.points,
this.hunter.points,
this.moleman.points,
this.phoenix.points,
this.pigman.points,
this.pirate.points,
this.renegade.points,
this.shaman.points,
this.shark.points,
this.skeleton.points,
this.snowman.points,
this.spider.points,
this.squid.points,
this.werewolf.points,
this.zombie.points
);
}
}

Expand Down
Loading

0 comments on commit 35f0131

Please sign in to comment.