-
-
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.
- Loading branch information
Showing
4 changed files
with
147 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import {commandRequires, CommandUtils} from "../../core/utils/CommandUtils"; | ||
import {GuildConstants} from "../../../../Lib/src/constants/GuildConstants"; | ||
import {DraftBotPacket, makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket"; | ||
import Player, {Players} from "../../core/database/game/models/Player"; | ||
import { | ||
CommandGuildLeaveAcceptPacketRes, | ||
CommandGuildLeavePacketReq, CommandGuildLeaveRefusePacketRes | ||
} from "../../../../Lib/src/packets/commands/CommandGuildLeavePacket"; | ||
import {Guilds} from "../../core/database/game/models/Guild"; | ||
import {ReactionCollectorGuildLeave} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildLeave"; | ||
import {EndCallback, ReactionCollectorInstance} from "../../core/utils/ReactionsCollector"; | ||
import {ReactionCollectorAcceptReaction} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; | ||
import {BlockingUtils} from "../../core/utils/BlockingUtils"; | ||
import {BlockingConstants} from "../../../../Lib/src/constants/BlockingConstants"; | ||
|
||
async function acceptGuildleave(player: Player, response: DraftBotPacket[]): Promise<void> { | ||
await player.reload(); | ||
if (player.guildId === null) { | ||
return; | ||
} | ||
const guild = await Guilds.getById(player.guildId); | ||
if (player.id === guild.chiefId) { | ||
if (guild.elderId !== null) { | ||
const elder = await Players.getById(guild.elderId); | ||
guild.elderId = null; | ||
guild.chiefId = elder.id; | ||
response.push(makePacket(CommandGuildLeaveAcceptPacketRes, { | ||
newChiefKeycloakId: elder.keycloakId, | ||
guildName: guild.name | ||
})); | ||
return; | ||
} | ||
// TODO : détruire la guilde ici | ||
response.push(makePacket(CommandGuildLeaveAcceptPacketRes, { | ||
guildName: guild.name | ||
})); | ||
return; | ||
} | ||
if (guild.elderId === player.id) { | ||
guild.elderId = null; | ||
} | ||
player.guildId = null; | ||
response.push(makePacket(CommandGuildLeaveAcceptPacketRes, { | ||
guildName: guild.name | ||
})); | ||
} | ||
|
||
export default class GuildElderCommand { | ||
@commandRequires(CommandGuildLeavePacketReq, { | ||
notBlocked: true, | ||
disallowedEffects: CommandUtils.DISALLOWED_EFFECTS.NOT_STARTED_OR_DEAD, | ||
level: GuildConstants.REQUIRED_LEVEL, | ||
guildNeeded: true | ||
}) | ||
async execute(response: DraftBotPacket[], player: Player, packet: CommandGuildLeavePacketReq, context: PacketContext): Promise<void> { | ||
if (player.guildId === null) { | ||
return; | ||
} | ||
const guild = await Guilds.getById(player.guildId); | ||
const elder = await Players.getById(guild.elderId); | ||
|
||
const collector = new ReactionCollectorGuildLeave( | ||
guild.name, | ||
elder.keycloakId | ||
); | ||
const endCallback: EndCallback = async (collector: ReactionCollectorInstance, response: DraftBotPacket[]): Promise<void> => { | ||
const reaction = collector.getFirstReaction(); | ||
if (reaction && reaction.reaction.type === ReactionCollectorAcceptReaction.name) { | ||
await acceptGuildleave(player, response); | ||
} | ||
else { | ||
response.push(makePacket(CommandGuildLeaveRefusePacketRes, {})); | ||
} | ||
BlockingUtils.unblockPlayer(player.id, BlockingConstants.REASONS.GUILD_LEAVE); | ||
}; | ||
|
||
const collectorPacket = new ReactionCollectorInstance( | ||
collector, | ||
context, | ||
{ | ||
allowedPlayerKeycloakIds: [player.keycloakId], | ||
reactionLimit: 1 | ||
}, | ||
endCallback | ||
) | ||
.block(player.id, BlockingConstants.REASONS.GUILD_LEAVE) | ||
.build(); | ||
|
||
response.push(collectorPacket); | ||
} | ||
} |
Empty file.
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,16 @@ | ||
import {DraftBotPacket, PacketDirection, sendablePacket} from "../DraftBotPacket"; | ||
|
||
@sendablePacket(PacketDirection.FRONT_TO_BACK) | ||
export class CommandGuildLeavePacketReq extends DraftBotPacket { | ||
} | ||
|
||
@sendablePacket(PacketDirection.BACK_TO_FRONT) | ||
export class CommandGuildLeaveRefusePacketRes extends DraftBotPacket { | ||
} | ||
|
||
@sendablePacket(PacketDirection.BACK_TO_FRONT) | ||
export class CommandGuildLeaveAcceptPacketRes extends DraftBotPacket { | ||
newChiefKeycloakId?: string; | ||
|
||
guildName!: string; | ||
} |
40 changes: 40 additions & 0 deletions
40
Lib/src/packets/interaction/ReactionCollectorGuildLeave.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,40 @@ | ||
import { | ||
ReactionCollector, | ||
ReactionCollectorAcceptReaction, | ||
ReactionCollectorCreationPacket, | ||
ReactionCollectorData, | ||
ReactionCollectorRefuseReaction | ||
} from "./ReactionCollectorPacket"; | ||
|
||
export class ReactionCollectorGuildLeaveData extends ReactionCollectorData { | ||
guildName!: string; | ||
|
||
newChiefKeycloakId!: string | null; | ||
} | ||
|
||
export class ReactionCollectorGuildLeave extends ReactionCollector { | ||
private readonly guildName: string; | ||
|
||
private readonly newChiefKeycloakId: string; | ||
|
||
constructor(guildName: string, newChiefKeycloakId: string) { | ||
super(); | ||
this.guildName = guildName; | ||
this.newChiefKeycloakId = newChiefKeycloakId; | ||
} | ||
|
||
creationPacket(id: string, endTime: number): ReactionCollectorCreationPacket { | ||
return { | ||
id, | ||
endTime, | ||
reactions: [ | ||
this.buildReaction(ReactionCollectorAcceptReaction, {}), | ||
this.buildReaction(ReactionCollectorRefuseReaction, {}) | ||
], | ||
data: this.buildData(ReactionCollectorGuildLeaveData, { | ||
guildName: this.guildName, | ||
newChiefKeycloakId: this.newChiefKeycloakId | ||
}) | ||
}; | ||
} | ||
} |