mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-14 22:34:35 +01:00
Unstuck players on login if they are loading into a bad scene
This commit is contained in:
@@ -29,8 +29,11 @@ public class GameConstants {
|
||||
public static final int START_ENTRY_ID = 2000101;
|
||||
public static final Position START_POS = new Position(99, 62, -4800);
|
||||
|
||||
// Challenge
|
||||
public static final int CHALLENGE_ENTRANCE = 100000103;
|
||||
|
||||
// Rogue
|
||||
public static final int ROGUE_LEAVE_ENTRANCE = 801120102;
|
||||
public static final int ROGUE_ENTRANCE = 801120102;
|
||||
|
||||
// Custom
|
||||
public static final int SERVER_CONSOLE_UID = 99;
|
||||
|
||||
@@ -23,7 +23,6 @@ import lombok.Setter;
|
||||
@Getter
|
||||
public class ChallengeInstance {
|
||||
private final Player player;
|
||||
private final Scene scene;
|
||||
private final ChallengeExcel excel;
|
||||
private final Position startPos;
|
||||
private final Position startRot;
|
||||
@@ -38,7 +37,6 @@ public class ChallengeInstance {
|
||||
|
||||
public ChallengeInstance(Player player, ChallengeExcel excel) {
|
||||
this.player = player;
|
||||
this.scene = player.getScene();
|
||||
this.excel = excel;
|
||||
this.startPos = player.getPos().clone();
|
||||
this.startRot = player.getRot().clone();
|
||||
@@ -46,16 +44,17 @@ public class ChallengeInstance {
|
||||
this.roundsLeft = excel.getChallengeCountDown();
|
||||
this.status = ChallengeStatus.CHALLENGE_DOING;
|
||||
this.currentExtraLineup = ExtraLineupType.LINEUP_CHALLENGE;
|
||||
}
|
||||
|
||||
// Setup first stage
|
||||
this.setupStage1();
|
||||
private Scene getScene() {
|
||||
return this.getPlayer().getScene();
|
||||
}
|
||||
|
||||
private int getChallengeId() {
|
||||
return this.getExcel().getId();
|
||||
}
|
||||
|
||||
private void setupStage1() {
|
||||
protected void setupStage1() {
|
||||
this.setupStage(
|
||||
excel.getMazeGroupID1(),
|
||||
excel.getConfigList1(),
|
||||
@@ -65,7 +64,7 @@ public class ChallengeInstance {
|
||||
);
|
||||
}
|
||||
|
||||
private void setupStage2() {
|
||||
protected void setupStage2() {
|
||||
this.setupStage(
|
||||
excel.getMazeGroupID2(),
|
||||
excel.getConfigList2(),
|
||||
@@ -97,10 +96,10 @@ public class ChallengeInstance {
|
||||
// Create monster with excels
|
||||
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, monsterInfo.getPos());
|
||||
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
||||
monster.setGroupId(group.getId());
|
||||
monster.setInstId(instId);
|
||||
monster.setEventId(eventId);
|
||||
monster.setOverrideStageId(eventId);
|
||||
monster.setGroupId(group.getId());
|
||||
monster.setWorldLevel(this.getPlayer().getWorldLevel());
|
||||
|
||||
// Add to scene
|
||||
|
||||
@@ -61,15 +61,23 @@ public class ChallengeManager extends BasePlayerManager {
|
||||
// Set first lineup before we enter scenes
|
||||
getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE_VALUE, false);
|
||||
|
||||
// Set challenge data for player
|
||||
ChallengeInstance instance = new ChallengeInstance(getPlayer(), excel);
|
||||
getPlayer().setChallengeInstance(instance);
|
||||
|
||||
// Enter scene
|
||||
boolean success = getPlayer().enterScene(excel.getMapEntranceID(), 0, false);
|
||||
if (success == false) {
|
||||
if (!success) {
|
||||
// Reset lineup/instance if entering scene failed
|
||||
getPlayer().getLineupManager().setCurrentExtraLineup(0, false);
|
||||
getPlayer().setChallengeInstance(null);
|
||||
// Send error packet
|
||||
getPlayer().sendPacket(new PacketStartChallengeScRsp());
|
||||
return;
|
||||
}
|
||||
|
||||
// Set challenge data for player
|
||||
ChallengeInstance data = new ChallengeInstance(getPlayer(), excel);
|
||||
getPlayer().setChallengeInstance(data);
|
||||
// Setup first challenge stage
|
||||
instance.setupStage1();
|
||||
|
||||
// Send packet
|
||||
getPlayer().sendPacket(new PacketStartChallengeScRsp(getPlayer(), challengeId));
|
||||
|
||||
@@ -24,6 +24,7 @@ import emu.lunarcore.game.challenge.ChallengeInstance;
|
||||
import emu.lunarcore.game.challenge.ChallengeManager;
|
||||
import emu.lunarcore.game.chat.ChatManager;
|
||||
import emu.lunarcore.game.chat.ChatMessage;
|
||||
import emu.lunarcore.game.enums.PlaneType;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||
import emu.lunarcore.game.inventory.Inventory;
|
||||
@@ -468,8 +469,21 @@ public class Player {
|
||||
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) {
|
||||
return false;
|
||||
if (planeExcel == null) return false;
|
||||
|
||||
// Unstuck check
|
||||
if (planeExcel.getPlaneType() == PlaneType.Challenge) {
|
||||
if (this.getChallengeInstance() == null) {
|
||||
return enterScene(GameConstants.CHALLENGE_ENTRANCE, 0, false);
|
||||
}
|
||||
} else {
|
||||
this.setChallengeInstance(null);
|
||||
}
|
||||
|
||||
if (planeExcel.getPlaneType() == PlaneType.Rogue) {
|
||||
if (this.getRogueInstance() == null) {
|
||||
return enterScene(GameConstants.ROGUE_ENTRANCE, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Get scene that we want to enter
|
||||
@@ -482,11 +496,8 @@ public class Player {
|
||||
nextScene = new Scene(this, planeExcel, floorId);
|
||||
}
|
||||
|
||||
// Clear any extra data the player might have
|
||||
this.setChallengeInstance(null);
|
||||
|
||||
// Set positions if player has logged in
|
||||
if (this.getSession().getState() != SessionState.WAITING_FOR_TOKEN) {
|
||||
// Save if scene has changed
|
||||
if (this.planeId != planeId || this.floorId != floorId || this.entryId != entryId) {
|
||||
this.getPos().set(pos);
|
||||
this.getRot().set(rot);
|
||||
this.planeId = planeId;
|
||||
@@ -537,8 +548,13 @@ public class Player {
|
||||
this.getLineupManager().validate(this);
|
||||
this.getAvatars().setupHeroPaths();
|
||||
|
||||
// Enter scene (should happen after everything else loads)
|
||||
// Load into saved scene (should happen after everything else loads)
|
||||
this.loadScene(planeId, floorId, entryId, this.getPos(), this.getRot());
|
||||
|
||||
// Unstuck check in case we couldn't load the scene
|
||||
if (this.getScene() == null) {
|
||||
this.enterScene(GameConstants.START_ENTRY_ID, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RogueManager extends BasePlayerManager {
|
||||
|
||||
// Get entrance id
|
||||
RogueInstance data = new RogueInstance(getPlayer(), excel);
|
||||
int entranceId = data.getCurrentRoom().getRoomExcel().getMapEntrance();
|
||||
getPlayer().setRogueInstance(data);
|
||||
|
||||
// Reset hp/sp
|
||||
lineup.forEachAvatar(avatar -> {
|
||||
@@ -70,18 +70,17 @@ public class RogueManager extends BasePlayerManager {
|
||||
getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_ROGUE, false);
|
||||
|
||||
// Enter scene
|
||||
int entranceId = data.getCurrentRoom().getRoomExcel().getMapEntrance();
|
||||
boolean success = getPlayer().enterScene(entranceId, 0, false);
|
||||
if (!success) {
|
||||
// Clear extra lineup if entering scene failed
|
||||
// Reset lineup/instance if entering scene failed
|
||||
getPlayer().getLineupManager().setCurrentExtraLineup(0, false);
|
||||
getPlayer().setRogueInstance(null);
|
||||
// Send error packet
|
||||
getPlayer().sendPacket(new PacketStartRogueScRsp());
|
||||
return;
|
||||
}
|
||||
|
||||
// Set rogue data
|
||||
getPlayer().setRogueInstance(data);
|
||||
|
||||
// Get room excel
|
||||
RogueRoomExcel roomExcel = data.getCurrentRoom().getExcel();
|
||||
|
||||
@@ -108,7 +107,7 @@ public class RogueManager extends BasePlayerManager {
|
||||
}
|
||||
|
||||
getPlayer().setRogueInstance(null);
|
||||
getPlayer().enterScene(GameConstants.ROGUE_LEAVE_ENTRANCE, 0, true); // Test
|
||||
getPlayer().enterScene(GameConstants.ROGUE_ENTRANCE, 0, true); // Test
|
||||
getPlayer().getSession().send(CmdId.QuitRogueScRsp);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
@@ -12,7 +13,7 @@ public class HandlerLeaveChallengeCsReq extends PacketHandler {
|
||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||
// TODO make sure client is in a challenge mode map
|
||||
session.getPlayer().getLineupManager().setCurrentExtraLineup(0, false);
|
||||
session.getPlayer().enterScene(100000103, 0, true);
|
||||
session.getPlayer().enterScene(GameConstants.CHALLENGE_ENTRANCE, 0, true);
|
||||
session.send(CmdId.LeaveChallengeScRsp);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user