Skip to content

Commit

Permalink
Apply rebalance
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Mar 8, 2024
1 parent 0e2373e commit 4463bc0
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 158 deletions.
238 changes: 117 additions & 121 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"use-local-osu-module": "npm i ../osu-droid-module/packages/osu-base ../osu-droid-module/packages/osu-difficulty-calculator ../osu-droid-module/packages/osu-droid-replay-analyzer ../osu-droid-module/packages/osu-droid-utilities ../osu-droid-module/packages/osu-rebalance-difficulty-calculator ../osu-droid-module/packages/osu-strain-graph-generator"
},
"engines": {
"node": "18.x"
"node": ">=18.x"
},
"keywords": [
"discordjs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Constants } from "@alice-core/Constants";
import { DatabaseManager } from "@alice-database/DatabaseManager";
import { UserBindCollectionManager } from "@alice-database/managers/elainaDb/UserBindCollectionManager";
import { UserBind } from "@alice-database/utils/elainaDb/UserBind";
import { SlashSubcommand } from "structures/core/SlashSubcommand";
import { DatabaseUserBind } from "structures/database/elainaDb/DatabaseUserBind";
Expand All @@ -10,18 +9,16 @@ import { MessageCreator } from "@alice-utils/creators/MessageCreator";
import { CommandHelper } from "@alice-utils/helpers/CommandHelper";
import { DPPHelper } from "@alice-utils/helpers/DPPHelper";
import { InteractionHelper } from "@alice-utils/helpers/InteractionHelper";
import { Snowflake } from "discord.js";
import { FindOptions } from "mongodb";

export const run: SlashSubcommand<true>["run"] = async (_, interaction) => {
const localization: PPLocalization = new PPLocalization(
const localization = new PPLocalization(
await CommandHelper.getLocale(interaction),
);

const discordid: Snowflake | undefined =
interaction.options.getUser("user")?.id;
const uid: number | null = interaction.options.getInteger("uid");
const username: string | null = interaction.options.getString("username");
const discordid = interaction.options.getUser("user")?.id;
const uid = interaction.options.getInteger("uid");
const username = interaction.options.getString("username");

if ([discordid, uid, username].filter(Boolean).length > 1) {
interaction.ephemeral = true;
Expand All @@ -33,8 +30,7 @@ export const run: SlashSubcommand<true>["run"] = async (_, interaction) => {
});
}

const dbManager: UserBindCollectionManager =
DatabaseManager.elainaDb.collections.userBind;
const dbManager = DatabaseManager.elainaDb.collections.userBind;

let playerInfo: UserBind | null;

Expand All @@ -43,6 +39,7 @@ export const run: SlashSubcommand<true>["run"] = async (_, interaction) => {
_id: 0,
uid: 1,
username: 1,
playc: 1,
pp: 1,
pptotal: 1,
},
Expand Down
1 change: 1 addition & 0 deletions src/interactions/contextmenus/user/viewDPPProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const run: UserContextMenuCommand["run"] = async (_, interaction) => {
_id: 0,
uid: 1,
username: 1,
playc: 1,
pp: 1,
pptotal: 1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface EmbedCreatorStrings {
readonly ppProfileTitle: string; // see PrototypecheckLocalization
readonly totalPP: string;
readonly ppProfile: string;
readonly totalPPNoBonus: string;
readonly warningInfo: string;
readonly warnedUser: string;
readonly warningId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class EmbedCreatorENTranslation extends Translation<EmbedCreatorStrings>
musicQueuer: "Queued/requested by %s",
ppProfileTitle: "PP Profile for %s",
totalPP: "Total PP",
totalPPNoBonus: "Total PP (excluding bonus)",
ppProfile: "PP Profile",
warningInfo: "Warning Info",
warningId: "Warning ID",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class EmbedCreatorESTranslation extends Translation<EmbedCreatorStrings>
musicQueuer: "Solicitado por %s",
ppProfileTitle: "Perfil de PP de %s",
totalPP: "PP total",
totalPPNoBonus: "PP total (sin bonus)",
ppProfile: "Perfil de Rendimiento (PP)",
warningInfo: "",
warnedUser: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class EmbedCreatorIDTranslation extends Translation<EmbedCreatorStrings>
musicQueuer: "Dimasukkan oleh %s",
ppProfileTitle: "Profil PP untuk %s",
totalPP: "Total PP",
totalPPNoBonus: "Total PP (tidak termasuk bonus)",
ppProfile: "Profil PP",
warningInfo: "Info Peringatan",
warningId: "ID Peringatan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class EmbedCreatorKRTranslation extends Translation<EmbedCreatorStrings>
musicQueuer: "%s에 의해 요청됨/재생목록에 넣어짐",
ppProfileTitle: "%s의 PP 프로필",
totalPP: "총 PP",
totalPPNoBonus: "총 PP(보너스 제외)",
ppProfile: "PP 프로필",
warningInfo: "",
warningId: "",
Expand Down
8 changes: 8 additions & 0 deletions src/utils/creators/EmbedCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { DPPProcessorRESTManager } from "@alice-utils/managers/DPPProcessorRESTM
import { PPCalculationMethod } from "@alice-enums/utils/PPCalculationMethod";
import { RecentPlay } from "@alice-database/utils/aliceDb/RecentPlay";
import { NormalEmbedOptions } from "@alice-structures/utils/NormalEmbedOptions";
import { DPPHelper } from "@alice-utils/helpers/DPPHelper";

/**
* Utility to create message embeds.
Expand Down Expand Up @@ -253,6 +254,10 @@ export abstract class EmbedCreator {
playerInfo.pptotal,
);

const bonusPP = DPPHelper.calculateBonusPerformancePoints(
playerInfo.playc,
);

embed.setDescription(
`${bold(
`${StringHelper.formatString(
Expand All @@ -269,6 +274,9 @@ export abstract class EmbedCreator {
LocaleHelper.convertToBCP47(language),
)})`,
)}\n` +
`${localization.getTranslation("totalPPNoBonus")}: ${bold(
`${(playerInfo.pptotal - bonusPP).toFixed(2)} pp`,
)} (-${bonusPP.toFixed(2)} pp)\n` +
`${localization.getTranslation(
"recommendedStarRating",
)}: ${bold(
Expand Down
53 changes: 26 additions & 27 deletions src/utils/helpers/DPPHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ import {
OsuDifficultyAttributes as RebalanceOsuDifficultyAttributes,
} from "@rian8337/osu-rebalance-difficulty-calculator";
import { Score } from "@rian8337/osu-droid-utilities";
import {
Collection,
EmbedBuilder,
RepliableInteraction,
Snowflake,
underscore,
} from "discord.js";
import { Collection, RepliableInteraction, underscore } from "discord.js";
import { CommandHelper } from "./CommandHelper";
import { NumberHelper } from "./NumberHelper";
import { DroidPerformanceAttributes } from "@alice-structures/difficultyattributes/DroidPerformanceAttributes";
Expand All @@ -41,7 +35,7 @@ export abstract class DPPHelper {
/**
* The ID of the role that permits pp-related moderation actions.
*/
static readonly ppModeratorRole: Snowflake = "551662194270404644";
static readonly ppModeratorRole = "551662194270404644";

/**
* Checks a beatmap's submission validity.
Expand All @@ -66,7 +60,7 @@ export abstract class DPPHelper {
static async checkSubmissionValidity(
beatmapOrScore: Score | MapInfo,
): Promise<DPPSubmissionValidity> {
const beatmapInfo: MapInfo | null =
const beatmapInfo =
beatmapOrScore instanceof MapInfo
? beatmapOrScore
: await BeatmapManager.getBeatmap(beatmapOrScore.hash, {
Expand Down Expand Up @@ -114,23 +108,23 @@ export abstract class DPPHelper {
playerInfo: UserBind,
page: number,
): Promise<void> {
const ppRank: number =
const ppRank =
await DatabaseManager.elainaDb.collections.userBind.getUserDPPRank(
playerInfo.pptotal,
);

const embed: EmbedBuilder = await EmbedCreator.createDPPListEmbed(
const embed = await EmbedCreator.createDPPListEmbed(
interaction,
playerInfo,
ppRank,
await CommandHelper.getLocale(interaction),
);

const list: PPEntry[] = [...playerInfo.pp.values()];
const list = [...playerInfo.pp.values()];

const onPageChange: OnButtonPageChange = async (_, page) => {
for (let i = 5 * (page - 1); i < 5 + 5 * (page - 1); ++i) {
const pp: PPEntry | undefined = list[i];
const pp = list.at(i);

if (pp) {
let modstring = pp.mods ? `+${pp.mods}` : "";
Expand Down Expand Up @@ -197,7 +191,7 @@ export abstract class DPPHelper {
dppList: Collection<string, PPEntry>,
entries: PPEntry[],
): boolean[] {
let needsSorting: boolean = false;
let needsSorting = false;

for (const entry of entries) {
if (isNaN(entry.pp)) {
Expand All @@ -220,13 +214,10 @@ export abstract class DPPHelper {
dppList.sort((a, b) => b.pp - a.pp);
}

const wasInserted: boolean[] = Utils.initializeArray(
entries.length,
true,
);
const wasInserted = Utils.initializeArray(entries.length, true);

while (dppList.size > 75) {
const lastEntry: PPEntry = dppList.last()!;
const lastEntry = dppList.last()!;

for (let i = 0; i < entries.length; ++i) {
if (lastEntry.hash !== entries[i].hash) {
Expand Down Expand Up @@ -345,19 +336,27 @@ export abstract class DPPHelper {
.sort((a, b) => b.pp - a.pp)
.reduce((a, v, i) => a + v.pp * Math.pow(0.95, i), 0) +
// Bonus pp portion
// TODO: uncomment this after rebalance
// (1250 / 3) * (1 - Math.pow(0.9992, playCount))
0
this.calculateBonusPerformancePoints(playCount)
);
}

/**
* Calculates the bonus performance points of a player.
*
* @param playCount The play count of the player.
* @returns The bonus performance points.
*/
static calculateBonusPerformancePoints(playCount: number): number {
return (1250 / 3) * (1 - Math.pow(0.9992, playCount));
}

/**
* Deletes a beatmap with specific hash from all players.
*
* @param hash The beatmap's hash.
*/
static async deletePlays(hash: string): Promise<void> {
const toUpdateList: Collection<string, UserBind> =
const toUpdateList =
await DatabaseManager.elainaDb.collections.userBind.get(
"discordid",
{ "pp.hash": hash },
Expand Down Expand Up @@ -456,7 +455,7 @@ export abstract class DPPHelper {
| OsuDifficultyAttributes
| CacheableDifficultyAttributes<OsuDifficultyAttributes>,
): string {
let string: string = `${attributes.starRating.toFixed(2)} stars (`;
let string = `${attributes.starRating.toFixed(2)} stars (`;
const starRatingDetails: string[] = [];

const addDetail = (num: number, suffix: string) =>
Expand All @@ -482,7 +481,7 @@ export abstract class DPPHelper {
| RebalanceOsuDifficultyAttributes
| ResponseDifficultyAttributes<RebalanceOsuDifficultyAttributes>,
): string {
let string: string = `${attributes.starRating.toFixed(2)} stars (`;
let string = `${attributes.starRating.toFixed(2)} stars (`;
const starRatingDetails: string[] = [];

const addDetail = (num: number, suffix: string) =>
Expand All @@ -506,7 +505,7 @@ export abstract class DPPHelper {
static getDroidPerformanceAttributesInfo(
attributes: DroidPerformanceAttributes,
): string {
let string: string = `${attributes.total.toFixed(2)} pp (`;
let string = `${attributes.total.toFixed(2)} pp (`;
const starRatingDetails: string[] = [];

const addDetail = (num: number, suffix: string) =>
Expand All @@ -532,7 +531,7 @@ export abstract class DPPHelper {
static getOsuPerformanceAttributesInfo(
attributes: OsuPerformanceAttributes,
): string {
let string: string = `${attributes.total.toFixed(2)} pp (`;
let string = `${attributes.total.toFixed(2)} pp (`;
const starRatingDetails: string[] = [];

const addDetail = (num: number, suffix: string) =>
Expand Down

0 comments on commit 4463bc0

Please sign in to comment.