[Lua] Update for newest AnimeGameLua Changes

* Use the enums directly in some clases
* Use RewindData and QuestData from AnimeGameLua instead of our own RewindData and TeleportData
This commit is contained in:
hartie95 2024-02-06 21:01:06 +01:00
parent 5996c0052f
commit e0448e0ca9
8 changed files with 41 additions and 97 deletions

View File

@ -27,9 +27,6 @@ import emu.grasscutter.data.server.MonsterMapping;
import emu.grasscutter.data.server.SubfieldMapping;
import emu.grasscutter.game.dungeons.DungeonDropEntry;
import emu.grasscutter.game.quest.QuestEncryptionKey;
import emu.grasscutter.game.quest.RewindData;
import emu.grasscutter.game.quest.TeleportData;
import emu.grasscutter.game.world.GroupReplacementData;
import emu.grasscutter.game.quest.enums.QuestCond;
import emu.grasscutter.utils.Utils;
import emu.grasscutter.data.excels.*;
@ -45,6 +42,8 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Tolerate;
import lombok.val;
import org.anime_game_servers.gi_lua.models.quest.QuestData;
import org.anime_game_servers.gi_lua.models.quest.RewindData;
import org.anime_game_servers.gi_lua.models.scene.DummyPoint;
import org.anime_game_servers.gi_lua.models.scene.SceneGroupReplacement;
@ -169,7 +168,7 @@ public class GameData {
private static final Int2ObjectMap<ReliquaryLevelData> reliquaryLevelDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<ShopGoodsData> shopGoodsDataMap = new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<RewindData> rewindDataMap = new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<TeleportData> teleportDataMap = new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<QuestData> teleportDataMap = new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<Map<String, DummyPoint>> dummyPointMap = new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<RefreshPolicyExcelConfigData> refreshPolicyExcelConfigDataMap = new Int2ObjectOpenHashMap<>();
// The following are accessed via getMapByResourceDef, and will show as unused

View File

@ -26,8 +26,6 @@ import emu.grasscutter.game.dungeons.DungeonDrop;
import emu.grasscutter.game.dungeons.enums.DungeonType;
import emu.grasscutter.game.managers.blossom.BlossomConfig;
import emu.grasscutter.game.quest.QuestEncryptionKey;
import emu.grasscutter.game.quest.RewindData;
import emu.grasscutter.game.quest.TeleportData;
import emu.grasscutter.game.quest.enums.QuestCond;
import emu.grasscutter.game.quest.enums.QuestContent;
import emu.grasscutter.game.world.SpawnDataEntry;
@ -45,6 +43,8 @@ import lombok.val;
import org.anime_game_servers.gi_lua.models.loader.SceneReplacementScriptLoadParams;
import org.anime_game_servers.gi_lua.models.loader.ShardQuestScriptLoadParams;
import org.anime_game_servers.gi_lua.models.quest.QuestData;
import org.anime_game_servers.gi_lua.models.quest.RewindData;
import org.anime_game_servers.gi_lua.models.scene.SceneGroupReplacement;
import org.reflections.Reflections;
import org.slf4j.Logger;
@ -766,7 +766,7 @@ public class ResourceLoader {
val sharedQuestParams = new ShardQuestScriptLoadParams(questId);
if(!ScriptSystem.getScriptLoader().loadData(sharedQuestParams, script -> {
// these are Map<String, class>
val teleportDataMap = script.getGlobalVariableMap("quest_data", TeleportData.class);
val teleportDataMap = script.getGlobalVariableMap("quest_data", QuestData.class);
val rewindDataMap = script.getGlobalVariableMap("rewind_data", RewindData.class);
// convert them to Map<Integer, class> and cache

View File

@ -288,10 +288,10 @@ public class GameMainQuest {
}
public boolean hasRewindPosition(int subId, List<Position> posAndRot){
RewindData questRewind = GameData.getRewindDataMap().get(subId);
val questRewind = GameData.getRewindDataMap().get(subId);
if (questRewind == null) return false;
RewindData.AvatarData avatarData = questRewind.getAvatar();
val avatarData = questRewind.getAvatar();
if (avatarData == null) return false;
String avatarPos = avatarData.getPos();
@ -319,14 +319,14 @@ public class GameMainQuest {
}
public boolean hasTeleportPostion(int subId, List<Position> posAndRot){
TeleportData questTransmit = GameData.getTeleportDataMap().get(subId);
val questTransmit = GameData.getTeleportDataMap().get(subId);
if (questTransmit == null) return false;
TeleportData.TransmitPoint transmitPoint = questTransmit.getTransmit_points().size() > 0 ? questTransmit.getTransmit_points().get(0) : null;
val transmitPoint = questTransmit.getTransmitPoints().size() > 0 ? questTransmit.getTransmitPoints().get(0) : null;
if (transmitPoint == null) return false;
String transmitPos = transmitPoint.getPos();
int sceneId = transmitPoint.getScene_id();
int sceneId = transmitPoint.getSceneId();
ScriptSceneData fullGlobals = GameData.getScriptSceneDataMap().get("flat.luas.scenes.full_globals.lua.json");
if (fullGlobals == null) return false;

View File

@ -1,28 +0,0 @@
package emu.grasscutter.game.quest;
import lombok.Data;
import lombok.Getter;
import java.util.List;
@Data
public class RewindData {
AvatarData avatar;
List<Npc> npcs;
@Data
public static class AvatarData {
@Getter private String pos;
}
@Data
public static class Npc {
private String script;
private int room_id;
private int data_index;
private int id;
private String pos;
private int scene_id;
private String alias;
}
}

View File

@ -1,36 +0,0 @@
package emu.grasscutter.game.quest;
import java.util.List;
import lombok.Data;
@Data
public class TeleportData {
List<TransmitPoint> transmit_points;
List<Npc> npcs;
List<Gadget> gadgets;
@Data
public static class TransmitPoint {
private int point_id;
private int scene_id;
private String pos;
}
@Data
public static class Npc {
private int data_index;
private int room_id;
private int scene_id;
private int id;
private String alias;
private String script;
private String pos;
}
@Data
public static class Gadget {
private int id;
private String pos;
}
}

View File

@ -921,4 +921,8 @@ public class Scene {
public void saveGroups() {
this.scriptManager.getCachedGroupInstances().values().forEach(SceneGroupInstance::save);
}
public int getCurDungeonId(){
return dungeonManager != null ? dungeonManager.getDungeonData().getId() : 0;
}
}

View File

@ -34,6 +34,7 @@ import lombok.val;
import messages.scene.VisionType;
import org.anime_game_servers.gi_lua.models.*;
import org.anime_game_servers.gi_lua.models.constants.EventType;
import org.anime_game_servers.gi_lua.models.constants.VisionLevelType;
import org.anime_game_servers.gi_lua.models.scene.SceneConfig;
import org.anime_game_servers.gi_lua.models.scene.SceneMeta;
import org.anime_game_servers.gi_lua.models.scene.block.SceneBlock;
@ -379,23 +380,28 @@ public class SceneScriptManager {
return instance;
}
private static void addEntityGridPosToMap(List<Map<GridPosition, Set<Integer>>> groupPositions, Set<Integer> visionLevels, SceneObject sceneObject, SceneGroupInfo group){
private static void addEntityGridPosToMap(List<Map<GridPosition, Set<Integer>>> groupPositions, Set<VisionLevelType> visionLevels, SceneObject sceneObject, SceneGroupInfo group){
visionLevels.add(addEntityGridPosToMap(groupPositions, sceneObject, group));
}
private static int addEntityGridPosToMap(List<Map<GridPosition, Set<Integer>>> groupPositions, SceneObject sceneObject, SceneGroupInfo group){
private static VisionLevelType addEntityGridPosToMap(List<Map<GridPosition, Set<Integer>>> groupPositions, SceneObject sceneObject, SceneGroupInfo group){
val visionLevel = switch (sceneObject.getType()){
case GADGET -> Math.max(getGadgetVisionLevel(((SceneGadget)sceneObject).getGadgetId()), sceneObject.getVisionLevel());
case REGION -> 0;
case GADGET -> {
val gadgetLevel = getGadgetVisionLevel(((SceneGadget)sceneObject).getGadgetId());
val scriptLevel = sceneObject.getVisionLevel();
if(gadgetLevel.getValue() > scriptLevel.getValue()) yield gadgetLevel;
else yield scriptLevel;
}
case REGION -> VisionLevelType.getDefault();
default -> sceneObject.getVisionLevel();
};
addGridPositionToMap(groupPositions.get(visionLevel), group.getId(), visionLevel, sceneObject.getPos());
addGridPositionToMap(groupPositions.get(visionLevel.getValue()), group.getId(), visionLevel, sceneObject.getPos());
return visionLevel;
}
private static void addGridPositionToMap(Map<GridPosition, Set<Integer>> map, int group_id, int vision_level, Position position) {
private static void addGridPositionToMap(Map<GridPosition, Set<Integer>> map, int group_id, VisionLevelType vision_level, Position position) {
//Convert position to grid position
GridPosition gridPos;
int width = Grasscutter.getConfig().server.game.visionOptions[vision_level].gridWidth;
int width = Grasscutter.getConfig().server.game.visionOptions[vision_level.getValue()].gridWidth;
gridPos = new GridPosition((int)(position.getX() / width), (int)(position.getZ() / width), width);
Set<Integer> groups = map.getOrDefault(gridPos, new HashSet<>());
@ -403,17 +409,17 @@ public class SceneScriptManager {
map.put(gridPos, groups);
}
private static int getGadgetVisionLevel(int gadget_id) {
private static VisionLevelType getGadgetVisionLevel(int gadget_id) {
var gadget = GameData.getGadgetDataMap().get(gadget_id);
if(gadget == null || gadget.getVisionLevel() == null) return 0;
if(gadget == null || gadget.getVisionLevel() == null) return VisionLevelType.getDefault();
var visionOptions = Grasscutter.getConfig().server.game.visionOptions;
for(int i = 0; i < visionOptions.length; i++)
if(visionOptions[i].name.compareTo(gadget.getVisionLevel()) == 0) {
return i;
return VisionLevelType.valueOf(visionOptions[i].name);
}
return 0;
return VisionLevelType.getDefault();
}
private void init() {
@ -458,7 +464,7 @@ public class SceneScriptManager {
group.load(scriptLoader);
//Add all entities here
Set<Integer> vision_levels = new HashSet<>();
Set<VisionLevelType> vision_levels = new HashSet<>();
val monsters = group.getMonsters();
if (monsters != null) {
@ -493,16 +499,15 @@ public class SceneScriptManager {
garbages.getGadgets().forEach(g -> addEntityGridPosToMap(groupPositions, g, groupInfo));
}
int max_vision_level = -1;
var maxVisionLevel = VisionLevelType.VISION_LEVEL_NORMAL;
if (!vision_levels.isEmpty()) {
for (int vision_level : vision_levels) {
if (max_vision_level == -1 || visionOptions[max_vision_level].visionRange < visionOptions[vision_level].visionRange)
max_vision_level = vision_level;
for (val visionLevel : vision_levels) {
if (visionOptions[maxVisionLevel.getValue()].visionRange < visionOptions[visionLevel.getValue()].visionRange)
maxVisionLevel = visionLevel;
}
}
if (max_vision_level == -1) max_vision_level = 0;
addGridPositionToMap(groupPositions.get(max_vision_level), groupInfo.getId(), max_vision_level, groupInfo.getPos());
addGridPositionToMap(groupPositions.get(maxVisionLevel.getValue()), groupInfo.getId(), maxVisionLevel, groupInfo.getPos());
});
var groupGrids = new ArrayList<Grid>();

View File

@ -2,7 +2,6 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.quest.GameQuest;
import emu.grasscutter.game.quest.TeleportData;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
@ -17,6 +16,7 @@ import java.util.ArrayList;
import java.util.Optional;
import lombok.val;
import org.anime_game_servers.gi_lua.models.quest.QuestData;
@Opcodes(PacketOpcodes.QuestTransmitReq)
public class HandlerQuestTransmitReq extends PacketHandler {
@ -27,8 +27,8 @@ public class HandlerQuestTransmitReq extends PacketHandler {
val player = session.getPlayer();
val posAndRot = new ArrayList<Position>();
final int sceneId = Optional.ofNullable(GameData.getTeleportDataMap().get(req.getQuestId()))
.map(TeleportData::getTransmit_points).stream().flatMap(List::stream).findFirst()
.map(TeleportData.TransmitPoint::getScene_id).orElse(3);
.map(QuestData::getTransmitPoints).stream().flatMap(List::stream).findFirst()
.map(QuestData.TransmitPoint::getSceneId).orElse(3);
val result = Optional.ofNullable(player.getQuestManager().getQuestById(req.getQuestId()))
.map(GameQuest::getMainQuest).filter(mainQuest -> mainQuest.hasTeleportPostion(req.getQuestId(), posAndRot))