Improve Player::enterScene logic

This commit is contained in:
Melledy
2023-10-02 08:37:38 -07:00
parent 23989366e1
commit ea3a773dbd

View File

@@ -351,36 +351,43 @@ public class Player {
this.sendPacket(new PacketSceneEntityMoveScNotify(this)); this.sendPacket(new PacketSceneEntityMoveScNotify(this));
} }
public void 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);
if (entry == null) return; if (entry == null) return false;
// Get floor info // Get floor info
FloorInfo floor = GameData.getFloorInfo(entry.getPlaneID(), entry.getFloorID()); FloorInfo floor = GameData.getFloorInfo(entry.getPlaneID(), entry.getFloorID());
if (floor == null) return; if (floor == null) return false;
// Get teleport anchor info (contains position) from the entry id // Get teleport anchor info (contains position) from the entry id
int startGroup = entry.getStartGroupID(); int startGroup = entry.getStartGroupID();
int anchorId = entry.getStartAnchorID(); int anchorId = entry.getStartAnchorID();
if (teleportId != 0 || anchorId == 0) {
if (teleportId != 0) {
PropInfo teleport = floor.getCachedTeleports().get(teleportId); PropInfo teleport = floor.getCachedTeleports().get(teleportId);
if (teleport != null) { if (teleport != null) {
startGroup = teleport.getAnchorGroupID(); startGroup = teleport.getAnchorGroupID();
anchorId = teleport.getAnchorID(); anchorId = teleport.getAnchorID();
} }
} else if (anchorId == 0) {
startGroup = floor.getStartGroupID();
anchorId = floor.getStartAnchorID();
} }
AnchorInfo anchor = floor.getAnchorInfo(startGroup, anchorId); AnchorInfo anchor = floor.getAnchorInfo(startGroup, anchorId);
if (anchor == null) return; if (anchor == null) return false;
// Move player to scene // Move player to scene
this.loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId(), anchor.clonePos()); boolean success = this.loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId(), anchor.clonePos());
// Send packet // Send packet
if (sendPacket) { if (success && sendPacket) {
this.sendPacket(new PacketEnterSceneByServerScNotify(this)); this.sendPacket(new PacketEnterSceneByServerScNotify(this));
} }
// 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) {