gopenfusion/shard/movement.go

32 lines
746 B
Go
Raw Normal View History

package shard
2023-06-25 06:51:21 +00:00
import (
2023-06-25 08:33:17 +00:00
"github.com/CPunch/gopenfusion/core/entity"
2023-06-25 06:51:21 +00:00
"github.com/CPunch/gopenfusion/core/protocol"
)
func (server *ShardServer) updatePlayerPosition(peer *protocol.CNPeer, X, Y, Z, Angle int) error {
plr, err := server.getPlayer(peer)
if err != nil {
return err
}
2023-06-25 08:33:17 +00:00
newPos := entity.MakeChunkPosition(X, Y)
oldPos := plr.Chunk
2023-06-25 06:51:21 +00:00
plr.X = X
plr.Y = Y
plr.Z = Z
plr.Angle = Angle
2023-06-25 08:33:17 +00:00
if newPos != oldPos {
server.updateEntityChunk(plr, oldPos, newPos)
}
2023-06-25 06:51:21 +00:00
return nil
}
func (server *ShardServer) playerMove(peer *protocol.CNPeer, pkt protocol.Packet) error {
var move protocol.SP_CL2FE_REQ_PC_MOVE
pkt.Decode(&move)
return server.updatePlayerPosition(peer, int(move.IX), int(move.IY), int(move.IZ), int(move.IAngle))
}