From 32c70cc83faa80a1c715e6b4fc5438336e49d482 Mon Sep 17 00:00:00 2001 From: Akka <104902222+Akka0@users.noreply.github.com> Date: Thu, 5 May 2022 22:00:11 +0800 Subject: [PATCH] Support of Enter Room Scene --- proto/PersonalSceneJumpReq.proto | 16 ++++++++ proto/PersonalSceneJumpRsp.proto | 19 ++++++++++ .../grasscutter/data/common/PointData.java | 11 +++++- .../recv/HandlerPersonalSceneJumpReq.java | 38 +++++++++++++++++++ .../send/PacketPersonalSceneJumpRsp.java | 20 ++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 proto/PersonalSceneJumpReq.proto create mode 100644 proto/PersonalSceneJumpRsp.proto create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java diff --git a/proto/PersonalSceneJumpReq.proto b/proto/PersonalSceneJumpReq.proto new file mode 100644 index 000000000..cc269f258 --- /dev/null +++ b/proto/PersonalSceneJumpReq.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +option java_package = "emu.grasscutter.net.proto"; + +message PersonalSceneJumpReq { + enum CmdId { + option allow_alias = true; + ENET_CHANNEL_ID = 0; + NONE = 0; + ENET_IS_RELIABLE = 1; + IS_ALLOW_CLIENT = 1; + CMD_ID = 260; + } + + uint32 point_id = 1; +} diff --git a/proto/PersonalSceneJumpRsp.proto b/proto/PersonalSceneJumpRsp.proto new file mode 100644 index 000000000..a91f6b5ca --- /dev/null +++ b/proto/PersonalSceneJumpRsp.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +option java_package = "emu.grasscutter.net.proto"; + +import "Vector.proto"; + +message PersonalSceneJumpRsp { + enum CmdId { + option allow_alias = true; + NONE = 0; + ENET_CHANNEL_ID = 0; + ENET_IS_RELIABLE = 1; + CMD_ID = 228; + } + + int32 retcode = 1; + uint32 dest_scene_id = 2; + Vector dest_pos = 3; +} diff --git a/src/main/java/emu/grasscutter/data/common/PointData.java b/src/main/java/emu/grasscutter/data/common/PointData.java index fa3891d7c..492f1fc60 100644 --- a/src/main/java/emu/grasscutter/data/common/PointData.java +++ b/src/main/java/emu/grasscutter/data/common/PointData.java @@ -13,7 +13,8 @@ public class PointData { private Position tranPos; private int[] dungeonIds; private int[] dungeonRandomList; - + + private int tranSceneId; public int getId() { return id; } @@ -38,6 +39,14 @@ public class PointData { return dungeonRandomList; } + public int getTranSceneId() { + return tranSceneId; + } + + public void setTranSceneId(int tranSceneId) { + this.tranSceneId = tranSceneId; + } + public void updateDailyDungeon() { if (getDungeonRandomList() == null) { return; diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java new file mode 100644 index 000000000..98c6984ee --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java @@ -0,0 +1,38 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.custom.ScenePointEntry; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PersonalSceneJumpReqOuterClass.PersonalSceneJumpReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPersonalSceneJumpRsp; +import emu.grasscutter.utils.Position; + + +@Opcodes(PacketOpcodes.PersonalSceneJumpReq) +public class HandlerPersonalSceneJumpReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PersonalSceneJumpReq req = PersonalSceneJumpReq.parseFrom(payload); + + // get the scene point + String code = session.getPlayer().getSceneId() + "_" + req.getPointId(); + ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(code); + + if (scenePointEntry != null) { + float x = scenePointEntry.getPointData().getTranPos().getX(); + float y = scenePointEntry.getPointData().getTranPos().getY(); + float z = scenePointEntry.getPointData().getTranPos().getZ(); + Position pos = new Position(x, y, z); + int sceneId = scenePointEntry.getPointData().getTranSceneId(); + + session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), sceneId, pos); + session.send(new PacketPersonalSceneJumpRsp(sceneId, pos)); + } + + } + +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java new file mode 100644 index 000000000..59065b5f8 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java @@ -0,0 +1,20 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PersonalSceneJumpRspOuterClass.PersonalSceneJumpRsp; +import emu.grasscutter.utils.Position; + +public class PacketPersonalSceneJumpRsp extends BasePacket { + + public PacketPersonalSceneJumpRsp(int sceneId, Position pos) { + super(PacketOpcodes.PersonalSceneJumpRsp); + + PersonalSceneJumpRsp proto = PersonalSceneJumpRsp.newBuilder() + .setDestSceneId(sceneId) + .setDestPos(pos.toProto()) + .build(); + + this.setData(proto); + } +}