From 345ab7d3e94933a1b3044b6f7cf87ef0ab0c6792 Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Wed, 18 Oct 2023 05:07:55 -0700 Subject: [PATCH] Add /unstuck command --- .../java/emu/lunarcore/GameConstants.java | 7 +++ .../command/commands/UnstuckCommand.java | 44 +++++++++++++++++++ .../emu/lunarcore/game/player/Player.java | 19 +++++--- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/main/java/emu/lunarcore/command/commands/UnstuckCommand.java diff --git a/src/main/java/emu/lunarcore/GameConstants.java b/src/main/java/emu/lunarcore/GameConstants.java index dc2410d..b10a9cc 100644 --- a/src/main/java/emu/lunarcore/GameConstants.java +++ b/src/main/java/emu/lunarcore/GameConstants.java @@ -3,6 +3,8 @@ package emu.lunarcore; import java.time.Instant; import java.time.ZoneOffset; +import emu.lunarcore.util.Position; + public class GameConstants { public static String VERSION = "1.4.0"; public static String MDK_VERSION = ""; @@ -21,6 +23,11 @@ public class GameConstants { public static final int MAX_CHAT_HISTORY = 100; // Max chat messages per conversation + public static final int START_PLANE_ID = 20001; + public static final int START_FLOOR_ID = 20001001; + public static final int START_ENTRY_ID = 2000101; + public static final Position START_POS = new Position(99, 62, -4800); + // Custom public static final int SERVER_CONSOLE_UID = 99; public static final int EQUIPMENT_SLOT_ID = 100; diff --git a/src/main/java/emu/lunarcore/command/commands/UnstuckCommand.java b/src/main/java/emu/lunarcore/command/commands/UnstuckCommand.java new file mode 100644 index 0000000..4c20592 --- /dev/null +++ b/src/main/java/emu/lunarcore/command/commands/UnstuckCommand.java @@ -0,0 +1,44 @@ +package emu.lunarcore.command.commands; + +import emu.lunarcore.LunarRail; +import emu.lunarcore.command.Command; +import emu.lunarcore.command.CommandArgs; +import emu.lunarcore.command.CommandHandler; +import emu.lunarcore.game.player.Player; +import emu.lunarcore.game.player.PlayerGender; +import emu.lunarcore.server.packet.send.PacketGetHeroBasicTypeInfoScRsp; + +@Command(label = "unstuck", permission = "admin.unstuck", desc = "/unstuck @[player id]. Unstucks an offline player if theyre in a scene that doesnt load.") +public class UnstuckCommand implements CommandHandler { + + @Override + public void execute(Player sender, CommandArgs args) { + // Make sure were on the game server + if (LunarRail.getGameDatabase() == null) { + this.sendMessage(sender, "Error: Game database not connected"); + return; + } + + // TODO add some logic to handle unstucking the target if theyre online + if (args.getTarget() != null) { + this.sendMessage(sender, "Error: Targeted player is online"); + return; + } + + // Get player from the database + Player player = LunarRail.getGameDatabase().getObjectByField(Player.class, "_id", args.getTargetUid()); + + if (player != null) { + // Reset position for the player + player.resetPosition(); + player.save(); + + // Done + this.sendMessage(sender, "Player unstuck successfully"); + } else { + // Done + this.sendMessage(sender, "Error: Player not found in database"); + } + } + +} diff --git a/src/main/java/emu/lunarcore/game/player/Player.java b/src/main/java/emu/lunarcore/game/player/Player.java index d05a597..a5760fe 100644 --- a/src/main/java/emu/lunarcore/game/player/Player.java +++ b/src/main/java/emu/lunarcore/game/player/Player.java @@ -110,6 +110,7 @@ public class Player { // Called when player is created public Player(GameSession session) { this(); + this.resetPosition(); this.session = session; this.accountUid = getAccount().getUid(); this.name = GameConstants.DEFAULT_NAME; @@ -118,12 +119,6 @@ public class Player { this.level = 1; 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; - this.unlockedHeadIcons = new HashSet<>(); this.lineupManager = new LineupManager(this); this.gachaInfo = new PlayerGachaInfo(); @@ -217,6 +212,18 @@ public class Player { } return false; } + + public void resetPosition() { + if (this.hasLoggedIn()) { + return; + } + + this.pos = GameConstants.START_POS.clone(); + this.rot = new Position(); + this.planeId = GameConstants.START_PLANE_ID; + this.floorId = GameConstants.START_FLOOR_ID; + this.entryId = GameConstants.START_ENTRY_ID; + } public boolean hasLoggedIn() { return this.getSession() != null && this.getSession().getState() != SessionState.WAITING_FOR_TOKEN;