Validate the NPC being talked to

This commit is contained in:
KingRainbow44 2023-05-11 21:11:10 -04:00
parent 9c0b9afae2
commit db1cc788b4
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 23 additions and 7 deletions

View File

@ -4,8 +4,10 @@ import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.GameResource; import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType;
import emu.grasscutter.game.talk.TalkExec; import emu.grasscutter.game.talk.TalkExec;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List; import java.util.List;
import lombok.*;
@ResourceType(name = "TalkExcelConfigData.json") @ResourceType(name = "TalkExcelConfigData.json")
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@ -26,6 +28,11 @@ public final class TalkConfigData extends GameResource {
alternate = {"_questId"}) alternate = {"_questId"})
private int questId; private int questId;
@SerializedName(
value = "npcId",
alternate = {"_npcId"})
private List<Integer> npcId;
@Override @Override
public void onLoad() { public void onLoad() {
this.finishExec = this.finishExec =

View File

@ -1,15 +1,15 @@
package emu.grasscutter.game.talk; 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.QUEST_CONTENT_COMPLETE_ANY_TALK;
import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.MainQuestData.TalkData; import emu.grasscutter.data.binout.MainQuestData.TalkData;
import emu.grasscutter.game.player.BasePlayerManager; import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import lombok.NonNull; import lombok.NonNull;
import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK;
import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_ANY_TALK;
import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK;
public final class TalkManager extends BasePlayerManager { public final class TalkManager extends BasePlayerManager {
public TalkManager(@NonNull Player player) { public TalkManager(@NonNull Player player) {
super(player); super(player);
@ -19,12 +19,21 @@ public final class TalkManager extends BasePlayerManager {
* Invoked when a talk is triggered. * Invoked when a talk is triggered.
* *
* @param talkId The ID of the talk. * @param talkId The ID of the talk.
* @param npcEntityId The entity ID of the NPC being talked to.
*/ */
public void triggerTalkAction(int talkId) { public void triggerTalkAction(int talkId, int npcEntityId) {
var talkData = GameData.getTalkConfigDataMap().get(talkId); var talkData = GameData.getTalkConfigDataMap().get(talkId);
if (talkData == null) return; if (talkData == null) return;
var player = this.getPlayer(); var player = this.getPlayer();
// Check if the NPC id is valid.
var entity = player.getScene().getEntityById(npcEntityId);
if (entity == null) return;
// The config ID of the entity is the NPC's ID.
if (!talkData.getNpcId().contains(entity.getConfigId()))
return;
// Execute the talk action on associated handlers. // Execute the talk action on associated handlers.
talkData talkData
.getFinishExec() .getFinishExec()

View File

@ -13,7 +13,7 @@ public class HandlerNpcTalkReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = NpcTalkReq.parseFrom(payload); var req = NpcTalkReq.parseFrom(payload);
session.getPlayer().getTalkManager().triggerTalkAction(req.getTalkId()); session.getPlayer().getTalkManager().triggerTalkAction(req.getTalkId(), req.getEntityId());
session.send(new PacketNpcTalkRsp(req.getNpcEntityId(), req.getTalkId(), req.getEntityId())); session.send(new PacketNpcTalkRsp(req.getNpcEntityId(), req.getTalkId(), req.getEntityId()));
} }
} }