mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Implement player rotation saving and optimize ObjectInfo
This commit is contained in:
@@ -12,10 +12,20 @@ public class ObjectInfo {
|
|||||||
public String Name;
|
public String Name;
|
||||||
public float RotY;
|
public float RotY;
|
||||||
|
|
||||||
/*
|
protected transient Position pos;
|
||||||
* Returns a new Position object
|
protected transient Position rot;
|
||||||
*/
|
|
||||||
public Position clonePos() {
|
public Position getPos() {
|
||||||
return new Position((int) (this.PosX * 1000f), (int) (this.PosY * 1000f), (int) (this.PosZ * 1000f));
|
if (this.pos == null) {
|
||||||
|
this.pos = new Position((int) (this.PosX * 1000f), (int) (this.PosY * 1000f), (int) (this.PosZ * 1000f));
|
||||||
|
}
|
||||||
|
return this.pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getRot() {
|
||||||
|
if (this.rot == null) {
|
||||||
|
this.rot = new Position(0, (int) (this.RotY * 1000f), 0);
|
||||||
|
}
|
||||||
|
return this.rot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import emu.lunarcore.game.enums.PropState;
|
import emu.lunarcore.game.enums.PropState;
|
||||||
import emu.lunarcore.game.scene.triggers.PropTrigger;
|
import emu.lunarcore.game.scene.triggers.PropTrigger;
|
||||||
|
import emu.lunarcore.util.Position;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -25,6 +26,14 @@ public class PropInfo extends ObjectInfo {
|
|||||||
|
|
||||||
@Setter private transient PropTrigger trigger;
|
@Setter private transient PropTrigger trigger;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getRot() {
|
||||||
|
if (this.rot == null) {
|
||||||
|
this.rot = new Position((int) (this.RotX * 1000f), (int) (this.RotY * 1000f), (int) (this.RotZ * 1000f));
|
||||||
|
}
|
||||||
|
return this.rot;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSharedValueByKey(String key) {
|
public String getSharedValueByKey(String key) {
|
||||||
if (this.getValueSource() == null) return null;
|
if (this.getValueSource() == null) return null;
|
||||||
|
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ public class GameAvatar implements GameEntity {
|
|||||||
public SceneEntityInfo toSceneEntityProto() {
|
public SceneEntityInfo toSceneEntityProto() {
|
||||||
var proto = SceneEntityInfo.newInstance()
|
var proto = SceneEntityInfo.newInstance()
|
||||||
.setEntityId(this.getEntityId())
|
.setEntityId(this.getEntityId())
|
||||||
.setMotion(MotionInfo.newInstance().setPos(getOwner().getPos().toProto()).setRot(Vector.newInstance().setY(0)))
|
.setMotion(MotionInfo.newInstance().setPos(getOwner().getPos().toProto()).setRot(getOwner().getRot().toProto()))
|
||||||
.setActor(SceneActorInfo.newInstance().setBaseAvatarId(this.getAvatarId()).setAvatarType(AvatarType.AVATAR_FORMAL_TYPE));
|
.setActor(SceneActorInfo.newInstance().setBaseAvatarId(this.getAvatarId()).setAvatarType(AvatarType.AVATAR_FORMAL_TYPE));
|
||||||
|
|
||||||
return proto;
|
return proto;
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ public class BattleService extends BaseGameService {
|
|||||||
anchorProp.getPropInfo().getAnchorID()
|
anchorProp.getPropInfo().getAnchorID()
|
||||||
);
|
);
|
||||||
if (anchor != null) {
|
if (anchor != null) {
|
||||||
player.moveTo(anchor.clonePos());
|
player.moveTo(anchor.getPos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class ChallengeData {
|
|||||||
private final Scene scene;
|
private final Scene scene;
|
||||||
private final ChallengeExcel excel;
|
private final ChallengeExcel excel;
|
||||||
private final Position startPos;
|
private final Position startPos;
|
||||||
|
private final Position startRot;
|
||||||
|
|
||||||
private int currentStage;
|
private int currentStage;
|
||||||
private ExtraLineupType currentExtraLineup;
|
private ExtraLineupType currentExtraLineup;
|
||||||
@@ -39,6 +40,7 @@ public class ChallengeData {
|
|||||||
this.scene = player.getScene();
|
this.scene = player.getScene();
|
||||||
this.excel = excel;
|
this.excel = excel;
|
||||||
this.startPos = player.getPos().clone();
|
this.startPos = player.getPos().clone();
|
||||||
|
this.startRot = player.getRot().clone();
|
||||||
this.currentStage = 1;
|
this.currentStage = 1;
|
||||||
this.roundsLimit = excel.getChallengeCountDown();
|
this.roundsLimit = excel.getChallengeCountDown();
|
||||||
this.status = ChallengeStatus.CHALLENGE_DOING;
|
this.status = ChallengeStatus.CHALLENGE_DOING;
|
||||||
@@ -92,7 +94,7 @@ public class ChallengeData {
|
|||||||
if (npcMonsterExcel == null) continue;
|
if (npcMonsterExcel == null) continue;
|
||||||
|
|
||||||
// Create monster with excels
|
// Create monster with excels
|
||||||
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, monsterInfo.clonePos());
|
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, monsterInfo.getPos());
|
||||||
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
||||||
monster.setInstId(instId);
|
monster.setInstId(instId);
|
||||||
monster.setEventId(eventId);
|
monster.setEventId(eventId);
|
||||||
@@ -137,7 +139,7 @@ public class ChallengeData {
|
|||||||
player.getLineupManager().setCurrentExtraLineup(this.getCurrentExtraLineup(), true);
|
player.getLineupManager().setCurrentExtraLineup(this.getCurrentExtraLineup(), true);
|
||||||
player.sendPacket(new PacketChallengeLineupNotify(this.getCurrentExtraLineup()));
|
player.sendPacket(new PacketChallengeLineupNotify(this.getCurrentExtraLineup()));
|
||||||
// Move player
|
// Move player
|
||||||
player.moveTo(this.getStartPos());
|
player.moveTo(this.getStartPos(), this.getStartRot());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public class Player {
|
|||||||
private transient Battle battle;
|
private transient Battle battle;
|
||||||
private transient Scene scene;
|
private transient Scene scene;
|
||||||
private Position pos;
|
private Position pos;
|
||||||
|
private Position rot;
|
||||||
private int planeId;
|
private int planeId;
|
||||||
private int floorId;
|
private int floorId;
|
||||||
private int entryId;
|
private int entryId;
|
||||||
@@ -115,6 +116,7 @@ public class Player {
|
|||||||
this.stamina = GameConstants.MAX_STAMINA;
|
this.stamina = GameConstants.MAX_STAMINA;
|
||||||
|
|
||||||
this.pos = new Position(99, 62, -4800);
|
this.pos = new Position(99, 62, -4800);
|
||||||
|
this.rot = new Position();
|
||||||
this.planeId = 20001;
|
this.planeId = 20001;
|
||||||
this.floorId = 20001001;
|
this.floorId = 20001001;
|
||||||
this.entryId = 2000101;
|
this.entryId = 2000101;
|
||||||
@@ -394,6 +396,12 @@ public class Player {
|
|||||||
this.sendPacket(new PacketSceneEntityMoveScNotify(this));
|
this.sendPacket(new PacketSceneEntityMoveScNotify(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void moveTo(Position pos, Position rot) {
|
||||||
|
this.getPos().set(pos);
|
||||||
|
this.getRot().set(rot);
|
||||||
|
this.sendPacket(new PacketSceneEntityMoveScNotify(this));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean enterScene(int entryId, int teleportId, boolean sendPacket) {
|
public boolean enterScene(int entryId, int teleportId, boolean sendPacket) {
|
||||||
// Get map entrance excel
|
// Get map entrance excel
|
||||||
MapEntranceExcel entry = GameData.getMapEntranceExcelMap().get(entryId);
|
MapEntranceExcel entry = GameData.getMapEntranceExcelMap().get(entryId);
|
||||||
@@ -422,7 +430,7 @@ public class Player {
|
|||||||
if (anchor == null) return false;
|
if (anchor == null) return false;
|
||||||
|
|
||||||
// Move player to scene
|
// Move player to scene
|
||||||
boolean success = this.loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId(), anchor.clonePos());
|
boolean success = this.loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId(), anchor.getPos(), anchor.getRot());
|
||||||
|
|
||||||
// Send packet
|
// Send packet
|
||||||
if (success && sendPacket) {
|
if (success && sendPacket) {
|
||||||
@@ -433,7 +441,7 @@ public class Player {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean loadScene(int planeId, int floorId, int entryId, Position pos) {
|
private boolean loadScene(int planeId, int floorId, int entryId, Position pos, Position rot) {
|
||||||
// Get maze plane excel
|
// Get maze plane excel
|
||||||
MazePlaneExcel planeExcel = GameData.getMazePlaneExcelMap().get(planeId);
|
MazePlaneExcel planeExcel = GameData.getMazePlaneExcelMap().get(planeId);
|
||||||
if (planeExcel == null) {
|
if (planeExcel == null) {
|
||||||
@@ -456,6 +464,7 @@ public class Player {
|
|||||||
// Set positions if player has logged in
|
// Set positions if player has logged in
|
||||||
if (this.getSession().getState() != SessionState.WAITING_FOR_TOKEN) {
|
if (this.getSession().getState() != SessionState.WAITING_FOR_TOKEN) {
|
||||||
this.getPos().set(pos);
|
this.getPos().set(pos);
|
||||||
|
this.getRot().set(rot);
|
||||||
this.planeId = planeId;
|
this.planeId = planeId;
|
||||||
this.floorId = floorId;
|
this.floorId = floorId;
|
||||||
this.entryId = entryId;
|
this.entryId = entryId;
|
||||||
@@ -491,6 +500,9 @@ public class Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onLogin() {
|
public void onLogin() {
|
||||||
|
// Validate
|
||||||
|
if (this.getRot() == null) this.rot = new Position();
|
||||||
|
|
||||||
// Load avatars and inventory first
|
// Load avatars and inventory first
|
||||||
this.getAvatars().loadFromDatabase();
|
this.getAvatars().loadFromDatabase();
|
||||||
this.getInventory().loadFromDatabase();
|
this.getInventory().loadFromDatabase();
|
||||||
@@ -501,7 +513,7 @@ public class Player {
|
|||||||
this.getAvatars().setupHeroPaths();
|
this.getAvatars().setupHeroPaths();
|
||||||
|
|
||||||
// Enter scene (should happen after everything else loads)
|
// Enter scene (should happen after everything else loads)
|
||||||
this.loadScene(planeId, floorId, entryId, this.getPos());
|
this.loadScene(planeId, floorId, entryId, this.getPos(), this.getRot());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proto
|
// Proto
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ public class Scene {
|
|||||||
if (npcMonsterExcel == null) continue;
|
if (npcMonsterExcel == null) continue;
|
||||||
|
|
||||||
// Create monster with excels
|
// Create monster with excels
|
||||||
EntityMonster monster = new EntityMonster(this, npcMonsterExcel, monsterInfo.clonePos());
|
EntityMonster monster = new EntityMonster(this, npcMonsterExcel, monsterInfo.getPos());
|
||||||
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
monster.getRot().set(monsterInfo.getRot());
|
||||||
monster.setInstId(monsterInfo.getID());
|
monster.setInstId(monsterInfo.getID());
|
||||||
monster.setEventId(monsterInfo.getEventID());
|
monster.setEventId(monsterInfo.getEventID());
|
||||||
monster.setGroupId(group.getId());
|
monster.setGroupId(group.getId());
|
||||||
@@ -135,13 +135,9 @@ public class Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create prop from prop info
|
// Create prop from prop info
|
||||||
EntityProp prop = new EntityProp(this, propExcel, propInfo.clonePos());
|
EntityProp prop = new EntityProp(this, propExcel, propInfo.getPos());
|
||||||
prop.setState(propInfo.getState());
|
prop.setState(propInfo.getState());
|
||||||
prop.getRot().set(
|
prop.getRot().set(propInfo.getRot());
|
||||||
(int) (propInfo.getRotX() * 1000f),
|
|
||||||
(int) (propInfo.getRotY() * 1000f),
|
|
||||||
(int) (propInfo.getRotZ() * 1000f)
|
|
||||||
);
|
|
||||||
prop.setInstId(propInfo.getID());
|
prop.setInstId(propInfo.getID());
|
||||||
prop.setGroupId(group.getId());
|
prop.setGroupId(group.getId());
|
||||||
prop.setPropInfo(propInfo);
|
prop.setPropInfo(propInfo);
|
||||||
@@ -184,8 +180,8 @@ public class Scene {
|
|||||||
if (haseDuplicateNpcId) continue;
|
if (haseDuplicateNpcId) continue;
|
||||||
|
|
||||||
// Create npc from npc info
|
// Create npc from npc info
|
||||||
EntityNpc npc = new EntityNpc(this, npcInfo.getNPCID(), npcInfo.clonePos());
|
EntityNpc npc = new EntityNpc(this, npcInfo.getNPCID(), npcInfo.getPos());
|
||||||
npc.getRot().setY((int) (npcInfo.getRotY() * 1000f));
|
npc.getRot().set(npcInfo.getRot());
|
||||||
npc.setInstId(npcInfo.getID());
|
npc.setInstId(npcInfo.getID());
|
||||||
npc.setGroupId(group.getId());
|
npc.setGroupId(group.getId());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user