Some teleport handlers (#13)

* feat: handle teleport using point

* Missing response teleport

* feat: handle personal scene teleport

* chore: remove some debug log
This commit is contained in:
Dang Hoang Phuc 2022-12-05 20:02:56 +07:00 committed by GitHub
parent caf49ffe3c
commit 03d543f61d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 154 additions and 0 deletions

View File

@ -0,0 +1,48 @@
using Weedwacker.GameServer.Data.BinOut.Scene.Point;
using Weedwacker.GameServer.Data;
using Weedwacker.GameServer.Enums;
using Weedwacker.Shared.Network.Proto;
using Weedwacker.Shared.Utils;
using Vim.Math3d;
using Weedwacker.GameServer.Packet.Send;
namespace Weedwacker.GameServer.Packet.Recv
{
[OpCode((ushort)OpCode.PersonalSceneJumpReq)]
internal class HandlePersonalSceneJumpReq : BaseHandler
{
public override async Task HandleAsync(Connection session, byte[] header, byte[] payload)
{
PersonalSceneJumpReq req = PersonalSceneJumpReq.Parser.ParseFrom(payload);
ScenePointData spd;
BasePoint bp;
GameData.ScenePointDataMap.TryGetValue("scene" + session.Player.SceneId + "_point", out spd);
spd.points.TryGetValue(req.PointId.ToString(), out bp);
if (bp == null)
{
Logger.WriteErrorLine("Scene " + session.Player.SceneId + " | Point " + req.PointId + " not found!");
return;
}
int transToSceneId = (bp as PersonalSceneJumpPoint).tranSceneId;
float x, y, z;
// TODO: SerializedName because there are some variants like: x, _x, X,...
bp.tranPos.TryGetValue("x", out x);
bp.tranPos.TryGetValue("y", out y);
bp.tranPos.TryGetValue("z", out z);
Vector3 transPos = new(x, y, z);
await session.Player.World.TransferPlayerToSceneAsync(session.Player, EnterReason.PersonalScene, EnterType.Jump, transToSceneId, transPos, false);
await session.SendPacketAsync(new PacketPersonalSceneJumpRsp((uint)transToSceneId, transPos));
}
}
}

View File

@ -0,0 +1,53 @@
using Vim.Math3d;
using Weedwacker.GameServer.Data;
using Weedwacker.GameServer.Data.BinOut.Scene.Point;
using Weedwacker.GameServer.Enums;
using Weedwacker.GameServer.Packet.Send;
using Weedwacker.Shared.Network.Proto;
using Weedwacker.Shared.Utils;
namespace Weedwacker.GameServer.Packet.Recv
{
[OpCode((ushort)OpCode.SceneTransToPointReq)]
internal class HandleSceneTransToPointReq : BaseHandler
{
public override async Task HandleAsync(Connection session, byte[] header, byte[] payload)
{
SceneTransToPointReq req = SceneTransToPointReq.Parser.ParseFrom(payload);
ScenePointData spd;
GameData.ScenePointDataMap.TryGetValue("scene" + req.SceneId + "_point", out spd);
if (spd == null)
{
Logger.WriteErrorLine("Scene " + req.SceneId + " not found!");
return;
}
BasePoint bp;
spd.points.TryGetValue(req.PointId.ToString(), out bp);
if (bp == null)
{
Logger.WriteErrorLine("Scene " + req.SceneId + " | Point " + req.PointId + " not found!");
return;
}
float x, y, z;
// TODO: SerializedName because there are some variants like: x, _x, X,...
bp.tranPos.TryGetValue("x", out x);
bp.tranPos.TryGetValue("y", out y);
bp.tranPos.TryGetValue("z", out z);
Vector3 transPos = new Vector3(x, y, z);
await session.Player.World.TransferPlayerToSceneAsync(session.Player, EnterReason.TransPoint, req.SceneId == (uint)session.Player.SceneId ? EnterType.Goto : EnterType.Jump, (int)req.SceneId, transPos, false);
await session.SendPacketAsync(new PacketSceneTransToPointRsp());
}
}
}

View File

@ -0,0 +1,38 @@
using Google.Protobuf;
using Vim.Math3d;
using Weedwacker.Shared.Network.Proto;
namespace Weedwacker.GameServer.Packet.Send
{
internal class PacketPersonalSceneJumpRsp : BasePacket
{
public PacketPersonalSceneJumpRsp(uint sceneId, Vector pos) : base(Enums.OpCode.PersonalSceneJumpRsp)
{
PersonalSceneJumpRsp proto = new PersonalSceneJumpRsp()
{
DestPos = pos,
DestSceneId = sceneId
};
Data = proto.ToByteArray();
}
public PacketPersonalSceneJumpRsp(uint sceneId, Vector3 pos) : base(Enums.OpCode.PersonalSceneJumpRsp)
{
Vector protoVector = new Vector()
{
X = pos.X,
Y = pos.Y,
Z = pos.Z
};
PersonalSceneJumpRsp proto = new PersonalSceneJumpRsp()
{
DestPos = protoVector,
DestSceneId = sceneId
};
Data = proto.ToByteArray();
}
}
}

View File

@ -0,0 +1,15 @@
using Google.Protobuf;
using Weedwacker.Shared.Network.Proto;
namespace Weedwacker.GameServer.Packet.Send
{
internal class PacketSceneTransToPointRsp : BasePacket
{
public PacketSceneTransToPointRsp() : base(Enums.OpCode.SceneTransToPointRsp)
{
SceneTransToPointRsp proto = new SceneTransToPointRsp();
Data = proto.ToByteArray();
}
}
}