Add /unstuck command

This commit is contained in:
Melledy
2023-10-18 05:07:55 -07:00
parent 594898fd57
commit 345ab7d3e9
3 changed files with 64 additions and 6 deletions

View File

@@ -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;

View File

@@ -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");
}
}
}

View File

@@ -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;