mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 05:44:36 +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 float RotY;
|
||||
|
||||
/*
|
||||
* Returns a new Position object
|
||||
*/
|
||||
public Position clonePos() {
|
||||
return new Position((int) (this.PosX * 1000f), (int) (this.PosY * 1000f), (int) (this.PosZ * 1000f));
|
||||
protected transient Position pos;
|
||||
protected transient Position rot;
|
||||
|
||||
public Position getPos() {
|
||||
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.scene.triggers.PropTrigger;
|
||||
import emu.lunarcore.util.Position;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -25,6 +26,14 @@ public class PropInfo extends ObjectInfo {
|
||||
|
||||
@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) {
|
||||
if (this.getValueSource() == null) return null;
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ public class GameAvatar implements GameEntity {
|
||||
public SceneEntityInfo toSceneEntityProto() {
|
||||
var proto = SceneEntityInfo.newInstance()
|
||||
.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));
|
||||
|
||||
return proto;
|
||||
|
||||
@@ -252,7 +252,7 @@ public class BattleService extends BaseGameService {
|
||||
anchorProp.getPropInfo().getAnchorID()
|
||||
);
|
||||
if (anchor != null) {
|
||||
player.moveTo(anchor.clonePos());
|
||||
player.moveTo(anchor.getPos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ChallengeData {
|
||||
private final Scene scene;
|
||||
private final ChallengeExcel excel;
|
||||
private final Position startPos;
|
||||
private final Position startRot;
|
||||
|
||||
private int currentStage;
|
||||
private ExtraLineupType currentExtraLineup;
|
||||
@@ -39,6 +40,7 @@ public class ChallengeData {
|
||||
this.scene = player.getScene();
|
||||
this.excel = excel;
|
||||
this.startPos = player.getPos().clone();
|
||||
this.startRot = player.getRot().clone();
|
||||
this.currentStage = 1;
|
||||
this.roundsLimit = excel.getChallengeCountDown();
|
||||
this.status = ChallengeStatus.CHALLENGE_DOING;
|
||||
@@ -92,7 +94,7 @@ public class ChallengeData {
|
||||
if (npcMonsterExcel == null) continue;
|
||||
|
||||
// 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.setInstId(instId);
|
||||
monster.setEventId(eventId);
|
||||
@@ -137,7 +139,7 @@ public class ChallengeData {
|
||||
player.getLineupManager().setCurrentExtraLineup(this.getCurrentExtraLineup(), true);
|
||||
player.sendPacket(new PacketChallengeLineupNotify(this.getCurrentExtraLineup()));
|
||||
// Move player
|
||||
player.moveTo(this.getStartPos());
|
||||
player.moveTo(this.getStartPos(), this.getStartRot());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -69,6 +69,7 @@ public class Player {
|
||||
private transient Battle battle;
|
||||
private transient Scene scene;
|
||||
private Position pos;
|
||||
private Position rot;
|
||||
private int planeId;
|
||||
private int floorId;
|
||||
private int entryId;
|
||||
@@ -115,6 +116,7 @@ public class Player {
|
||||
this.stamina = GameConstants.MAX_STAMINA;
|
||||
|
||||
this.pos = new Position(99, 62, -4800);
|
||||
this.rot = new Position();
|
||||
this.planeId = 20001;
|
||||
this.floorId = 20001001;
|
||||
this.entryId = 2000101;
|
||||
@@ -394,6 +396,12 @@ public class Player {
|
||||
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) {
|
||||
// Get map entrance excel
|
||||
MapEntranceExcel entry = GameData.getMapEntranceExcelMap().get(entryId);
|
||||
@@ -422,7 +430,7 @@ public class Player {
|
||||
if (anchor == null) return false;
|
||||
|
||||
// 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
|
||||
if (success && sendPacket) {
|
||||
@@ -433,7 +441,7 @@ public class Player {
|
||||
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
|
||||
MazePlaneExcel planeExcel = GameData.getMazePlaneExcelMap().get(planeId);
|
||||
if (planeExcel == null) {
|
||||
@@ -456,6 +464,7 @@ public class Player {
|
||||
// Set positions if player has logged in
|
||||
if (this.getSession().getState() != SessionState.WAITING_FOR_TOKEN) {
|
||||
this.getPos().set(pos);
|
||||
this.getRot().set(rot);
|
||||
this.planeId = planeId;
|
||||
this.floorId = floorId;
|
||||
this.entryId = entryId;
|
||||
@@ -491,6 +500,9 @@ public class Player {
|
||||
}
|
||||
|
||||
public void onLogin() {
|
||||
// Validate
|
||||
if (this.getRot() == null) this.rot = new Position();
|
||||
|
||||
// Load avatars and inventory first
|
||||
this.getAvatars().loadFromDatabase();
|
||||
this.getInventory().loadFromDatabase();
|
||||
@@ -501,7 +513,7 @@ public class Player {
|
||||
this.getAvatars().setupHeroPaths();
|
||||
|
||||
// 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
|
||||
|
||||
@@ -113,8 +113,8 @@ public class Scene {
|
||||
if (npcMonsterExcel == null) continue;
|
||||
|
||||
// Create monster with excels
|
||||
EntityMonster monster = new EntityMonster(this, npcMonsterExcel, monsterInfo.clonePos());
|
||||
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
||||
EntityMonster monster = new EntityMonster(this, npcMonsterExcel, monsterInfo.getPos());
|
||||
monster.getRot().set(monsterInfo.getRot());
|
||||
monster.setInstId(monsterInfo.getID());
|
||||
monster.setEventId(monsterInfo.getEventID());
|
||||
monster.setGroupId(group.getId());
|
||||
@@ -135,13 +135,9 @@ public class Scene {
|
||||
}
|
||||
|
||||
// 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.getRot().set(
|
||||
(int) (propInfo.getRotX() * 1000f),
|
||||
(int) (propInfo.getRotY() * 1000f),
|
||||
(int) (propInfo.getRotZ() * 1000f)
|
||||
);
|
||||
prop.getRot().set(propInfo.getRot());
|
||||
prop.setInstId(propInfo.getID());
|
||||
prop.setGroupId(group.getId());
|
||||
prop.setPropInfo(propInfo);
|
||||
@@ -184,8 +180,8 @@ public class Scene {
|
||||
if (haseDuplicateNpcId) continue;
|
||||
|
||||
// Create npc from npc info
|
||||
EntityNpc npc = new EntityNpc(this, npcInfo.getNPCID(), npcInfo.clonePos());
|
||||
npc.getRot().setY((int) (npcInfo.getRotY() * 1000f));
|
||||
EntityNpc npc = new EntityNpc(this, npcInfo.getNPCID(), npcInfo.getPos());
|
||||
npc.getRot().set(npcInfo.getRot());
|
||||
npc.setInstId(npcInfo.getID());
|
||||
npc.setGroupId(group.getId());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user