Load talks from MainQuestData

This commit is contained in:
KingRainbow44 2023-04-30 20:54:26 -04:00
parent 6869008bcc
commit 400a670856
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 53 additions and 48 deletions

View File

@ -63,6 +63,10 @@ public class MainQuestData {
this.talks = this.talks.stream() this.talks = this.talks.stream()
.filter(Objects::nonNull).toList(); .filter(Objects::nonNull).toList();
// Apply talk data to the quest talk map.
this.talks.forEach(talkData -> GameData.getQuestTalkMap().put(
talkData.getId(), this.getId()));
// Apply additional sub-quest data to sub-quests.
Arrays.stream(this.subQuests).forEach(quest -> { Arrays.stream(this.subQuests).forEach(quest -> {
var questData = GameData.getQuestDataMap().get(quest.getSubId()); var questData = GameData.getQuestDataMap().get(quest.getSubId());
if (questData != null) questData.applyFrom(quest); if (questData != null) questData.applyFrom(quest);

View File

@ -1,33 +1,28 @@
package emu.grasscutter.data.excels; package emu.grasscutter.data.excels;
import emu.grasscutter.data.GameResource; import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import lombok.AccessLevel; import lombok.Getter;
import lombok.Getter;
import lombok.Setter; @Getter
import lombok.experimental.FieldDefaults; @ResourceType(name = "ChapterExcelConfigData.json")
public class ChapterData extends GameResource {
@ResourceType(name = "ChapterExcelConfigData.json") @Getter private static final Map<Integer, ChapterData> beginQuestChapterMap
@Getter = new HashMap<>();
@Setter // TODO: remove on next API break @Getter private static final Map<Integer, ChapterData> endQuestChapterMap
@FieldDefaults(level = AccessLevel.PRIVATE) = new HashMap<>();
public class ChapterData extends GameResource {
// Why public? TODO: privatise next API break @Getter(onMethod_ = @Override)
public static final Map<Integer, ChapterData> beginQuestChapterMap = new HashMap<>(); private int id;
public static final Map<Integer, ChapterData> endQuestChapterMap = new HashMap<>(); private int beginQuestId;
private int endQuestId;
@Getter(onMethod_ = @Override) private int needPlayerLevel;
int id;
@Override
int beginQuestId; public void onLoad() {
int endQuestId; beginQuestChapterMap.put(beginQuestId, this);
int needPlayerLevel; beginQuestChapterMap.put(endQuestId, this);
}
@Override }
public void onLoad() {
beginQuestChapterMap.put(beginQuestId, this);
beginQuestChapterMap.put(endQuestId, this);
}
}

View File

@ -94,11 +94,11 @@ public class GameQuest {
getOwner().sendPacket(new PacketQuestListUpdateNotify(this)); getOwner().sendPacket(new PacketQuestListUpdateNotify(this));
if (ChapterData.beginQuestChapterMap.containsKey(subQuestId)) { if (ChapterData.getBeginQuestChapterMap().containsKey(subQuestId)) {
getOwner() getOwner()
.sendPacket( .sendPacket(
new PacketChapterStateNotify( new PacketChapterStateNotify(
ChapterData.beginQuestChapterMap.get(subQuestId).getId(), ChapterData.getBeginQuestChapterMap().get(subQuestId).getId(),
ChapterStateOuterClass.ChapterState.CHAPTER_STATE_BEGIN)); ChapterStateOuterClass.ChapterState.CHAPTER_STATE_BEGIN));
} }
@ -178,23 +178,29 @@ public class GameQuest {
return true; return true;
} }
public void finish() { public synchronized void finish() {
// Check if the quest has been finished.
if (this.state == QuestState.QUEST_STATE_FINISHED) {
Grasscutter.getLogger().debug("Quest {} was already finished.", this.getSubQuestId());
return;
}
this.state = QuestState.QUEST_STATE_FINISHED; this.state = QuestState.QUEST_STATE_FINISHED;
this.finishTime = Utils.getCurrentSeconds(); this.finishTime = Utils.getCurrentSeconds();
getOwner().sendPacket(new PacketQuestListUpdateNotify(this)); this.getOwner().sendPacket(new PacketQuestListUpdateNotify(this));
if (getQuestData().isFinishParent()) { if (this.getQuestData().isFinishParent()) {
// This quest finishes the questline - the main quest will also save the quest to db, so we // This quest finishes the questline - the main quest will also save the quest to db, so we
// don't have to call save() here // don't have to call save() here
getMainQuest().finish(); this.getMainQuest().finish();
} }
getQuestData() this.getQuestData()
.getFinishExec() .getFinishExec()
.forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam())); .forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam()));
// Some subQuests have conditions that subQuests are finished (even from different MainQuests) // Some subQuests have conditions that subQuests are finished (even from different MainQuests)
getOwner() this.getOwner()
.getQuestManager() .getQuestManager()
.queueEvent( .queueEvent(
QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL, QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL,
@ -203,25 +209,25 @@ public class GameQuest {
0, 0,
0, 0,
0); 0);
getOwner() this.getOwner()
.getQuestManager() .getQuestManager()
.queueEvent(QuestContent.QUEST_CONTENT_FINISH_PLOT, this.subQuestId, 0); .queueEvent(QuestContent.QUEST_CONTENT_FINISH_PLOT, this.subQuestId, 0);
getOwner() this.getOwner()
.getQuestManager() .getQuestManager()
.queueEvent( .queueEvent(
QuestCond.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); QuestCond.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0);
getOwner() this.getOwner()
.getScene() .getScene()
.triggerDungeonEvent(DungeonPassConditionType.DUNGEON_COND_FINISH_QUEST, getSubQuestId()); .triggerDungeonEvent(DungeonPassConditionType.DUNGEON_COND_FINISH_QUEST, getSubQuestId());
getOwner().getProgressManager().tryUnlockOpenStates(); this.getOwner().getProgressManager().tryUnlockOpenStates();
if (ChapterData.endQuestChapterMap.containsKey(subQuestId)) { if (ChapterData.getEndQuestChapterMap().containsKey(subQuestId)) {
mainQuest this.getMainQuest()
.getOwner() .getOwner()
.sendPacket( .sendPacket(
new PacketChapterStateNotify( new PacketChapterStateNotify(
ChapterData.endQuestChapterMap.get(subQuestId).getId(), ChapterData.getEndQuestChapterMap().get(subQuestId).getId(),
ChapterStateOuterClass.ChapterState.CHAPTER_STATE_END)); ChapterStateOuterClass.ChapterState.CHAPTER_STATE_END));
} }