mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Rewrite how scenes are handled and move enums to their own package
This commit is contained in:
@@ -10,7 +10,6 @@ public class GameConstants {
|
||||
public static final ZoneOffset CURRENT_OFFSET = ZoneOffset.systemDefault().getRules().getOffset(Instant.now());
|
||||
|
||||
// Game
|
||||
public static final int HOME_PLANE_ID = 10000;
|
||||
public static final String DEFAULT_NAME = "Trailblazer";
|
||||
public static final int TRAILBLAZER_AVATAR_ID = 8001;
|
||||
public static final int MAX_TRAILBLAZER_LEVEL = 70;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class GameData {
|
||||
@Getter private static Int2ObjectMap<NpcExcel> npcExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<NpcMonsterExcel> npcMonsterExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<StageExcel> stageExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<MazePlaneExcel> mazePlaneExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<MapEntranceExcel> mapEntranceExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<HeroExcel> heroExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package emu.lunarcore.data.config;
|
||||
|
||||
import emu.lunarcore.game.scene.entity.PropState;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.List;
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import emu.lunarcore.game.avatar.AvatarBaseType;
|
||||
import emu.lunarcore.game.avatar.DamageType;
|
||||
import emu.lunarcore.game.enums.AvatarBaseType;
|
||||
import emu.lunarcore.game.enums.DamageType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
19
src/main/java/emu/lunarcore/data/excel/MazePlaneExcel.java
Normal file
19
src/main/java/emu/lunarcore/data/excel/MazePlaneExcel.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package emu.lunarcore.data.excel;
|
||||
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import emu.lunarcore.game.enums.GameModeType;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = {"MazePlane.json"})
|
||||
public class MazePlaneExcel extends GameResource {
|
||||
private int PlaneID;
|
||||
private int WorldID;
|
||||
private GameModeType PlaneType = GameModeType.Unknown;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return PlaneID;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import emu.lunarcore.data.GameDepot;
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import emu.lunarcore.data.ResourceType.LoadPriority;
|
||||
import emu.lunarcore.game.avatar.AvatarPropertyType;
|
||||
import emu.lunarcore.game.enums.AvatarPropertyType;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -4,7 +4,7 @@ import emu.lunarcore.data.GameDepot;
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import emu.lunarcore.data.ResourceType.LoadPriority;
|
||||
import emu.lunarcore.game.avatar.AvatarPropertyType;
|
||||
import emu.lunarcore.game.enums.AvatarPropertyType;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package emu.lunarcore.game.avatar;
|
||||
package emu.lunarcore.game.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package emu.lunarcore.game.avatar;
|
||||
package emu.lunarcore.game.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package emu.lunarcore.game.avatar;
|
||||
package emu.lunarcore.game.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
30
src/main/java/emu/lunarcore/game/enums/GameModeType.java
Normal file
30
src/main/java/emu/lunarcore/game/enums/GameModeType.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package emu.lunarcore.game.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum GameModeType {
|
||||
Unknown (0),
|
||||
Town (1),
|
||||
Maze (2),
|
||||
Train (3),
|
||||
Challenge (4),
|
||||
RogueExplore (5),
|
||||
RogueChallenge (6),
|
||||
TownRoom (7),
|
||||
Raid (8),
|
||||
FarmRelic (9),
|
||||
Client (10),
|
||||
ChallengeActivity (11),
|
||||
ActivityPunkLord (12),
|
||||
RogueAeonRoom (13),
|
||||
TrialActivity (14),
|
||||
AetherDivide (15),
|
||||
ChessRogue (16);
|
||||
|
||||
private final int val;
|
||||
|
||||
private GameModeType(int value) {
|
||||
this.val = value;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package emu.lunarcore.game.scene.entity;
|
||||
package emu.lunarcore.game.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -14,7 +14,7 @@ import emu.lunarcore.data.GameDepot;
|
||||
import emu.lunarcore.data.excel.ItemExcel;
|
||||
import emu.lunarcore.data.excel.RelicMainAffixExcel;
|
||||
import emu.lunarcore.data.excel.RelicSubAffixExcel;
|
||||
import emu.lunarcore.game.avatar.AvatarPropertyType;
|
||||
import emu.lunarcore.game.enums.AvatarPropertyType;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.EquipmentOuterClass.Equipment;
|
||||
import emu.lunarcore.proto.ItemOuterClass.Item;
|
||||
|
||||
@@ -11,6 +11,7 @@ import emu.lunarcore.data.config.AnchorInfo;
|
||||
import emu.lunarcore.data.config.FloorInfo;
|
||||
import emu.lunarcore.data.config.PropInfo;
|
||||
import emu.lunarcore.data.excel.MapEntranceExcel;
|
||||
import emu.lunarcore.data.excel.MazePlaneExcel;
|
||||
import emu.lunarcore.game.account.Account;
|
||||
import emu.lunarcore.game.avatar.AvatarStorage;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
@@ -246,7 +247,7 @@ public class Player {
|
||||
this.battle = battle;
|
||||
}
|
||||
|
||||
public void enterScene(int entryId, int teleportId) {
|
||||
public void enterScene(int entryId, int teleportId, boolean sendPacket) {
|
||||
// Get map entrance excel
|
||||
MapEntranceExcel entry = GameData.getMapEntranceExcelMap().get(entryId);
|
||||
if (entry == null) return;
|
||||
@@ -255,7 +256,7 @@ public class Player {
|
||||
FloorInfo floor = GameData.getFloorInfo(entry.getPlaneID(), entry.getFloorID());
|
||||
if (floor == null) return;
|
||||
|
||||
// Get teleport anchor
|
||||
// Get teleport anchor info (contains position) from the entry id
|
||||
int startGroup = entry.getStartGroupID();
|
||||
int anchorId = entry.getStartAnchorID();
|
||||
if (teleportId != 0 || anchorId == 0) {
|
||||
@@ -268,38 +269,50 @@ public class Player {
|
||||
|
||||
AnchorInfo anchor = floor.getAnchorInfo(startGroup, anchorId);
|
||||
if (anchor == null) return;
|
||||
|
||||
// Move player to scene
|
||||
this.loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId(), anchor.clonePos());
|
||||
|
||||
// Set position
|
||||
this.getPos().set(
|
||||
(int) (anchor.getPosX() * 1000f),
|
||||
(int) (anchor.getPosY() * 1000f),
|
||||
(int) (anchor.getPosZ() * 1000f)
|
||||
);
|
||||
this.planeId = entry.getPlaneID();
|
||||
this.floorId = entry.getFloorID();
|
||||
this.entryId = entry.getId();
|
||||
|
||||
// Save player
|
||||
this.save();
|
||||
|
||||
// Move to scene
|
||||
loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId());
|
||||
}
|
||||
|
||||
private void loadScene(int planeId, int floorId, int entryId) {
|
||||
// Sanity check
|
||||
if (this.scene != null && this.scene.getPlaneId() == planeId) {
|
||||
// Don't create a new scene if were already in the one we want to teleport to
|
||||
} else {
|
||||
this.scene = new Scene(this, planeId, floorId, entryId);
|
||||
}
|
||||
|
||||
// TODO send packet
|
||||
if (this.getSession().getState() != SessionState.WAITING_FOR_TOKEN) {
|
||||
// Send packet
|
||||
if (sendPacket) {
|
||||
this.sendPacket(new PacketEnterSceneByServerScNotify(this));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean loadScene(int planeId, int floorId, int entryId, Position pos) {
|
||||
// Get maze plane excel
|
||||
MazePlaneExcel planeExcel = GameData.getMazePlaneExcelMap().get(planeId);
|
||||
if (planeExcel == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get scene that we want to enter
|
||||
Scene nextScene = null;
|
||||
|
||||
if (getScene() != null && getScene().getPlaneId() == planeId && getScene().getFloorId() == floorId) {
|
||||
// Don't create a new scene if were already in the one we want to teleport to
|
||||
nextScene = this.scene;
|
||||
} else {
|
||||
nextScene = new Scene(this, planeExcel, floorId);
|
||||
}
|
||||
|
||||
// Set positions if player has logged in
|
||||
if (this.getSession().getState() != SessionState.WAITING_FOR_TOKEN) {
|
||||
this.getPos().set(pos);
|
||||
this.planeId = planeId;
|
||||
this.floorId = floorId;
|
||||
this.entryId = entryId;
|
||||
this.save();
|
||||
}
|
||||
|
||||
// Set player scene
|
||||
this.scene = nextScene;
|
||||
this.scene.setEntryId(entryId);
|
||||
|
||||
// Done, return success
|
||||
return true;
|
||||
}
|
||||
|
||||
public void dropMessage(String message) {
|
||||
this.sendPacket(new PacketRevcMsgScNotify(this, message));
|
||||
}
|
||||
@@ -329,7 +342,7 @@ public class Player {
|
||||
this.getAvatars().setupHeroPaths();
|
||||
|
||||
// Enter scene (should happen after everything else loads)
|
||||
this.loadScene(planeId, floorId, entryId);
|
||||
this.loadScene(planeId, floorId, entryId, this.getPos());
|
||||
}
|
||||
|
||||
public PlayerBasicInfo toProto() {
|
||||
|
||||
@@ -7,9 +7,11 @@ import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.config.*;
|
||||
import emu.lunarcore.data.config.GroupInfo.GroupLoadSide;
|
||||
import emu.lunarcore.data.excel.MazePlaneExcel;
|
||||
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
||||
import emu.lunarcore.data.excel.StageExcel;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.player.PlayerLineup;
|
||||
import emu.lunarcore.game.scene.entity.*;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
@@ -25,9 +27,10 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public class Scene {
|
||||
private final Player player;
|
||||
private final MazePlaneExcel excel;
|
||||
private final int planeId;
|
||||
private final int floorId;
|
||||
private final int entryId;
|
||||
private int entryId;
|
||||
|
||||
private int lastEntityId = 0;
|
||||
|
||||
@@ -38,11 +41,11 @@ public class Scene {
|
||||
// Other entities TODO
|
||||
private Int2ObjectMap<GameEntity> entities;
|
||||
|
||||
public Scene(Player player, int planeId, int floorId, int entryId) {
|
||||
public Scene(Player player, MazePlaneExcel excel, int floorId) {
|
||||
this.player = player;
|
||||
this.planeId = planeId;
|
||||
this.excel = excel;
|
||||
this.planeId = excel.getPlaneID();
|
||||
this.floorId = floorId;
|
||||
this.entryId = entryId;
|
||||
|
||||
// Setup avatars
|
||||
this.avatarEntityIds = new IntOpenHashSet();
|
||||
@@ -76,12 +79,12 @@ public class Scene {
|
||||
if (group.getMonsterList() != null && group.getMonsterList().size() > 0) {
|
||||
for (MonsterInfo monsterInfo : group.getMonsterList()) {
|
||||
// Get excels from game data
|
||||
NpcMonsterExcel excel = GameData.getNpcMonsterExcelMap().get(monsterInfo.getNPCMonsterID());
|
||||
NpcMonsterExcel npcMonsterExcel = GameData.getNpcMonsterExcelMap().get(monsterInfo.getNPCMonsterID());
|
||||
StageExcel stage = GameData.getStageExcelMap().get(1);
|
||||
if (excel == null || stage == null) continue;
|
||||
|
||||
// Create monster with excels
|
||||
EntityMonster monster = new EntityMonster(excel, stage, monsterInfo.clonePos());
|
||||
EntityMonster monster = new EntityMonster(npcMonsterExcel, stage, monsterInfo.clonePos());
|
||||
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
||||
monster.setInstId(monsterInfo.getID());
|
||||
monster.setEventId(monsterInfo.getEventID());
|
||||
@@ -146,6 +149,10 @@ public class Scene {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setEntryId(int entryId) {
|
||||
this.entryId = entryId;
|
||||
}
|
||||
|
||||
private int getNextEntityId() {
|
||||
return ++lastEntityId;
|
||||
@@ -215,8 +222,8 @@ public class Scene {
|
||||
public SceneInfo toProto() {
|
||||
// Proto
|
||||
var proto = SceneInfo.newInstance()
|
||||
.setWorldId(301)
|
||||
.setLCMMECNPOBA(this.getPlaneId() == GameConstants.HOME_PLANE_ID ? 3 : 2)
|
||||
.setWorldId(this.getExcel().getWorldID())
|
||||
.setLCMMECNPOBA(this.getExcel().getPlaneType().getVal())
|
||||
.setPlaneId(this.getPlaneId())
|
||||
.setFloorId(this.getFloorId())
|
||||
.setEntryId(this.getEntryId());
|
||||
|
||||
@@ -2,6 +2,7 @@ package emu.lunarcore.game.scene.entity;
|
||||
|
||||
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
||||
import emu.lunarcore.data.excel.StageExcel;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.proto.MotionInfoOuterClass.MotionInfo;
|
||||
import emu.lunarcore.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
|
||||
import emu.lunarcore.proto.SceneNpcMonsterInfoOuterClass.SceneNpcMonsterInfo;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class HandlerEnterSceneCsReq extends PacketHandler {
|
||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||
var req = EnterSceneCsReq.parseFrom(data);
|
||||
|
||||
session.getPlayer().enterScene(req.getEntryId(), req.getTeleportId());
|
||||
session.getPlayer().enterScene(req.getEntryId(), req.getTeleportId(), true);
|
||||
session.send(CmdId.EnterSceneScRsp);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user