From 4b47a5a424390b15dd3dc653323e7c7d633c6037 Mon Sep 17 00:00:00 2001 From: BastLast Date: Mon, 13 Jan 2025 19:12:52 +0100 Subject: [PATCH] split glorypoints in attack & defense #2276 --- .../Fight/GloryPointsTestCommand.ts | 11 +- Core/src/commands/player/FightCommand.ts | 146 +++++++++--------- Core/src/commands/player/ProfileCommand.ts | 2 +- Core/src/commands/player/ReportCommand.ts | 2 +- Core/src/core/database/game/models/Player.ts | 22 ++- Core/src/core/database/logs/LogsDatabase.ts | 2 +- Core/src/core/fights/fighter/PlayerFighter.ts | 7 +- .../core/missions/interfaces/reachGlory.ts | 2 +- Discord/src/commands/player/FightCommand.ts | 2 +- 9 files changed, 108 insertions(+), 88 deletions(-) diff --git a/Core/src/commands/admin/testCommands/Fight/GloryPointsTestCommand.ts b/Core/src/commands/admin/testCommands/Fight/GloryPointsTestCommand.ts index 95074e420..d7da7f24c 100644 --- a/Core/src/commands/admin/testCommands/Fight/GloryPointsTestCommand.ts +++ b/Core/src/commands/admin/testCommands/Fight/GloryPointsTestCommand.ts @@ -6,9 +6,10 @@ export const commandInfo: ITestCommand = { aliases: ["glory"], commandFormat: "", typeWaited: { - points: TypeKey.INTEGER + "points": TypeKey.INTEGER, + "type (0 = defensif 1 = attack)": TypeKey.INTEGER }, - description: "Mets les glory points votre joueur à la valeur donnée" + description: "Mets les glory points d'attaque ou de défense votre joueur à la valeur donnée" }; /** @@ -16,13 +17,15 @@ export const commandInfo: ITestCommand = { */ const gloryPointsTestCommand: ExecuteTestCommandLike = async (player, args, response) => { const gloryPoints = parseInt(args[0], 10); + const type = parseInt(args[1], 10) + if (gloryPoints < 0) { throw new Error("Erreur glory points : glory points inférieurs à 0 interdits !"); } - await player.setGloryPoints(gloryPoints, NumberChangeReason.TEST, response); + await player.setGloryPoints(gloryPoints, type===0, NumberChangeReason.TEST, response); await player.save(); - return `Vous avez maintenant ${player.gloryPoints} :sparkles: !`; + return `Vous avez maintenant ${player.getGloryPoints()} :sparkles: !`; }; commandInfo.execute = gloryPointsTestCommand; \ No newline at end of file diff --git a/Core/src/commands/player/FightCommand.ts b/Core/src/commands/player/FightCommand.ts index 7374d8eb9..607b4979f 100644 --- a/Core/src/commands/player/FightCommand.ts +++ b/Core/src/commands/player/FightCommand.ts @@ -6,90 +6,98 @@ import {ReactionCollectorFight} from "../../../../Lib/src/packets/interaction/Re import {EndCallback, ReactionCollectorInstance} from "../../core/utils/ReactionsCollector"; import {ReactionCollectorAcceptReaction} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; import { - CommandFightPacketReq, - CommandFightRefusePacketRes + CommandFightPacketReq, + CommandFightRefusePacketRes } from "../../../../Lib/src/packets/commands/CommandFightPacket"; import {BlockingConstants} from "../../../../Lib/src/constants/BlockingConstants"; import {InventorySlots} from "../../core/database/game/models/InventorySlot"; type PlayerStats = { - classId: number, - fightRanking: { - glory: number, - } - energy: { - value: number, - max: number - }, - attack: number, - defense: number, - speed: number - breath: { - base: number, - max: number, - regen: number - } + classId: number, + fightRanking: { + glory: number, + } + energy: { + value: number, + max: number + }, + attack: number, + defense: number, + speed: number + breath: { + base: number, + max: number, + regen: number + } } async function getPlayerStats(player: Player): Promise { - const playerActiveObjects = await InventorySlots.getMainSlotsItems(player.id); - return { - classId: player.class, - fightRanking: { - glory: player.gloryPoints - }, - energy: { - value: player.getCumulativeFightPoint(), - max: player.getMaxCumulativeFightPoint() - }, - attack: player.getCumulativeAttack(playerActiveObjects), - defense: player.getCumulativeDefense(playerActiveObjects), - speed: player.getCumulativeSpeed(playerActiveObjects), - breath: { - base: player.getBaseBreath(), - max: player.getMaxBreath(), - regen: player.getBreathRegen() - } - }; + const playerActiveObjects = await InventorySlots.getMainSlotsItems(player.id); + return { + classId: player.class, + fightRanking: { + glory: player.getGloryPoints() + }, + energy: { + value: player.getCumulativeFightPoint(), + max: player.getMaxCumulativeFightPoint() + }, + attack: player.getCumulativeAttack(playerActiveObjects), + defense: player.getCumulativeDefense(playerActiveObjects), + speed: player.getCumulativeSpeed(playerActiveObjects), + breath: { + base: player.getBaseBreath(), + max: player.getMaxBreath(), + regen: player.getBreathRegen() + } + }; } +/** + * Find another player to fight the player that started the command + * @param player + * @returns player opponent + */ +function findOpponent(player: Player): Player { + + return +} export default class FightCommand { - @commandRequires(CommandFightPacketReq, { - notBlocked: true, - disallowedEffects: CommandUtils.DISALLOWED_EFFECTS.NOT_STARTED_OR_DEAD, - level: FightConstants.REQUIRED_LEVEL - }) - async execute(response: DraftBotPacket[], player: Player, packet: CommandFightPacketReq, context: PacketContext): Promise { - const toCheckPlayer = await Players.getAskedPlayer({keycloakId: packet.playerKeycloakId}, player); + @commandRequires(CommandFightPacketReq, { + notBlocked: true, + disallowedEffects: CommandUtils.DISALLOWED_EFFECTS.NOT_STARTED_OR_DEAD, + level: FightConstants.REQUIRED_LEVEL + }) + async execute(response: DraftBotPacket[], player: Player, packet: CommandFightPacketReq, context: PacketContext): Promise { + const toCheckPlayer = await Players.getAskedPlayer({keycloakId: packet.playerKeycloakId}, player); - const collector = new ReactionCollectorFight( - await getPlayerStats(toCheckPlayer) - ); + const collector = new ReactionCollectorFight( + await getPlayerStats(toCheckPlayer) + ); - const endCallback: EndCallback = async (collector: ReactionCollectorInstance, response: DraftBotPacket[]): Promise => { - const reaction = collector.getFirstReaction(); - if (reaction && reaction.reaction.type === ReactionCollectorAcceptReaction.name) { - // Acceptation du fight/matchmaking - } - else { - response.push(makePacket(CommandFightRefusePacketRes, {})); - } - }; + const endCallback: EndCallback = async (collector: ReactionCollectorInstance, response: DraftBotPacket[]): Promise => { + const reaction = collector.getFirstReaction(); + if (reaction && reaction.reaction.type === ReactionCollectorAcceptReaction.name) { + // Acceptation du fight/matchmaking + } else { + response.push(makePacket(CommandFightRefusePacketRes, {})); + } + }; - const collectorPacket = new ReactionCollectorInstance( - collector, - context, - { - allowedPlayerKeycloakIds: [player.keycloakId], - reactionLimit: 1 - }, - endCallback - ) - .block(player.id, BlockingConstants.REASONS.FIGHT_CONFIRMATION) - .build(); + const collectorPacket = new ReactionCollectorInstance( + collector, + context, + { + allowedPlayerKeycloakIds: [player.keycloakId], + reactionLimit: 1 + }, + endCallback + ) + .block(player.id, BlockingConstants.REASONS.FIGHT_CONFIRMATION) + .build(); - response.push(collectorPacket); - } + response.push(collectorPacket); + } } diff --git a/Core/src/commands/player/ProfileCommand.ts b/Core/src/commands/player/ProfileCommand.ts index b185e4c75..de2fb5f83 100644 --- a/Core/src/commands/player/ProfileCommand.ts +++ b/Core/src/commands/player/ProfileCommand.ts @@ -76,7 +76,7 @@ export default class ProfileCommand { hasTimeDisplay: toCheckPlayer.isUnderEffect() }, fightRanking: toCheckPlayer.level >= FightConstants.REQUIRED_LEVEL ? { - glory: toCheckPlayer.gloryPoints, + glory: toCheckPlayer.getGloryPoints(), league: toCheckPlayer.getLeague().id } : null, missions: { diff --git a/Core/src/commands/player/ReportCommand.ts b/Core/src/commands/player/ReportCommand.ts index b11e25130..c8f4c8901 100644 --- a/Core/src/commands/player/ReportCommand.ts +++ b/Core/src/commands/player/ReportCommand.ts @@ -559,7 +559,7 @@ async function doPVEBoss( } const playerFighter = new PlayerFighter(player, ClassDataController.instance.getById(player.class)); - await playerFighter.loadStats(true); + await playerFighter.loadStats(); playerFighter.setBaseFightPoints(playerFighter.getMaxFightPoints() - player.fightPointsLost); const fight = new FightController( diff --git a/Core/src/core/database/game/models/Player.ts b/Core/src/core/database/game/models/Player.ts index 0008ba8f2..015db793e 100644 --- a/Core/src/core/database/game/models/Player.ts +++ b/Core/src/core/database/game/models/Player.ts @@ -109,7 +109,9 @@ export class Player extends Model { declare notifications: string; - declare gloryPoints: number; + declare defenseGloryPoints: number; + + declare attackGloryPoints: number; declare gloryPointsLastSeason: number; @@ -253,6 +255,13 @@ export class Player extends Model { return this.addMoney(parameters); } + /** + * Return the value of glory that is displayed to the users + */ + public getGloryPoints(): number { + return this.attackGloryPoints + this.defenseGloryPoints + } + /** * Check if a player needs to level up */ @@ -819,7 +828,7 @@ export class Player extends Model { * Get the league of the player */ public getLeague(): League { - return LeagueDataController.instance.getByGlory(this.gloryPoints); + return LeagueDataController.instance.getByGlory(this.getGloryPoints()); } /** @@ -832,19 +841,20 @@ export class Player extends Model { /** * Set the glory points of the player * @param gloryPoints + * @param isDefense - true if the points to set are the defense Glory points * @param reason * @param response * @param fightId * @private */ - public async setGloryPoints(gloryPoints: number, reason: NumberChangeReason, response: DraftBotPacket[], fightId: number = null): Promise { + public async setGloryPoints(gloryPoints: number, isDefense: boolean, reason: NumberChangeReason, response: DraftBotPacket[], fightId: number = null): Promise { + await draftBotInstance.logsDatabase.logPlayersGloryPoints(this.keycloakId, gloryPoints, reason, fightId); + isDefense? this.defenseGloryPoints = gloryPoints: this.attackGloryPoints = gloryPoints; Object.assign(this, await MissionsController.update(this, response, { missionId: "reachGlory", - count: gloryPoints, + count: this.getGloryPoints(), set: true })); - await draftBotInstance.logsDatabase.logPlayersGloryPoints(this.keycloakId, gloryPoints, reason, fightId); - this.gloryPoints = gloryPoints; } /** diff --git a/Core/src/core/database/logs/LogsDatabase.ts b/Core/src/core/database/logs/LogsDatabase.ts index 259d1ff1c..c2ee560fb 100644 --- a/Core/src/core/database/logs/LogsDatabase.ts +++ b/Core/src/core/database/logs/LogsDatabase.ts @@ -1246,7 +1246,7 @@ export class LogsDatabase extends Database { await LogsPlayers15BestSeason.create({ playerId: player.id, position: i + 1, - seasonGlory: players[i].gloryPoints, + seasonGlory: players[i].getGloryPoints(), date: now }); } diff --git a/Core/src/core/fights/fighter/PlayerFighter.ts b/Core/src/core/fights/fighter/PlayerFighter.ts index 14c25b3c8..80cb778f1 100644 --- a/Core/src/core/fights/fighter/PlayerFighter.ts +++ b/Core/src/core/fights/fighter/PlayerFighter.ts @@ -87,12 +87,11 @@ export class PlayerFighter extends Fighter { /** * The fighter loads its various stats - * @param friendly true if the fight is friendly * @public */ - public async loadStats(friendly: boolean): Promise { + public async loadStats(): Promise { const playerActiveObjects: PlayerActiveObjects = await InventorySlots.getPlayerActiveObjects(this.player.id); - this.stats.fightPoints = friendly ? this.player.getMaxCumulativeFightPoint() : this.player.getCumulativeFightPoint(); + this.stats.fightPoints = this.player.getCumulativeFightPoint(); this.stats.maxFightPoint = this.player.getMaxCumulativeFightPoint(); this.stats.attack = this.player.getCumulativeAttack(playerActiveObjects); this.stats.defense = this.player.getCumulativeDefense(playerActiveObjects); @@ -100,7 +99,7 @@ export class PlayerFighter extends Fighter { this.stats.breath = this.player.getBaseBreath(); this.stats.maxBreath = this.player.getMaxBreath(); this.stats.breathRegen = this.player.getBreathRegen(); - this.glory = this.player.gloryPoints; + this.glory = this.player.getGloryPoints(); } /** diff --git a/Core/src/core/missions/interfaces/reachGlory.ts b/Core/src/core/missions/interfaces/reachGlory.ts index c5129836a..c65f4c295 100644 --- a/Core/src/core/missions/interfaces/reachGlory.ts +++ b/Core/src/core/missions/interfaces/reachGlory.ts @@ -5,7 +5,7 @@ export const missionInterface: IMission = { generateRandomVariant: () => 0, - initialNumberDone: (player) => player.gloryPoints, + initialNumberDone: (player) => player.getGloryPoints(), updateSaveBlob: () => null }; \ No newline at end of file diff --git a/Discord/src/commands/player/FightCommand.ts b/Discord/src/commands/player/FightCommand.ts index 99c90e5ae..c8f355d73 100644 --- a/Discord/src/commands/player/FightCommand.ts +++ b/Discord/src/commands/player/FightCommand.ts @@ -32,7 +32,7 @@ export async function createFightCollector(packet: ReactionCollectorCreationPack i18n.t("commands:fight.confirmDesc", { lng: interaction.userLanguage, pseudo: interaction.user.displayName, - confirmSubText: i18n.t("commands:fight.confirmSubTexts."+ subTextKey, { + confirmSubText: i18n.t(`commands:fight.confirmSubTexts.${subTextKey}`, { lng: interaction.userLanguage }), glory: i18n.t("commands:fight:information.glory", {