Add support for codexQuests (#870)

This commit is contained in:
ShigemoriHakura 2022-05-14 07:33:07 +08:00 committed by GitHub
parent ab6aa96144
commit 749ef3ff23
8 changed files with 139 additions and 1 deletions

View File

@ -9,7 +9,6 @@ import java.util.Map;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.utils.Utils;
import emu.grasscutter.data.custom.AbilityEmbryoEntry;
import emu.grasscutter.data.custom.AbilityModifier;
import emu.grasscutter.data.custom.AbilityModifierEntry;
import emu.grasscutter.data.custom.OpenConfigEntry;
import emu.grasscutter.data.custom.MainQuestData;
@ -65,6 +64,8 @@ public class GameData {
private static final Int2ObjectMap<SceneData> sceneDataMap = new Int2ObjectLinkedOpenHashMap<>();
private static final Int2ObjectMap<FetterData> fetterDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<CodexQuest> codexQuestMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<CodexQuest> codexQuestIdMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<FetterCharacterCardData> fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<RewardData> rewardDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<WorldLevelData> worldLevelDataMap = new Int2ObjectOpenHashMap<>();
@ -293,6 +294,10 @@ public class GameData {
return fetters;
}
public static Int2ObjectMap<CodexQuest> getCodexQuestMap(){return codexQuestMap;}
public static Int2ObjectMap<CodexQuest> getCodexQuestIdMap(){return codexQuestIdMap;}
public static Int2ObjectMap<WorldLevelData> getWorldLevelDataMap() {
return worldLevelDataMap;
}

View File

@ -0,0 +1,42 @@
package emu.grasscutter.data.def;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
@ResourceType(name = {"QuestCodexExcelConfigData.json"}, loadPriority = ResourceType.LoadPriority.HIGH)
public class CodexQuest extends GameResource {
private int Id;
private int ParentQuestId;
private int ChapterId;
private int SortOrder;
private boolean IsDisuse;
public int getParentQuestId() {
return ParentQuestId;
}
public int getId() {
return Id;
}
public int getChapterId() {
return ChapterId;
}
public int getSortOrder() {
return SortOrder;
}
public boolean getIsDisuse() {
return IsDisuse;
}
@Override
public void onLoad() {
if(!this.getIsDisuse()) {
GameData.getCodexQuestIdMap().put(this.getParentQuestId(), this);
}
}
}

View File

@ -1212,6 +1212,7 @@ public class Player {
session.send(new PacketAvatarDataNotify(this));
session.send(new PacketFinishedParentQuestNotify(this));
session.send(new PacketQuestListNotify(this));
session.send(new PacketCodexDataFullNotify(this));
session.send(new PacketServerCondMeetQuestListUpdateNotify(this));
session.send(new PacketAllWidgetDataNotify(this));
session.send(new PacketWidgetGadgetAllDataNotify());

View File

@ -3,6 +3,7 @@ package emu.grasscutter.game.quest;
import java.util.HashMap;
import java.util.Map;
import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify;
import org.bson.types.ObjectId;
import dev.morphia.annotations.Entity;
@ -91,6 +92,7 @@ public class GameMainQuest {
this.isFinished = true;
this.state = ParentQuestState.PARENT_QUEST_STATE_FINISHED;
this.getOwner().getSession().send(new PacketFinishedParentQuestUpdateNotify(this));
this.getOwner().getSession().send(new PacketCodexDataUpdateNotify(this));
this.save();
}

View File

@ -11,6 +11,7 @@ import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.quest.enums.LogicType;
import emu.grasscutter.game.quest.enums.QuestState;
import emu.grasscutter.net.proto.QuestOuterClass.Quest;
import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify;
import emu.grasscutter.server.packet.send.PacketQuestListUpdateNotify;
import emu.grasscutter.server.packet.send.PacketQuestProgressUpdateNotify;
import emu.grasscutter.utils.Utils;

View File

@ -66,6 +66,12 @@ public class QuestManager {
}
}
}
public void forEachMainQuest(Consumer<GameMainQuest> callback) {
for (GameMainQuest mainQuest : getQuests().values()) {
callback.accept(mainQuest);
}
}
// TODO
public void forEachActiveQuest(Consumer<GameQuest> callback) {

View File

@ -0,0 +1,54 @@
package emu.grasscutter.server.packet.send;
import java.util.Collections;
import java.util.List;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.CodexDataFullNotifyOuterClass.CodexDataFullNotify;
import emu.grasscutter.net.proto.CodexTypeDataOuterClass.CodexTypeData;
import emu.grasscutter.net.proto.CodexTypeOuterClass;
import emu.grasscutter.server.game.GameSession;
public class PacketCodexDataFullNotify extends BasePacket {
public PacketCodexDataFullNotify(Player player) {
super(PacketOpcodes.CodexDataFullNotify, true);
//Quests
CodexTypeData.Builder questTypeData = CodexTypeData.newBuilder()
.setTypeValue(1);
//Tips
CodexTypeData.Builder pushTipsTypeData = CodexTypeData.newBuilder()
.setTypeValue(6);
//Views
CodexTypeData.Builder viewTypeData = CodexTypeData.newBuilder()
.setTypeValue(7);
//Weapons
CodexTypeData.Builder weaponTypeData = CodexTypeData.newBuilder()
.setTypeValue(2);
player.getQuestManager().forEachMainQuest(mainQuest -> {
if(mainQuest.isFinished()){
var codexQuest = GameData.getCodexQuestIdMap().get(mainQuest.getParentQuestId());
if(codexQuest != null){
questTypeData.addCodexIdList(codexQuest.getId()).addAllHaveViewedList(Collections.singleton(true));
}
}
});
CodexDataFullNotify.Builder proto = CodexDataFullNotify.newBuilder()
.addTypeDataList(questTypeData.build())
.addTypeDataList(pushTipsTypeData.build())
.addTypeDataList(viewTypeData.build())
.addTypeDataList(weaponTypeData);
this.setData(proto);
}
}

View File

@ -0,0 +1,27 @@
package emu.grasscutter.server.packet.send;
import java.util.Collections;
import java.util.List;
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.quest.GameMainQuest;
import emu.grasscutter.game.quest.GameQuest;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.CodexDataUpdateNotifyOuterClass.CodexDataUpdateNotify;
import emu.grasscutter.server.game.GameSession;
public class PacketCodexDataUpdateNotify extends BasePacket {
public PacketCodexDataUpdateNotify(GameMainQuest quest) {
super(PacketOpcodes.CodexDataUpdateNotify, true);
var codexQuest = GameData.getCodexQuestIdMap().get(quest.getParentQuestId());
if(codexQuest != null){
CodexDataUpdateNotify proto = CodexDataUpdateNotify.newBuilder()
.setTypeValue(1)
.setId(codexQuest.getId())
.build();
this.setData(proto);
}
}
}