mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2024-11-24 04:49:47 +00:00
Refactor PacketSceneTransToPointRsp and add a null check when getting ScenePointEntries
This commit is contained in:
parent
1250194480
commit
b99ca4e02f
@ -23,11 +23,17 @@ public final class ChangeSceneCommand implements CommandHandler {
|
||||
|
||||
try {
|
||||
int sceneId = Integer.parseInt(args.get(0));
|
||||
|
||||
if (sceneId == sender.getSceneId()) {
|
||||
CommandHandler.sendMessage(sender, "You are already in that scene");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, sender.getPos());
|
||||
|
||||
CommandHandler.sendMessage(sender, "Changed to scene " + sceneId);
|
||||
|
||||
if (!result) {
|
||||
CommandHandler.sendMessage(sender, "Scene does not exist or you are already in it");
|
||||
CommandHandler.sendMessage(sender, "Scene does not exist");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CommandHandler.sendMessage(sender, "Usage: changescene <scene id>");
|
||||
|
@ -206,28 +206,9 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
public void deregisterScene(GenshinScene scene) {
|
||||
this.getScenes().remove(scene.getId());
|
||||
}
|
||||
|
||||
public boolean forceTransferPlayerToScene(GenshinPlayer player, int sceneId, Position pos) {
|
||||
// Forces the client to reload the scene map to prevent the player from falling off the map.
|
||||
if (GenshinData.getSceneDataMap().get(sceneId) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.getScene() != null) {
|
||||
player.getScene().removePlayer(player);
|
||||
}
|
||||
|
||||
GenshinScene scene = this.getSceneById(sceneId);
|
||||
scene.addPlayer(player);
|
||||
player.getPos().set(pos);
|
||||
|
||||
// Teleport packet
|
||||
player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterSelf, EnterReason.TransPoint, sceneId, pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean transferPlayerToScene(GenshinPlayer player, int sceneId, Position pos) {
|
||||
if (player.getScene().getId() == sceneId || GenshinData.getSceneDataMap().get(sceneId) == null) {
|
||||
if (GenshinData.getSceneDataMap().get(sceneId) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,15 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.data.GenshinData;
|
||||
import emu.grasscutter.data.custom.ScenePointEntry;
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq;
|
||||
import emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp;
|
||||
import emu.grasscutter.utils.Position;
|
||||
|
||||
@Opcodes(PacketOpcodes.SceneTransToPointReq)
|
||||
public class HandlerSceneTransToPointReq extends PacketHandler {
|
||||
@ -13,7 +17,20 @@ public class HandlerSceneTransToPointReq extends PacketHandler {
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload);
|
||||
session.send(new PacketSceneTransToPointRsp(session.getPlayer(), req.getPointId(), req.getSceneId()));
|
||||
|
||||
String code = req.getSceneId() + "_" + req.getPointId();
|
||||
ScenePointEntry scenePointEntry = GenshinData.getScenePointEntries().get(code);
|
||||
|
||||
if (scenePointEntry != null) {
|
||||
float x = scenePointEntry.getPointData().getTranPos().getX();
|
||||
float y = scenePointEntry.getPointData().getTranPos().getY();
|
||||
float z = scenePointEntry.getPointData().getTranPos().getZ();
|
||||
|
||||
session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getSceneId(), new Position(x, y, z));
|
||||
session.send(new PacketSceneTransToPointRsp(session.getPlayer(), req.getPointId(), req.getSceneId()));
|
||||
} else {
|
||||
session.send(new PacketSceneTransToPointRsp());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,23 +13,22 @@ public class PacketSceneTransToPointRsp extends GenshinPacket {
|
||||
public PacketSceneTransToPointRsp(GenshinPlayer player, int pointId, int sceneId) {
|
||||
super(PacketOpcodes.SceneTransToPointRsp);
|
||||
|
||||
String code = sceneId + "_" + pointId;
|
||||
ScenePointEntry scenePointEntry = GenshinData.getScenePointEntries().get(code);
|
||||
|
||||
float x = scenePointEntry.getPointData().getTranPos().getX();
|
||||
float y = scenePointEntry.getPointData().getTranPos().getY();
|
||||
float z = scenePointEntry.getPointData().getTranPos().getZ();
|
||||
|
||||
player.getPos().set(new Position(x, y, z));
|
||||
|
||||
player.getWorld().forceTransferPlayerToScene(player, sceneId, player.getPos());
|
||||
|
||||
SceneTransToPointRsp proto = SceneTransToPointRsp.newBuilder()
|
||||
.setRetcode(0)
|
||||
.setPointId(pointId)
|
||||
.setSceneId(sceneId)
|
||||
.build();
|
||||
.setRetcode(0)
|
||||
.setPointId(pointId)
|
||||
.setSceneId(sceneId)
|
||||
.build();
|
||||
|
||||
this.setData(proto);
|
||||
}
|
||||
|
||||
public PacketSceneTransToPointRsp() {
|
||||
super(PacketOpcodes.SceneTransToPointRsp);
|
||||
|
||||
SceneTransToPointRsp proto = SceneTransToPointRsp.newBuilder()
|
||||
.setRetcode(1) // Internal server error
|
||||
.build();
|
||||
|
||||
this.setData(proto);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user