Skip to content

Commit

Permalink
split glorypoints in attack & defense #2276
Browse files Browse the repository at this point in the history
  • Loading branch information
BastLast committed Jan 13, 2025
1 parent 1446ae4 commit 4b47a5a
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ export const commandInfo: ITestCommand = {
aliases: ["glory"],
commandFormat: "<points>",
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"
};

/**
* Set the glory points of the player
*/
const gloryPointsTestCommand: ExecuteTestCommandLike = async (player, args, response) => {
const gloryPoints = parseInt(args[0], 10);
const type = parseInt(args[1], 10)

Check failure on line 20 in Core/src/commands/admin/testCommands/Fight/GloryPointsTestCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Missing semicolon

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);

Check warning on line 25 in Core/src/commands/admin/testCommands/Fight/GloryPointsTestCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Operator '===' must be spaced
await player.save();

return `Vous avez maintenant ${player.gloryPoints} :sparkles: !`;
return `Vous avez maintenant ${player.getGloryPoints()} :sparkles: !`;
};

commandInfo.execute = gloryPointsTestCommand;
146 changes: 77 additions & 69 deletions Core/src/commands/player/FightCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check failure on line 9 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 1 tab but found 4 spaces
CommandFightRefusePacketRes

Check failure on line 10 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 1 tab but found 4 spaces
} 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<PlayerStats> {
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);

Check failure on line 35 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 1 tab but found 4 spaces
return {

Check failure on line 36 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 1 tab but found 4 spaces
classId: player.class,

Check failure on line 37 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 2 tabs but found 8 spaces
fightRanking: {

Check failure on line 38 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 2 tabs but found 8 spaces
glory: player.getGloryPoints()

Check failure on line 39 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 3 tabs but found 12 spaces
},

Check failure on line 40 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 2 tabs but found 8 spaces
energy: {

Check failure on line 41 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Expected indentation of 2 tabs but found 8 spaces
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 {

Check failure on line 61 in Core/src/commands/player/FightCommand.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Core/src/commands/player/FightCommand.ts#L61

'findOpponent' is defined but never used.

return

Check warning on line 63 in Core/src/commands/player/FightCommand.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Core/src/commands/player/FightCommand.ts#L63

Unnecessary return statement.
}

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<void> {
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<void> {
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<void> => {
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<void> => {

Check warning on line 79 in Core/src/commands/player/FightCommand.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Core/src/commands/player/FightCommand.ts#L79

Async arrow function has no 'await' expression.
const reaction = collector.getFirstReaction();
if (reaction && reaction.reaction.type === ReactionCollectorAcceptReaction.name) {
// Acceptation du fight/matchmaking
} else {

Check warning on line 83 in Core/src/commands/player/FightCommand.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Closing curly brace appears on the same line as the subsequent block
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);
}
}

2 changes: 1 addition & 1 deletion Core/src/commands/player/ProfileCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion Core/src/commands/player/ReportCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 16 additions & 6 deletions Core/src/core/database/game/models/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ export class Player extends Model {

declare notifications: string;

declare gloryPoints: number;
declare defenseGloryPoints: number;

declare attackGloryPoints: number;

declare gloryPointsLastSeason: number;

Expand Down Expand Up @@ -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
*/
Expand Down Expand 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());
}

/**
Expand All @@ -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<void> {
public async setGloryPoints(gloryPoints: number, isDefense: boolean, reason: NumberChangeReason, response: DraftBotPacket[], fightId: number = null): Promise<void> {
await draftBotInstance.logsDatabase.logPlayersGloryPoints(this.keycloakId, gloryPoints, reason, fightId);
isDefense? this.defenseGloryPoints = gloryPoints: this.attackGloryPoints = gloryPoints;

Check warning on line 852 in Core/src/core/database/game/models/Player.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Operator '?' must be spaced

Check warning on line 852 in Core/src/core/database/game/models/Player.ts

View workflow job for this annotation

GitHub Actions / eslint-core-module

Operator ':' must be spaced
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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Core/src/core/database/logs/LogsDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down
7 changes: 3 additions & 4 deletions Core/src/core/fights/fighter/PlayerFighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,19 @@ 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<void> {
public async loadStats(): Promise<void> {
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);
this.stats.speed = this.player.getCumulativeSpeed(playerActiveObjects);
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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Core/src/core/missions/interfaces/reachGlory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const missionInterface: IMission = {

generateRandomVariant: () => 0,

initialNumberDone: (player) => player.gloryPoints,
initialNumberDone: (player) => player.getGloryPoints(),

updateSaveBlob: () => null
};
2 changes: 1 addition & 1 deletion Discord/src/commands/player/FightCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 4b47a5a

Please sign in to comment.