Unstuck players on login if they are loading into a bad scene

This commit is contained in:
Melledy
2023-10-25 11:03:56 -07:00
parent 1a0e64863f
commit 0514a121fc
6 changed files with 56 additions and 30 deletions

View File

@@ -29,8 +29,11 @@ public class GameConstants {
public static final int START_ENTRY_ID = 2000101; public static final int START_ENTRY_ID = 2000101;
public static final Position START_POS = new Position(99, 62, -4800); public static final Position START_POS = new Position(99, 62, -4800);
// Challenge
public static final int CHALLENGE_ENTRANCE = 100000103;
// Rogue // Rogue
public static final int ROGUE_LEAVE_ENTRANCE = 801120102; public static final int ROGUE_ENTRANCE = 801120102;
// Custom // Custom
public static final int SERVER_CONSOLE_UID = 99; public static final int SERVER_CONSOLE_UID = 99;

View File

@@ -23,7 +23,6 @@ import lombok.Setter;
@Getter @Getter
public class ChallengeInstance { public class ChallengeInstance {
private final Player player; private final Player player;
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 final Position startRot;
@@ -38,7 +37,6 @@ public class ChallengeInstance {
public ChallengeInstance(Player player, ChallengeExcel excel) { public ChallengeInstance(Player player, ChallengeExcel excel) {
this.player = player; this.player = player;
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.startRot = player.getRot().clone();
@@ -46,16 +44,17 @@ public class ChallengeInstance {
this.roundsLeft = excel.getChallengeCountDown(); this.roundsLeft = excel.getChallengeCountDown();
this.status = ChallengeStatus.CHALLENGE_DOING; this.status = ChallengeStatus.CHALLENGE_DOING;
this.currentExtraLineup = ExtraLineupType.LINEUP_CHALLENGE; this.currentExtraLineup = ExtraLineupType.LINEUP_CHALLENGE;
}
// Setup first stage
this.setupStage1(); private Scene getScene() {
return this.getPlayer().getScene();
} }
private int getChallengeId() { private int getChallengeId() {
return this.getExcel().getId(); return this.getExcel().getId();
} }
private void setupStage1() { protected void setupStage1() {
this.setupStage( this.setupStage(
excel.getMazeGroupID1(), excel.getMazeGroupID1(),
excel.getConfigList1(), excel.getConfigList1(),
@@ -65,7 +64,7 @@ public class ChallengeInstance {
); );
} }
private void setupStage2() { protected void setupStage2() {
this.setupStage( this.setupStage(
excel.getMazeGroupID2(), excel.getMazeGroupID2(),
excel.getConfigList2(), excel.getConfigList2(),
@@ -97,10 +96,10 @@ public class ChallengeInstance {
// Create monster with excels // Create monster with excels
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, monsterInfo.getPos()); EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, monsterInfo.getPos());
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f)); monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
monster.setGroupId(group.getId());
monster.setInstId(instId); monster.setInstId(instId);
monster.setEventId(eventId); monster.setEventId(eventId);
monster.setOverrideStageId(eventId); monster.setOverrideStageId(eventId);
monster.setGroupId(group.getId());
monster.setWorldLevel(this.getPlayer().getWorldLevel()); monster.setWorldLevel(this.getPlayer().getWorldLevel());
// Add to scene // Add to scene

View File

@@ -61,15 +61,23 @@ public class ChallengeManager extends BasePlayerManager {
// Set first lineup before we enter scenes // Set first lineup before we enter scenes
getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE_VALUE, false); getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE_VALUE, false);
// Set challenge data for player
ChallengeInstance instance = new ChallengeInstance(getPlayer(), excel);
getPlayer().setChallengeInstance(instance);
// Enter scene // Enter scene
boolean success = getPlayer().enterScene(excel.getMapEntranceID(), 0, false); 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; return;
} }
// Set challenge data for player // Setup first challenge stage
ChallengeInstance data = new ChallengeInstance(getPlayer(), excel); instance.setupStage1();
getPlayer().setChallengeInstance(data);
// Send packet // Send packet
getPlayer().sendPacket(new PacketStartChallengeScRsp(getPlayer(), challengeId)); getPlayer().sendPacket(new PacketStartChallengeScRsp(getPlayer(), challengeId));

View File

@@ -24,6 +24,7 @@ import emu.lunarcore.game.challenge.ChallengeInstance;
import emu.lunarcore.game.challenge.ChallengeManager; import emu.lunarcore.game.challenge.ChallengeManager;
import emu.lunarcore.game.chat.ChatManager; import emu.lunarcore.game.chat.ChatManager;
import emu.lunarcore.game.chat.ChatMessage; import emu.lunarcore.game.chat.ChatMessage;
import emu.lunarcore.game.enums.PlaneType;
import emu.lunarcore.game.enums.PropState; import emu.lunarcore.game.enums.PropState;
import emu.lunarcore.game.gacha.PlayerGachaInfo; import emu.lunarcore.game.gacha.PlayerGachaInfo;
import emu.lunarcore.game.inventory.Inventory; 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) { 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) return false;
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 // Get scene that we want to enter
@@ -481,12 +495,9 @@ public class Player {
} else { } else {
nextScene = new Scene(this, planeExcel, floorId); nextScene = new Scene(this, planeExcel, floorId);
} }
// Clear any extra data the player might have
this.setChallengeInstance(null);
// Set positions if player has logged in // Save if scene has changed
if (this.getSession().getState() != SessionState.WAITING_FOR_TOKEN) { if (this.planeId != planeId || this.floorId != floorId || this.entryId != entryId) {
this.getPos().set(pos); this.getPos().set(pos);
this.getRot().set(rot); this.getRot().set(rot);
this.planeId = planeId; this.planeId = planeId;
@@ -537,8 +548,13 @@ public class Player {
this.getLineupManager().validate(this); this.getLineupManager().validate(this);
this.getAvatars().setupHeroPaths(); 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()); 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 // Proto

View File

@@ -55,8 +55,8 @@ public class RogueManager extends BasePlayerManager {
// Get entrance id // Get entrance id
RogueInstance data = new RogueInstance(getPlayer(), excel); RogueInstance data = new RogueInstance(getPlayer(), excel);
int entranceId = data.getCurrentRoom().getRoomExcel().getMapEntrance(); getPlayer().setRogueInstance(data);
// Reset hp/sp // Reset hp/sp
lineup.forEachAvatar(avatar -> { lineup.forEachAvatar(avatar -> {
avatar.setCurrentHp(lineup, 10000); avatar.setCurrentHp(lineup, 10000);
@@ -70,18 +70,17 @@ public class RogueManager extends BasePlayerManager {
getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_ROGUE, false); getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_ROGUE, false);
// Enter scene // Enter scene
int entranceId = data.getCurrentRoom().getRoomExcel().getMapEntrance();
boolean success = getPlayer().enterScene(entranceId, 0, false); boolean success = getPlayer().enterScene(entranceId, 0, false);
if (!success) { if (!success) {
// Clear extra lineup if entering scene failed // Reset lineup/instance if entering scene failed
getPlayer().getLineupManager().setCurrentExtraLineup(0, false); getPlayer().getLineupManager().setCurrentExtraLineup(0, false);
getPlayer().setRogueInstance(null);
// Send error packet // Send error packet
getPlayer().sendPacket(new PacketStartRogueScRsp()); getPlayer().sendPacket(new PacketStartRogueScRsp());
return; return;
} }
// Set rogue data
getPlayer().setRogueInstance(data);
// Get room excel // Get room excel
RogueRoomExcel roomExcel = data.getCurrentRoom().getExcel(); RogueRoomExcel roomExcel = data.getCurrentRoom().getExcel();
@@ -108,7 +107,7 @@ public class RogueManager extends BasePlayerManager {
} }
getPlayer().setRogueInstance(null); 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); getPlayer().getSession().send(CmdId.QuitRogueScRsp);
} }

View File

@@ -1,5 +1,6 @@
package emu.lunarcore.server.packet.recv; package emu.lunarcore.server.packet.recv;
import emu.lunarcore.GameConstants;
import emu.lunarcore.server.game.GameSession; import emu.lunarcore.server.game.GameSession;
import emu.lunarcore.server.packet.CmdId; import emu.lunarcore.server.packet.CmdId;
import emu.lunarcore.server.packet.Opcodes; 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 { public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
// TODO make sure client is in a challenge mode map // TODO make sure client is in a challenge mode map
session.getPlayer().getLineupManager().setCurrentExtraLineup(0, false); session.getPlayer().getLineupManager().setCurrentExtraLineup(0, false);
session.getPlayer().enterScene(100000103, 0, true); session.getPlayer().enterScene(GameConstants.CHALLENGE_ENTRANCE, 0, true);
session.send(CmdId.LeaveChallengeScRsp); session.send(CmdId.LeaveChallengeScRsp);
} }