This commit is contained in:
flswld committed 2023-10-18 23:30:16 +08:00
1 parent e08e9579bd
commit ab16df5cb6
5 files changed
+92 -5

No files matched your search

+1 -1
View File
@@ -524,7 +524,7 @@ func (w *World) InitPlayerWorldAvatar(player *model.Player) {
scene.DestroyEntity(worldAvatar.avatarEntityId)
scene.DestroyEntity(worldAvatar.weaponEntityId)
worldAvatar.avatarEntityId = scene.CreateEntityAvatar(player, worldAvatar.avatarId)
worldAvatar.weaponEntityId = scene.CreateEntityWeapon()
worldAvatar.weaponEntityId = scene.CreateEntityWeapon(player.Pos, player.Rot)
}
}
+3 -3
View File
@@ -115,14 +115,14 @@ func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32
return entity.id
}
func (s *Scene) CreateEntityWeapon() uint32 {
func (s *Scene) CreateEntityWeapon(pos, rot *model.Vector) uint32 {
entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_WEAPON)
entity := &Entity{
id: entityId,
scene: s,
lifeState: constant.LIFE_STATE_ALIVE,
pos: new(model.Vector),
rot: new(model.Vector),
pos: &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z},
rot: &model.Vector{X: rot.X, Y: rot.Y, Z: rot.Z},
moveState: uint16(proto.MotionState_MOTION_NONE),
lastMoveSceneTimeMs: 0,
lastMoveReliableSeq: 0,
+37
View File
@@ -2,6 +2,7 @@ package game
import (
"fmt"
"math"
"strings"
"time"
@@ -38,6 +39,25 @@ func DoForward[IET model.InvokeEntryType](player *model.Player, invokeHandler *m
if invokeHandler.AllLen() == 0 && invokeHandler.AllExceptCurLen() == 0 && invokeHandler.HostLen() == 0 {
return
}
// TODO aoi漏移除玩家的bug解决了就删掉
aiWorldAoi := world.GetAiWorldAoi()
gid := aiWorldAoi.GetGidByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
if gid == math.MaxUint32 {
return
}
gridList := aiWorldAoi.GetSurrGridListByGid(gid)
for _, grid := range gridList {
objectList := grid.GetObjectList()
for uid, wa := range objectList {
playerMap := world.GetAllPlayer()
_, exist := playerMap[uint32(uid)]
if !exist {
logger.Error("remove not in world player cause by aoi bug, niw uid: %v, niw wa: %+v, uid: %v", uid, wa, player.PlayerId)
delete(objectList, uid)
}
}
}
// TODO aoi漏移除玩家的bug解决了就删掉
if WORLD_MANAGER.IsAiWorld(world) && cmdId != cmd.CombatInvocationsNotify {
if invokeHandler.AllLen() > 0 {
reflection.SetStructFieldValue(newNtf, forwardField, invokeHandler.EntryListForwardAll)
@@ -239,6 +259,14 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
}
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
// 玩家实体在移动
avatarEntity := entity.GetAvatarEntity()
if avatarEntity.GetUid() != player.PlayerId {
logger.Error("can not move other player avatar entity, entityId: %v, uid: %v", entity.GetId(), player.PlayerId)
return
}
aoiDebug := player.GetAoiDebug()
aoiDebug.AddHistoryPos(pos)
aoiDebug.CheckPlayerPosPtr(player)
if !WORLD_MANAGER.IsAiWorld(world) {
g.SceneBlockAoiPlayerMove(player, world, scene, player.Pos, pos, entity.GetId())
} else {
@@ -397,6 +425,15 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S
// 玩家跨越了格子
logger.Debug("player cross ai world aoi grid, oldGid: %v, oldPos: %+v, newGid: %v, newPos: %+v, uid: %v",
oldGid, oldPos, newGid, newPos, player.PlayerId)
aoiDebug := player.GetAoiDebug()
if aoiDebug.LastGid == 0 {
aoiDebug.LastGid = oldGid
}
if aoiDebug.LastGid != oldGid {
logger.Error("aoi bug move skip grid, last gid: %v, old gid: %v, uid: %v", aoiDebug.LastGid, oldGid, player.PlayerId)
aoiDebug.PrintHistoryPosList()
}
aoiDebug.LastGid = newGid
// 找出本次移动所带来的消失和出现的格子
oldGridList := aiWorldAoi.GetSurrGridListByGid(oldGid)
newGridList := aiWorldAoi.GetSurrGridListByGid(newGid)
+50
View File
@@ -1,6 +1,9 @@
package model
import (
"encoding/json"
"time"
"hk4e/pkg/logger"
"hk4e/protocol/proto"
@@ -85,6 +88,7 @@ type Player struct {
CommandAssignUid uint32 `bson:"-" msgpack:"-"` // 命令指定uid
WeatherInfo *WeatherInfo `bson:"-" msgpack:"-"` // 天气信息
ClientVersion int `bson:"-" msgpack:"-"` // 玩家在线的客户端版本
AoiDebug *AoiDebug `bson:"-" msgpack:"-"` // aoi debug
// 特殊数据
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
}
@@ -182,3 +186,49 @@ func (i *InvokeHandler[T]) Clear() {
i.EntryListForwardHost = make([]*T, 0)
i.EntryListForwardServer = make([]*T, 0)
}
type HistoryPos struct {
Time string
Pos *Vector
}
type AoiDebug struct {
Uid uint32
HistoryPosList []*HistoryPos
LastGid uint32
PlayerPosPtr *Vector
}
func (p *Player) GetAoiDebug() *AoiDebug {
if p.AoiDebug == nil {
p.AoiDebug = &AoiDebug{
Uid: p.PlayerId,
HistoryPosList: make([]*HistoryPos, 0),
LastGid: 0,
PlayerPosPtr: p.Pos,
}
}
return p.AoiDebug
}
func (a *AoiDebug) AddHistoryPos(pos *Vector) {
a.HistoryPosList = append(a.HistoryPosList, &HistoryPos{
Time: time.Now().Format("2006-01-02 15:04:05.000"),
Pos: &Vector{X: pos.X, Y: pos.Y, Z: pos.Z},
})
if len(a.HistoryPosList) > 100 {
a.HistoryPosList = a.HistoryPosList[1:]
}
}
func (a *AoiDebug) PrintHistoryPosList() {
data, _ := json.Marshal(a.HistoryPosList)
logger.Debug("HistoryPosList: %v, uid: %v", string(data), a.Uid)
}
func (a *AoiDebug) CheckPlayerPosPtr(player *Player) {
if a.PlayerPosPtr != player.Pos {
logger.Error("player pos ptr change, oldPtr: %p, nowPtr: %v, oldPos: %+v, nowPos: %+v, uid: %v",
a.PlayerPosPtr, player.Pos, a.PlayerPosPtr, player.Pos, player.PlayerId)
}
}
+1 -1
View File
@@ -131,7 +131,7 @@ func (l *Logger) writeLogFile(logStr string) {
logStr = strings.ReplaceAll(logStr, v, "")
}
if l.File == nil {
file, err := os.OpenFile("./"+l.AppName+".log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
file, err := os.OpenFile("./log/"+l.AppName+".log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
fmt.Printf(RED+"open new log file error: %v\n"+RESET, err)
return