Add PlayerNpcTalkEvent

This commit is contained in:
KingRainbow44 2023-08-29 23:54:34 -04:00
parent dbc45f36f0
commit 1ca451559c
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 35 additions and 3 deletions

View File

@ -1,13 +1,14 @@
package emu.grasscutter.game.talk;
import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK;
import static emu.grasscutter.game.quest.enums.QuestContent.*;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.MainQuestData.TalkData;
import emu.grasscutter.game.player.*;
import emu.grasscutter.server.event.player.PlayerNpcTalkEvent;
import lombok.NonNull;
import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK;
import static emu.grasscutter.game.quest.enums.QuestContent.*;
public final class TalkManager extends BasePlayerManager {
public TalkManager(@NonNull Player player) {
super(player);
@ -23,6 +24,11 @@ public final class TalkManager extends BasePlayerManager {
var player = this.getPlayer();
var talkData = GameData.getTalkConfigDataMap().get(talkId);
// Invoke PlayerNpcTalkEvent.
var event = new PlayerNpcTalkEvent(player, talkData, talkId, npcEntityId);
if (!event.call()) return;
if (talkData != null) {
// Check if the NPC id is valid.
var entity = player.getScene().getEntityById(npcEntityId);

View File

@ -0,0 +1,26 @@
package emu.grasscutter.server.event.player;
import emu.grasscutter.data.excels.TalkConfigData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.Cancellable;
import emu.grasscutter.server.event.types.PlayerEvent;
import lombok.Getter;
import javax.annotation.Nullable;
@Getter
public final class PlayerNpcTalkEvent extends PlayerEvent implements Cancellable {
private final TalkConfigData talk;
private final int talkId, npcEntityId;
public PlayerNpcTalkEvent(Player player,
@Nullable TalkConfigData talk,
int talkId,
int npcEntityId) {
super(player);
this.talk = talk;
this.talkId = talkId;
this.npcEntityId = npcEntityId;
}
}