2023-06-22 06:53:38 +00:00
|
|
|
package shard
|
2023-06-25 06:51:21 +00:00
|
|
|
|
|
|
|
import (
|
2023-11-28 03:23:28 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-12-01 23:11:41 +00:00
|
|
|
"github.com/CPunch/gopenfusion/cnet"
|
2023-12-02 01:56:23 +00:00
|
|
|
"github.com/CPunch/gopenfusion/cnet/protocol"
|
2023-12-01 22:56:55 +00:00
|
|
|
"github.com/CPunch/gopenfusion/shard/entity"
|
2023-12-01 21:29:19 +00:00
|
|
|
"github.com/CPunch/gopenfusion/util"
|
2023-06-25 06:51:21 +00:00
|
|
|
)
|
|
|
|
|
2023-06-27 05:36:02 +00:00
|
|
|
func (server *ShardServer) updatePlayerPosition(plr *entity.Player, X, Y, Z, Angle int) {
|
2023-06-25 06:51:21 +00:00
|
|
|
plr.X = X
|
|
|
|
plr.Y = Y
|
|
|
|
plr.Z = Z
|
|
|
|
plr.Angle = Angle
|
2023-11-21 07:36:23 +00:00
|
|
|
server.updateEntityChunk(plr, plr.GetChunkPos(), entity.MakeChunkPosition(X, Y))
|
2023-06-25 06:51:21 +00:00
|
|
|
}
|
|
|
|
|
2023-12-02 01:15:00 +00:00
|
|
|
func (server *ShardServer) playerMove(peer *cnet.Peer, pkt protocol.Packet) error {
|
2023-06-25 06:51:21 +00:00
|
|
|
var move protocol.SP_CL2FE_REQ_PC_MOVE
|
|
|
|
pkt.Decode(&move)
|
|
|
|
|
2023-12-01 06:56:34 +00:00
|
|
|
plr, ok := peer.UserData().(*entity.Player)
|
|
|
|
if !ok || plr == nil {
|
|
|
|
return fmt.Errorf("playerMove: plr is nil")
|
2023-06-25 09:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update chunking
|
2023-06-27 05:36:02 +00:00
|
|
|
server.updatePlayerPosition(plr, int(move.IX), int(move.IY), int(move.IZ), int(move.IAngle))
|
2023-06-25 09:27:42 +00:00
|
|
|
|
|
|
|
return server.sendOthersPacket(plr, protocol.P_FE2CL_PC_MOVE, protocol.SP_FE2CL_PC_MOVE{
|
2023-06-25 23:29:31 +00:00
|
|
|
ICliTime: move.ICliTime,
|
2023-06-25 09:27:42 +00:00
|
|
|
IX: move.IX,
|
|
|
|
IY: move.IY,
|
|
|
|
IZ: move.IZ,
|
|
|
|
FVX: move.FVX,
|
|
|
|
FVY: move.FVY,
|
|
|
|
FVZ: move.FVZ,
|
|
|
|
IAngle: move.IAngle,
|
|
|
|
CKeyValue: move.CKeyValue,
|
|
|
|
ISpeed: move.ISpeed,
|
|
|
|
IID: int32(plr.PlayerID),
|
2023-12-01 21:29:19 +00:00
|
|
|
ISvrTime: util.GetTime(),
|
2023-06-25 09:27:42 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-02 01:15:00 +00:00
|
|
|
func (server *ShardServer) playerStop(peer *cnet.Peer, pkt protocol.Packet) error {
|
2023-06-25 09:27:42 +00:00
|
|
|
var stop protocol.SP_CL2FE_REQ_PC_STOP
|
|
|
|
pkt.Decode(&stop)
|
|
|
|
|
2023-12-01 06:56:34 +00:00
|
|
|
plr, ok := peer.UserData().(*entity.Player)
|
|
|
|
if !ok || plr == nil {
|
|
|
|
return fmt.Errorf("playerStop: plr is nil")
|
2023-06-25 09:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update chunking
|
2023-06-27 05:36:02 +00:00
|
|
|
server.updatePlayerPosition(plr, int(stop.IX), int(stop.IY), int(stop.IZ), plr.Angle)
|
2023-06-25 09:27:42 +00:00
|
|
|
|
|
|
|
return server.sendOthersPacket(plr, protocol.P_FE2CL_PC_STOP, protocol.SP_FE2CL_PC_STOP{
|
2023-06-25 23:29:31 +00:00
|
|
|
ICliTime: stop.ICliTime,
|
2023-06-25 09:27:42 +00:00
|
|
|
IX: stop.IX,
|
|
|
|
IY: stop.IY,
|
|
|
|
IZ: stop.IZ,
|
|
|
|
IID: int32(plr.PlayerID),
|
2023-12-01 21:29:19 +00:00
|
|
|
ISvrTime: util.GetTime(),
|
2023-06-25 09:27:42 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-02 01:15:00 +00:00
|
|
|
func (server *ShardServer) playerJump(peer *cnet.Peer, pkt protocol.Packet) error {
|
2023-06-25 09:27:42 +00:00
|
|
|
var jump protocol.SP_CL2FE_REQ_PC_JUMP
|
|
|
|
pkt.Decode(&jump)
|
|
|
|
|
2023-12-01 06:56:34 +00:00
|
|
|
plr, ok := peer.UserData().(*entity.Player)
|
|
|
|
if !ok || plr == nil {
|
2023-11-28 03:23:28 +00:00
|
|
|
return fmt.Errorf("playerJump: _plr is nil")
|
2023-06-25 09:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update chunking
|
2023-06-27 05:36:02 +00:00
|
|
|
server.updatePlayerPosition(plr, int(jump.IX), int(jump.IY), int(jump.IZ), plr.Angle)
|
2023-06-25 09:27:42 +00:00
|
|
|
|
|
|
|
return server.sendOthersPacket(plr, protocol.P_FE2CL_PC_JUMP, protocol.SP_FE2CL_PC_JUMP{
|
2023-06-25 23:29:31 +00:00
|
|
|
ICliTime: jump.ICliTime,
|
2023-06-25 09:27:42 +00:00
|
|
|
IX: jump.IX,
|
|
|
|
IY: jump.IY,
|
|
|
|
IZ: jump.IZ,
|
|
|
|
IVX: jump.IVX,
|
|
|
|
IVY: jump.IVY,
|
|
|
|
IVZ: jump.IVZ,
|
|
|
|
IAngle: jump.IAngle,
|
|
|
|
CKeyValue: jump.CKeyValue,
|
|
|
|
ISpeed: jump.ISpeed,
|
|
|
|
IID: int32(plr.PlayerID),
|
2023-12-01 21:29:19 +00:00
|
|
|
ISvrTime: util.GetTime(),
|
2023-06-25 09:27:42 +00:00
|
|
|
})
|
2023-06-25 06:51:21 +00:00
|
|
|
}
|