mirror of
https://github.com/Anime-Game-Servers/Weedwacker.git
synced 2024-10-07 01:44:46 +00:00
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:
parent
caf49ffe3c
commit
03d543f61d
48
src/GameServer/Packet/Recv/HandlePersonalSceneJumpReq.cs
Normal file
48
src/GameServer/Packet/Recv/HandlePersonalSceneJumpReq.cs
Normal 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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
53
src/GameServer/Packet/Recv/HandleSceneTransToPointReq.cs
Normal file
53
src/GameServer/Packet/Recv/HandleSceneTransToPointReq.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
38
src/GameServer/Packet/Send/PacketPersonalSceneJumpRsp.cs
Normal file
38
src/GameServer/Packet/Send/PacketPersonalSceneJumpRsp.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
15
src/GameServer/Packet/Send/PacketSceneTransToPointRsp.cs
Normal file
15
src/GameServer/Packet/Send/PacketSceneTransToPointRsp.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user