Add /scene command

This commit is contained in:
Melledy
2023-11-01 12:45:47 -07:00
parent 01256cd605
commit 3ad2cd7841
4 changed files with 74 additions and 11 deletions

View File

@@ -0,0 +1,64 @@
package emu.lunarcore.command.commands;
import emu.lunarcore.command.Command;
import emu.lunarcore.command.CommandArgs;
import emu.lunarcore.command.CommandHandler;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.config.AnchorInfo;
import emu.lunarcore.data.config.FloorInfo;
import emu.lunarcore.data.excel.MazePlaneExcel;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.util.Utils;
@Command(label = "scene", aliases = {"sc"}, permission = "player.scene", desc = "/scene [scene id] [floor id]. Teleports the player to the specified scene.")
public class SceneCommand implements CommandHandler {
@Override
public void execute(Player sender, CommandArgs args) {
// Check target
if (args.getTarget() == null) {
this.sendMessage(sender, "Error: Targeted player not found or offline");
return;
}
// Get arguments
int planeId = Utils.parseSafeInt(args.get(0));
int floorId = Utils.parseSafeInt(args.get(1));
// Get maze plane
MazePlaneExcel excel = GameData.getMazePlaneExcelMap().get(planeId);
if (excel == null) {
this.sendMessage(sender, "Error: Maze plane not found");
return;
}
if (floorId <= 0) {
floorId = excel.getStartFloorID();
}
// Get floor info
FloorInfo floor = GameData.getFloorInfo(planeId, floorId);
if (floor == null) {
this.sendMessage(sender, "Error: Floor info not found");
return;
}
int startGroup = floor.getStartGroupID();
int anchorId = floor.getStartAnchorID();
AnchorInfo anchor = floor.getAnchorInfo(startGroup, anchorId);
if (anchor == null) {
this.sendMessage(sender, "Error: Floor info not found");
return;
}
// Move player to scene
boolean success = args.getTarget().loadScene(planeId, floorId, 0, anchor.getPos(), anchor.getRot(), true);
// Send packet
if (success) {
this.sendMessage(sender, "Teleported player to " + planeId);
}
}
}

View File

@@ -12,6 +12,7 @@ import lombok.Getter;
public class MazePlaneExcel extends GameResource { public class MazePlaneExcel extends GameResource {
private int PlaneID; private int PlaneID;
private int WorldID; private int WorldID;
private int StartFloorID;
private long PlaneName; private long PlaneName;
@SerializedName(value = "PlaneType") @SerializedName(value = "PlaneType")

View File

@@ -462,18 +462,10 @@ public class Player {
if (anchor == null) return false; if (anchor == null) return false;
// Move player to scene // Move player to scene
boolean success = this.loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId(), anchor.getPos(), anchor.getRot()); return this.loadScene(entry.getPlaneID(), entry.getFloorID(), entry.getId(), anchor.getPos(), anchor.getRot(), sendPacket);
// Send packet
if (success && sendPacket) {
this.sendPacket(new PacketEnterSceneByServerScNotify(this));
}
// Success
return success;
} }
private boolean loadScene(int planeId, int floorId, int entryId, Position pos, Position rot) { public boolean loadScene(int planeId, int floorId, int entryId, Position pos, Position rot, boolean sendPacket) {
// Get maze plane excel // Get maze plane excel
MazePlaneExcel planeExcel = GameData.getMazePlaneExcelMap().get(planeId); MazePlaneExcel planeExcel = GameData.getMazePlaneExcelMap().get(planeId);
if (planeExcel == null) return false; if (planeExcel == null) return false;
@@ -517,6 +509,11 @@ public class Player {
this.scene = nextScene; this.scene = nextScene;
this.scene.setEntryId(entryId); this.scene.setEntryId(entryId);
// Send packet
if (sendPacket) {
this.sendPacket(new PacketEnterSceneByServerScNotify(this));
}
// Done, return success // Done, return success
return true; return true;
} }
@@ -563,7 +560,7 @@ public class Player {
} }
// Load into saved 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(), false);
// Unstuck check in case we couldn't load the scene // Unstuck check in case we couldn't load the scene
if (this.getScene() == null) { if (this.getScene() == null) {

View File

@@ -117,6 +117,7 @@ public class Handbook {
MazePlaneExcel excel = GameData.getMazePlaneExcelMap().get(id); MazePlaneExcel excel = GameData.getMazePlaneExcelMap().get(id);
writer.print(excel.getId()); writer.print(excel.getId());
writer.print(" : "); writer.print(" : ");
writer.print("[" + excel.getPlaneType() + "] ");
writer.println(textMap.getOrDefault(excel.getPlaneName(), "null")); writer.println(textMap.getOrDefault(excel.getPlaneName(), "null"));
} }
} catch (IOException e) { } catch (IOException e) {