-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/shopSmallEvent' into shopSmallEvent
# Conflicts: # Discord/src/packetHandlers/handlers/ReactionCollectorHandlers.ts # Discord/src/smallEvents/shop.ts # Lang/fr/smallEvents.json
- Loading branch information
Showing
80 changed files
with
1,040 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"startMap": 23, | ||
"endMap": 21, | ||
"tripDuration": 420 | ||
"startMap": 23, | ||
"endMap": 21, | ||
"tripDuration": 240 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"startMap": 21, | ||
"endMap": 23, | ||
"tripDuration": 420 | ||
"startMap": 21, | ||
"endMap": 23, | ||
"tripDuration": 240 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Core/src/commands/admin/testCommands/Player/UnblockTestCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {ExecuteTestCommandLike, ITestCommand} from "../../../../core/CommandsTest"; | ||
import {BlockingUtils} from "../../../../core/utils/BlockingUtils"; | ||
|
||
export const commandInfo: ITestCommand = { | ||
name: "unblock", | ||
description: "Vous permet de vous débloquer lorsqu'une commande vous bloque (ATTENTION: si vous obtenez un exploit avec cette commande, ce n'en est pas un)" | ||
}; | ||
|
||
/** | ||
* Unblock the player | ||
*/ | ||
const unblockTestCommand: ExecuteTestCommandLike = (player) => { | ||
const reasons = BlockingUtils.getPlayerBlockingReason(player.id).map(r => { | ||
BlockingUtils.unblockPlayer(player.id, r); | ||
return r; | ||
}); | ||
return `Vous vous êtes débloqué des raisons suivantes : ${reasons.join(", ")}`; | ||
}; | ||
|
||
commandInfo.execute = unblockTestCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import {DraftBotPacket, makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket"; | ||
import {Player, Players} from "../../core/database/game/models/Player"; | ||
import { | ||
CommandUnlockAcceptPacketRes, | ||
CommandUnlockHimself, | ||
CommandUnlockNoPlayerFound, | ||
CommandUnlockNotEnoughMoney, | ||
CommandUnlockNotInJail, | ||
CommandUnlockPacketReq, | ||
CommandUnlockRefusePacketRes | ||
} from "../../../../Lib/src/packets/commands/CommandUnlockPacket"; | ||
import {EndCallback, ReactionCollectorInstance} from "../../core/utils/ReactionsCollector"; | ||
import {ReactionCollectorAcceptReaction} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; | ||
import {BlockingConstants} from "../../../../Lib/src/constants/BlockingConstants"; | ||
import {BlockingUtils} from "../../core/utils/BlockingUtils"; | ||
import {commandRequires, CommandUtils} from "../../core/utils/CommandUtils"; | ||
import {ReactionCollectorUnlock} from "../../../../Lib/src/packets/interaction/ReactionCollectorUnlock"; | ||
import {draftBotInstance} from "../../index"; | ||
import {UnlockConstants} from "../../../../Lib/src/constants/UnlockConstants"; | ||
import {TravelTime} from "../../core/maps/TravelTime"; | ||
import {NumberChangeReason} from "../../../../Lib/src/constants/LogsConstants"; | ||
import {Effect} from "../../../../Lib/src/enums/Effect"; | ||
|
||
/** | ||
* Accept the unlock of a player | ||
* @param player | ||
* @param freedPlayer | ||
* @param response | ||
*/ | ||
async function acceptUnlock(player: Player, freedPlayer: Player, response: DraftBotPacket[]): Promise<void> { | ||
await player.reload(); | ||
// Do all necessary checks again just in case something changed during the menu | ||
if (unlockCannotBeDone(player, freedPlayer, response)) { | ||
return; | ||
} | ||
|
||
await TravelTime.removeEffect(freedPlayer, NumberChangeReason.UNLOCK); | ||
await player.spendMoney({ | ||
amount: UnlockConstants.PRICE_FOR_UNLOCK, | ||
response, | ||
reason: NumberChangeReason.UNLOCK | ||
}); | ||
|
||
await Promise.all([ | ||
player.save(), | ||
freedPlayer.save() | ||
]); | ||
|
||
draftBotInstance.logsDatabase.logUnlock(player.keycloakId, freedPlayer.keycloakId).then(); | ||
|
||
response.push(makePacket(CommandUnlockAcceptPacketRes, { | ||
unlockedKeycloakId: freedPlayer.keycloakId | ||
})); | ||
} | ||
|
||
/** | ||
* Check if the player can unlock another player | ||
* @param player The player who wants to kick a member | ||
* @param freedPlayer The player who will be freed from the prison | ||
* @param response The response to send | ||
*/ | ||
function unlockCannotBeDone(player: Player, freedPlayer: Player, response: DraftBotPacket[]): boolean { | ||
if (freedPlayer === null) { | ||
response.push(makePacket(CommandUnlockNoPlayerFound, {})); | ||
return true; | ||
} | ||
if (player.money < UnlockConstants.PRICE_FOR_UNLOCK) { | ||
response.push(makePacket(CommandUnlockNotEnoughMoney, { | ||
money: player.money | ||
})); | ||
return true; | ||
} | ||
if (player.id === freedPlayer.id) { | ||
response.push(makePacket(CommandUnlockHimself, {})); | ||
return true; | ||
} | ||
if (freedPlayer.effectId !== Effect.JAILED.id) { | ||
response.push(makePacket(CommandUnlockNotInJail, {})); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
export default class UnlockCommand { | ||
@commandRequires(CommandUnlockPacketReq, { | ||
notBlocked: true, | ||
allowedEffects: CommandUtils.ALLOWED_EFFECTS.NO_EFFECT | ||
}) | ||
async execute(response: DraftBotPacket[], player: Player, packet: CommandUnlockPacketReq, context: PacketContext): Promise<void> { | ||
const freedPlayer = await Players.getAskedPlayer(packet.askedPlayer, player); | ||
|
||
if (unlockCannotBeDone(player, freedPlayer, response)) { | ||
return; | ||
} | ||
|
||
// Send collector | ||
const collector = new ReactionCollectorUnlock( | ||
freedPlayer.keycloakId | ||
); | ||
|
||
const endCallback: EndCallback = async (collector: ReactionCollectorInstance, response: DraftBotPacket[]): Promise<void> => { | ||
const reaction = collector.getFirstReaction(); | ||
if (reaction && reaction.reaction.type === ReactionCollectorAcceptReaction.name) { | ||
await acceptUnlock(player, freedPlayer, response); | ||
} | ||
else { | ||
response.push(makePacket(CommandUnlockRefusePacketRes, {})); | ||
} | ||
BlockingUtils.unblockPlayer(player.id, BlockingConstants.REASONS.UNLOCK); | ||
}; | ||
|
||
const collectorPacket = new ReactionCollectorInstance( | ||
collector, | ||
context, | ||
{ | ||
allowedPlayerKeycloakIds: [player.keycloakId], | ||
reactionLimit: 1 | ||
}, | ||
endCallback | ||
) | ||
.block(player.id, BlockingConstants.REASONS.UNLOCK) | ||
.build(); | ||
|
||
response.push(collectorPacket); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.