Skip to content

Commit

Permalink
eslint fix #2273
Browse files Browse the repository at this point in the history
  • Loading branch information
Ntalcme authored and BastLast committed Jan 15, 2025
1 parent dffdf6a commit 8434738
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export const commandInfo: ITestCommand = {
*/
const gloryPointsTestCommand: ExecuteTestCommandLike = async (player, args, response) => {
const gloryPoints = parseInt(args[0], 10);
const type = parseInt(args[1], 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, type===0, NumberChangeReason.TEST, response);
await player.setGloryPoints(gloryPoints, type === 0, NumberChangeReason.TEST, response);
await player.save();

return `Vous avez maintenant ${player.getGloryPoints()} :sparkles: !`;
Expand Down
22 changes: 11 additions & 11 deletions Core/src/commands/player/FightCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ async function getPlayerStats(player: Player): Promise<PlayerStats> {
* @returns player opponent
*/
async function findOpponent(player: Player, offset: number): Promise<Player | null> {
const closestPlayers = await Players.findByDefenseGlory(player.attackGloryPoints, FightConstants.PLAYER_PER_OPPONENT_SEARCH, offset)
//shuffle array
const closestPlayers = await Players.findByDefenseGlory(player.attackGloryPoints, FightConstants.PLAYER_PER_OPPONENT_SEARCH, offset);
// Shuffle array
closestPlayers.sort(() => Math.random() - 0.5);
let selectedPlayer: Player = null;
for (const closestPlayer of closestPlayers) {
if (
closestPlayer.id === player.id || // cannot fight itself
closestPlayer.level < FightConstants.REQUIRED_LEVEL || // level too low
closestPlayer.id === player.id || // Cannot fight itself
closestPlayer.level < FightConstants.REQUIRED_LEVEL || // Level too low
Math.abs(player.defenseGloryPoints - closestPlayer.attackGloryPoints) > FightConstants.ELO.MAX_ELO_GAP // ELO gap too large
) {
continue;
Expand All @@ -79,24 +79,24 @@ async function findOpponent(player: Player, offset: number): Promise<Player | nu
FightConstants.DEFENDER_COOLDOWN_MINUTES
)
) {
continue; // defender on cooldown
continue; // Defender on cooldown
}
const bo3 = await LogsReadRequests.getRankedFightsThisWeek(player.keycloakId, closestPlayer.keycloakId);
if (
bo3.won > 1 ||
bo3.lost > 1 ||
bo3.draw + bo3.won + bo3.lost >= 3
) {
continue; // max fights already played
continue; // Max fights already played
}
selectedPlayer = closestPlayer;
}
if (selectedPlayer || offset > FightConstants.MAX_OFFSET_FOR_OPPONENT_SEARCH) {
return selectedPlayer;
}
else {
return findOpponent(player, offset + 1);
}

return findOpponent(player, offset + 1);

}

export default class FightCommand {
Expand All @@ -117,9 +117,9 @@ export default class FightCommand {
if (reaction && reaction.reaction.type === ReactionCollectorAcceptReaction.name) {
const opponent = await findOpponent(player, 0);
if (!opponent) {
// error message if no opponent found
// Error message if no opponent found
}
// start fight
// Start fight
}
else {
response.push(makePacket(CommandFightRefusePacketRes, {}));
Expand Down
10 changes: 5 additions & 5 deletions Core/src/core/database/game/models/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class Player extends Model {
* Return the value of glory that is displayed to the users
*/
public getGloryPoints(): number {
return this.attackGloryPoints + this.defenseGloryPoints
return this.attackGloryPoints + this.defenseGloryPoints;
}

/**
Expand Down Expand Up @@ -849,7 +849,7 @@ export class Player extends Model {
*/
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;
isDefense ? this.defenseGloryPoints = gloryPoints : this.attackGloryPoints = gloryPoints;
Object.assign(this, await MissionsController.update(this, response, {
missionId: "reachGlory",
count: this.getGloryPoints(),
Expand Down Expand Up @@ -1429,13 +1429,13 @@ export class Players {
* @param offset - offset in case the found players are not enough and an offset search is necessary
*/
static async findByDefenseGlory(defenseGlory: number, amountOfPlayersToRetrieve: number, offset: number): Promise<Player[]> {
return Player.findAll({
return await Player.findAll({
where: {
defenseGlory: { [Op.ne]: null }
defenseGlory: {[Op.ne]: null}
},
order: [
// Trier par la différence absolue avec defenseGlory recherchée
[Sequelize.literal(`ABS(defenseGlory - ${defenseGlory})`), 'ASC']
[Sequelize.literal(`ABS(defenseGlory - ${defenseGlory})`), "ASC"]
],
limit: amountOfPlayersToRetrieve,
offset: offset
Expand Down
2 changes: 1 addition & 1 deletion Discord/src/commands/player/FightCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function createFightCollector(packet: ReactionCollectorCreationPack
const interaction = DiscordCache.getInteraction(context.discord!.interaction)!;
await interaction.deferReply();
const data = packet.data.data as ReactionCollectorFightData;
const subTextKey = RandomUtils.draftbotRandom.bool(FightConstants.RARE_SUB_TEXT_INTRO) ? "rare" : "common"
const subTextKey = RandomUtils.draftbotRandom.bool(FightConstants.RARE_SUB_TEXT_INTRO) ? "rare" : "common";
const embed = new DraftBotEmbed().formatAuthor(i18n.t("commands:fight.title", {
lng: interaction.userLanguage,
pseudo: interaction.user.displayName
Expand Down
4 changes: 2 additions & 2 deletions Lib/src/constants/FightConstants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export abstract class FightConstants {
static readonly RARE_SUB_TEXT_INTRO = 0.001 // chance of having rare subtext (1=100%)
static readonly RARE_SUB_TEXT_INTRO = 0.001; // Chance of having rare subtext (1=100%)

static readonly MAX_TURNS = 24;

Expand Down Expand Up @@ -128,7 +128,7 @@ export abstract class FightConstants {

static readonly DEFAULT_ACTION_WEIGHT = 1;

// time needed to wait before being able to fight again after a ranked fight as a defender
// Time needed to wait before being able to fight again after a ranked fight as a defender
static DEFENDER_COOLDOWN_MINUTES = 30;

// Maximum offset for opponent search
Expand Down

0 comments on commit 8434738

Please sign in to comment.