big world mmorpg mode

This commit is contained in:
flswld
2023-04-10 02:20:57 +08:00
parent e554b99e7e
commit 5a043a9482
11 changed files with 184 additions and 84 deletions

View File

@@ -311,7 +311,7 @@ func UpdateFrame(rgb bool) {
for _, v := range SCREEN_ENTITY_ID_LIST { for _, v := range SCREEN_ENTITY_ID_LIST {
scene.DestroyEntity(v) scene.DestroyEntity(v)
} }
GAME.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_REMOVE, SCREEN_ENTITY_ID_LIST) GAME.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_REMOVE, SCREEN_ENTITY_ID_LIST, false, nil)
SCREEN_ENTITY_ID_LIST = make([]uint32, 0) SCREEN_ENTITY_ID_LIST = make([]uint32, 0)
leftTopPos := &model.Vector{ leftTopPos := &model.Vector{
X: BASE_POS.X + float64(SCREEN_WIDTH)*SCREEN_DPI/2, X: BASE_POS.X + float64(SCREEN_WIDTH)*SCREEN_DPI/2,

View File

@@ -90,10 +90,7 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
USER_MANAGER.SetRemoteUserOnlineState(BigWorldAiUid, true, mainGsAppid) USER_MANAGER.SetRemoteUserOnlineState(BigWorldAiUid, true, mainGsAppid)
if r.IsMainGs() { if r.IsMainGs() {
// TODO 测试 // TODO 测试
r.ai.Pos.X -= random.GetRandomFloat64(25.0, 35.0) for i := 1; i < 100; i++ {
r.ai.Pos.Y += 1.0
r.ai.Pos.Z += random.GetRandomFloat64(25.0, 35.0)
for i := 1; i < 3; i++ {
uid := 1000000 + uint32(i) uid := 1000000 + uint32(i)
avatarId := uint32(0) avatarId := uint32(0)
for _, avatarData := range gdconf.GetAvatarDataMap() { for _, avatarData := range gdconf.GetAvatarDataMap() {
@@ -108,9 +105,12 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
AvatarTeamGuidList: []uint64{dbAvatar.AvatarMap[avatarId].Guid}, AvatarTeamGuidList: []uint64{dbAvatar.AvatarMap[avatarId].Guid},
CurAvatarGuid: dbAvatar.AvatarMap[avatarId].Guid, CurAvatarGuid: dbAvatar.AvatarMap[avatarId].Guid,
}) })
robot.Pos.X -= random.GetRandomFloat64(25.0, 35.0) pos := &model.Vector{
robot.Pos.Y += 1.0 X: 1800.0 + random.GetRandomFloat64(-100.0, 100.0),
robot.Pos.Z += random.GetRandomFloat64(25.0, 35.0) Y: 195.0 + random.GetRandomFloat64(0.0, 5.0),
Z: -1500.0 + random.GetRandomFloat64(-100.0, 100.0),
}
robot.Pos = pos
r.UserWorldAddPlayer(WORLD_MANAGER.GetAiWorld(), robot) r.UserWorldAddPlayer(WORLD_MANAGER.GetAiWorld(), robot)
} }
} }

View File

@@ -4,6 +4,7 @@ import (
"time" "time"
"hk4e/gdconf" "hk4e/gdconf"
"hk4e/gs/model"
"hk4e/pkg/logger" "hk4e/pkg/logger"
"hk4e/pkg/random" "hk4e/pkg/random"
"hk4e/protocol/cmd" "hk4e/protocol/cmd"
@@ -190,6 +191,7 @@ func (t *TickManager) onTickMinute(now int64) {
gdconf.LuaStateLruRemove() gdconf.LuaStateLruRemove()
for _, world := range WORLD_MANAGER.GetAllWorld() { for _, world := range WORLD_MANAGER.GetAllWorld() {
for _, player := range world.GetAllPlayer() { for _, player := range world.GetAllPlayer() {
if player.SceneLoadState == model.SceneEnterDone {
// 随机物品 // 随机物品
allItemDataConfig := GAME.GetAllItemDataConfig() allItemDataConfig := GAME.GetAllItemDataConfig()
count := random.GetRandomInt32(0, 4) count := random.GetRandomInt32(0, 4)
@@ -212,13 +214,16 @@ func (t *TickManager) onTickMinute(now int64) {
} }
} }
} }
}
func (t *TickManager) onTick10Second(now int64) { func (t *TickManager) onTick10Second(now int64) {
for _, world := range WORLD_MANAGER.GetAllWorld() { for _, world := range WORLD_MANAGER.GetAllWorld() {
if world.GetOwner().SceneLoadState == model.SceneEnterDone {
GAME.SceneTimeNotify(world) GAME.SceneTimeNotify(world)
GAME.PlayerTimeNotify(world) GAME.PlayerTimeNotify(world)
} }
} }
}
func (t *TickManager) onTick5Second(now int64) { func (t *TickManager) onTick5Second(now int64) {
for _, world := range WORLD_MANAGER.GetAllWorld() { for _, world := range WORLD_MANAGER.GetAllWorld() {
@@ -227,17 +232,21 @@ func (t *TickManager) onTick5Second(now int64) {
GAME.UserDealEnterWorld(world.owner, applyUid, true) GAME.UserDealEnterWorld(world.owner, applyUid, true)
} }
} }
if world.GetOwner().SceneLoadState == model.SceneEnterDone {
// 多人世界其他玩家的坐标位置广播 // 多人世界其他玩家的坐标位置广播
GAME.WorldPlayerLocationNotify(world) GAME.WorldPlayerLocationNotify(world)
GAME.ScenePlayerLocationNotify(world) GAME.ScenePlayerLocationNotify(world)
} }
} }
}
func (t *TickManager) onTickSecond(now int64) { func (t *TickManager) onTickSecond(now int64) {
for _, world := range WORLD_MANAGER.GetAllWorld() { for _, world := range WORLD_MANAGER.GetAllWorld() {
if world.GetOwner().SceneLoadState == model.SceneEnterDone {
// 世界里所有玩家的网络延迟广播 // 世界里所有玩家的网络延迟广播
GAME.WorldPlayerRTTNotify(world) GAME.WorldPlayerRTTNotify(world)
} }
}
// // GCG游戏Tick // // GCG游戏Tick
// for _, game := range GCG_MANAGER.gameMap { // for _, game := range GCG_MANAGER.gameMap {
// game.onTick() // game.onTick()
@@ -247,6 +256,7 @@ func (t *TickManager) onTickSecond(now int64) {
func (t *TickManager) onTick200MilliSecond(now int64) { func (t *TickManager) onTick200MilliSecond(now int64) {
for _, world := range WORLD_MANAGER.GetAllWorld() { for _, world := range WORLD_MANAGER.GetAllWorld() {
for _, player := range world.GetAllPlayer() { for _, player := range world.GetAllPlayer() {
if player.SceneLoadState == model.SceneEnterDone {
// 耐力消耗 // 耐力消耗
GAME.SustainStaminaHandler(player) GAME.SustainStaminaHandler(player)
GAME.VehicleRestoreStaminaHandler(player) GAME.VehicleRestoreStaminaHandler(player)
@@ -254,6 +264,7 @@ func (t *TickManager) onTick200MilliSecond(now int64) {
} }
} }
} }
}
func (t *TickManager) onTick100MilliSecond(now int64) { func (t *TickManager) onTick100MilliSecond(now int64) {
} }

View File

@@ -64,9 +64,16 @@ func (w *WorldManager) CreateWorld(owner *model.Player) *World {
waitEnterPlayerMap: make(map[uint32]int64), waitEnterPlayerMap: make(map[uint32]int64),
multiplayerTeam: CreateMultiplayerTeam(), multiplayerTeam: CreateMultiplayerTeam(),
peerList: make([]*model.Player, 0), peerList: make([]*model.Player, 0),
bigWorldAoi: nil,
} }
world.mpLevelEntityId = world.GetNextWorldEntityId(constant.ENTITY_TYPE_MP_LEVEL) world.mpLevelEntityId = world.GetNextWorldEntityId(constant.ENTITY_TYPE_MP_LEVEL)
w.worldMap[worldId] = world w.worldMap[worldId] = world
if w.IsBigWorld(world) {
aoiManager := alg.NewAoiManager()
aoiManager.SetAoiRange(-8000, 4000, -200, 1000, -5500, 6500)
aoiManager.Init3DRectAoiManager(1200, 12, 1200)
world.bigWorldAoi = aoiManager
}
return world return world
} }
@@ -94,15 +101,11 @@ func (w *WorldManager) InitAiWorld(owner *model.Player) {
} }
func (w *WorldManager) IsAiWorld(world *World) bool { func (w *WorldManager) IsAiWorld(world *World) bool {
return world.id == w.aiWorld.id
}
func (w *WorldManager) IsRobotWorld(world *World) bool {
return world.owner.PlayerID < PlayerBaseUid return world.owner.PlayerID < PlayerBaseUid
} }
func (w *WorldManager) IsBigWorld(world *World) bool { func (w *WorldManager) IsBigWorld(world *World) bool {
return (world.id == w.aiWorld.id) && (w.aiWorld.owner.PlayerID == BigWorldAiUid) return world.owner.PlayerID == BigWorldAiUid
} }
func (w *WorldManager) GetSceneBlockAoiMap() map[uint32]*alg.AoiManager { func (w *WorldManager) GetSceneBlockAoiMap() map[uint32]*alg.AoiManager {
@@ -216,6 +219,7 @@ type World struct {
waitEnterPlayerMap map[uint32]int64 // 进入世界的玩家等待列表 key:uid value:开始时间 waitEnterPlayerMap map[uint32]int64 // 进入世界的玩家等待列表 key:uid value:开始时间
multiplayerTeam *MultiplayerTeam // 多人队伍 multiplayerTeam *MultiplayerTeam // 多人队伍
peerList []*model.Player // 玩家编号列表 peerList []*model.Player // 玩家编号列表
bigWorldAoi *alg.AoiManager // 大世界的aoi管理器
} }
func (w *World) GetId() uint32 { func (w *World) GetId() uint32 {
@@ -335,11 +339,7 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
activeAvatarId := dbTeam.GetActiveAvatarId() activeAvatarId := dbTeam.GetActiveAvatarId()
w.SetPlayerLocalTeam(player, []uint32{activeAvatarId}) w.SetPlayerLocalTeam(player, []uint32{activeAvatarId})
} }
playerNum := w.GetWorldPlayerNum() if WORLD_MANAGER.IsBigWorld(w) {
if playerNum > 4 {
if !WORLD_MANAGER.IsBigWorld(w) {
return
}
w.AddMultiplayerTeam(player) w.AddMultiplayerTeam(player)
} else { } else {
w.UpdateMultiplayerTeam() w.UpdateMultiplayerTeam()
@@ -362,6 +362,12 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
} }
scene.AddPlayer(player) scene.AddPlayer(player)
w.InitPlayerTeamEntityId(player) w.InitPlayerTeamEntityId(player)
if WORLD_MANAGER.IsBigWorld(w) {
activeAvatarId := w.GetPlayerActiveAvatarId(player)
worldAvatar := w.GetPlayerWorldAvatar(player, activeAvatarId)
w.bigWorldAoi.AddObjectToGridByPos(int64(player.PlayerID), worldAvatar,
float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
}
} }
func (w *World) RemovePlayer(player *model.Player) { func (w *World) RemovePlayer(player *model.Player) {
@@ -374,12 +380,10 @@ func (w *World) RemovePlayer(player *model.Player) {
delete(w.multiplayerTeam.localTeamMap, player.PlayerID) delete(w.multiplayerTeam.localTeamMap, player.PlayerID)
delete(w.multiplayerTeam.localAvatarIndexMap, player.PlayerID) delete(w.multiplayerTeam.localAvatarIndexMap, player.PlayerID)
delete(w.multiplayerTeam.localTeamEntityMap, player.PlayerID) delete(w.multiplayerTeam.localTeamEntityMap, player.PlayerID)
playerNum := w.GetWorldPlayerNum() if WORLD_MANAGER.IsBigWorld(w) {
if playerNum > 4 {
if !WORLD_MANAGER.IsBigWorld(w) {
return
}
w.RemoveMultiplayerTeam(player) w.RemoveMultiplayerTeam(player)
w.bigWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerID),
float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
} else { } else {
if player.PlayerID != w.owner.PlayerID { if player.PlayerID != w.owner.PlayerID {
w.UpdateMultiplayerTeam() w.UpdateMultiplayerTeam()
@@ -663,9 +667,6 @@ func (w *World) copyLocalTeamToWorld(start int, end int, peerId uint32) {
// 看来还是不能简单的走通用逻辑 需要对大世界场景队伍做特殊处理 欺骗客户端其他玩家仅仅以场景角色实体的形式出现 // 看来还是不能简单的走通用逻辑 需要对大世界场景队伍做特殊处理 欺骗客户端其他玩家仅仅以场景角色实体的形式出现
func (w *World) AddMultiplayerTeam(player *model.Player) { func (w *World) AddMultiplayerTeam(player *model.Player) {
if !WORLD_MANAGER.IsBigWorld(w) {
return
}
localTeam := w.GetPlayerLocalTeam(player) localTeam := w.GetPlayerLocalTeam(player)
w.multiplayerTeam.worldTeam = append(w.multiplayerTeam.worldTeam, localTeam...) w.multiplayerTeam.worldTeam = append(w.multiplayerTeam.worldTeam, localTeam...)
} }

View File

@@ -266,7 +266,7 @@ func (g *Game) AoiPlayerMove(player *model.Player, oldPos *model.Vector, newPos
newGid := aoiManager.GetGidByPos(float32(newPos.X), 0.0, float32(newPos.Z)) newGid := aoiManager.GetGidByPos(float32(newPos.X), 0.0, float32(newPos.Z))
if oldGid != newGid { if oldGid != newGid {
// 跨越了block格子 // 跨越了block格子
logger.Debug("player cross grid, oldGid: %v, newGid: %v, uid: %v", oldGid, newGid, player.PlayerID) logger.Debug("player cross scene block grid, oldGid: %v, newGid: %v, uid: %v", oldGid, newGid, player.PlayerID)
} }
// 加载和卸载的group // 加载和卸载的group
oldNeighborGroupMap := g.GetNeighborGroup(player.SceneId, oldPos) oldNeighborGroupMap := g.GetNeighborGroup(player.SceneId, oldPos)
@@ -294,20 +294,30 @@ func (g *Game) AoiPlayerMove(player *model.Player, oldPos *model.Vector, newPos
oldVisionEntityMap := g.GetVisionEntity(scene, oldPos) oldVisionEntityMap := g.GetVisionEntity(scene, oldPos)
newVisionEntityMap := g.GetVisionEntity(scene, newPos) newVisionEntityMap := g.GetVisionEntity(scene, newPos)
delEntityIdList := make([]uint32, 0) delEntityIdList := make([]uint32, 0)
for entityId := range oldVisionEntityMap { for entityId, entity := range oldVisionEntityMap {
_, exist := newVisionEntityMap[entityId] _, exist := newVisionEntityMap[entityId]
if exist { if exist {
continue continue
} }
if WORLD_MANAGER.IsBigWorld(world) {
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
continue
}
}
// 旧有新没有的实体即为消失的 // 旧有新没有的实体即为消失的
delEntityIdList = append(delEntityIdList, entityId) delEntityIdList = append(delEntityIdList, entityId)
} }
addEntityIdList := make([]uint32, 0) addEntityIdList := make([]uint32, 0)
for entityId := range newVisionEntityMap { for entityId, entity := range newVisionEntityMap {
_, exist := oldVisionEntityMap[entityId] _, exist := oldVisionEntityMap[entityId]
if exist { if exist {
continue continue
} }
if WORLD_MANAGER.IsBigWorld(world) {
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
continue
}
}
// 新有旧没有的实体即为出现的 // 新有旧没有的实体即为出现的
addEntityIdList = append(addEntityIdList, entityId) addEntityIdList = append(addEntityIdList, entityId)
} }
@@ -318,6 +328,60 @@ func (g *Game) AoiPlayerMove(player *model.Player, oldPos *model.Vector, newPos
if len(addEntityIdList) > 0 { if len(addEntityIdList) > 0 {
g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false) g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false)
} }
if WORLD_MANAGER.IsBigWorld(world) {
oldGid := world.bigWorldAoi.GetGidByPos(float32(oldPos.X), float32(oldPos.Y), float32(oldPos.Z))
newGid := world.bigWorldAoi.GetGidByPos(float32(newPos.X), float32(newPos.Y), float32(newPos.Z))
if oldGid != newGid {
// 玩家跨越了格子
logger.Debug("player cross big world aoi grid, oldGid: %v, newGid: %v, uid: %v", oldGid, newGid, player.PlayerID)
// 老格子移除玩家 新格子添加玩家
activeAvatarId := world.GetPlayerActiveAvatarId(player)
activeWorldAvatar := world.GetPlayerWorldAvatar(player, activeAvatarId)
world.bigWorldAoi.RemoveObjectFromGrid(int64(player.PlayerID), oldGid)
world.bigWorldAoi.AddObjectToGrid(int64(player.PlayerID), activeWorldAvatar, newGid)
oldOtherWorldAvatarMap := world.bigWorldAoi.GetObjectListByPos(float32(oldPos.X), float32(oldPos.Y), float32(oldPos.Z))
delEntityIdList := make([]uint32, 0)
for _, otherWorldAvatarAny := range oldOtherWorldAvatarMap {
otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar)
if otherWorldAvatar.GetUid() == player.PlayerID {
continue
}
delEntityIdList = append(delEntityIdList, otherWorldAvatar.GetAvatarEntityId())
}
// 通知自己 老格子里的其它玩家消失
g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_MISS, delEntityIdList)
for otherPlayerId := range oldOtherWorldAvatarMap {
if uint32(otherPlayerId) == player.PlayerID {
continue
}
otherPlayer := USER_MANAGER.GetOnlineUser(uint32(otherPlayerId))
// 通知老格子里的其它玩家 自己消失
g.RemoveSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MISS, []uint32{
activeWorldAvatar.GetAvatarEntityId(),
})
}
newOtherWorldAvatarMap := world.bigWorldAoi.GetObjectListByPos(float32(newPos.X), float32(newPos.Y), float32(newPos.Z))
addEntityIdList := make([]uint32, 0)
for _, otherWorldAvatarAny := range newOtherWorldAvatarMap {
otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar)
if otherWorldAvatar.GetUid() == player.PlayerID {
continue
}
addEntityIdList = append(addEntityIdList, otherWorldAvatar.GetAvatarEntityId())
}
// 通知自己 新格子里的其他玩家出现
g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false)
for otherPlayerId := range newOtherWorldAvatarMap {
if uint32(otherPlayerId) == player.PlayerID {
continue
}
otherPlayer := USER_MANAGER.GetOnlineUser(uint32(otherPlayerId))
sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, player, world.GetPlayerActiveAvatarId(player))
// 通知新格子里的其他玩家 自己出现
g.AddSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MEET, []*proto.SceneEntityInfo{sceneEntityInfoAvatar})
}
}
}
} }
func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Message) { func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Message) {
@@ -535,7 +599,7 @@ func (g *Game) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb.Messag
} }
scene := world.GetSceneById(player.SceneId) scene := world.GetSceneById(player.SceneId)
scene.DestroyEntity(req.EntityId) scene.DestroyEntity(req.EntityId)
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{req.EntityId}) g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{req.EntityId}, false, nil)
} }
func (g *Game) EvtAiSyncSkillCdNotify(player *model.Player, payloadMsg pb.Message) { func (g *Game) EvtAiSyncSkillCdNotify(player *model.Player, payloadMsg pb.Message) {

View File

@@ -149,10 +149,6 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player
} }
g.SendMsg(cmd.PlayerLoginRsp, userId, clientSeq, playerLoginRsp) g.SendMsg(cmd.PlayerLoginRsp, userId, clientSeq, playerLoginRsp)
if userId < PlayerBaseUid {
return
}
MESSAGE_QUEUE.SendToAll(&mq.NetMsg{ MESSAGE_QUEUE.SendToAll(&mq.NetMsg{
MsgType: mq.MsgTypeServer, MsgType: mq.MsgTypeServer,
EventId: mq.ServerUserOnlineStateChangeNotify, EventId: mq.ServerUserOnlineStateChangeNotify,
@@ -161,6 +157,9 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player
IsOnline: true, IsOnline: true,
}, },
}) })
if userId < PlayerBaseUid {
return
}
atomic.AddInt32(&ONLINE_PLAYER_NUM, 1) atomic.AddInt32(&ONLINE_PLAYER_NUM, 1)
SELF = nil SELF = nil

View File

@@ -348,9 +348,12 @@ func (g *Game) HostEnterMpWorld(hostPlayer *model.Player) {
) )
g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify) g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify)
// 仅仅把当前的场上角色的实体消失掉 scene := world.GetSceneById(hostPlayer.SceneId)
activeAvatarId := world.GetPlayerActiveAvatarId(hostPlayer) entityIdList := make([]uint32, 0)
g.RemoveSceneEntityNotifyToPlayer(hostPlayer, proto.VisionType_VISION_MISS, []uint32{world.GetPlayerWorldAvatarEntityId(hostPlayer, activeAvatarId)}) for _, entity := range scene.GetAllEntity() {
entityIdList = append(entityIdList, entity.GetId())
}
g.RemoveSceneEntityNotifyToPlayer(hostPlayer, proto.VisionType_VISION_MISS, entityIdList)
} }
func (g *Game) UserLeaveWorld(player *model.Player) bool { func (g *Game) UserLeaveWorld(player *model.Player) bool {
@@ -412,7 +415,7 @@ func (g *Game) UserWorldRemovePlayer(world *World, player *model.Player) {
g.SendMsg(cmd.PlayerQuitFromMpNotify, player.PlayerID, player.ClientSeq, playerQuitFromMpNotify) g.SendMsg(cmd.PlayerQuitFromMpNotify, player.PlayerID, player.ClientSeq, playerQuitFromMpNotify)
activeAvatarId := world.GetPlayerActiveAvatarId(player) activeAvatarId := world.GetPlayerActiveAvatarId(player)
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}) g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}, false, nil)
} }
world.RemovePlayer(player) world.RemovePlayer(player)
@@ -488,7 +491,7 @@ func (g *Game) UpdateWorldScenePlayerInfo(player *model.Player, world *World) {
} }
g.SendMsg(cmd.ScenePlayerInfoNotify, player.PlayerID, player.ClientSeq, scenePlayerInfoNotify) g.SendMsg(cmd.ScenePlayerInfoNotify, player.PlayerID, player.ClientSeq, scenePlayerInfoNotify)
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world) sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerID, player.ClientSeq, sceneTeamUpdateNotify) g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerID, player.ClientSeq, sceneTeamUpdateNotify)
syncTeamEntityNotify := &proto.SyncTeamEntityNotify{ syncTeamEntityNotify := &proto.SyncTeamEntityNotify{

View File

@@ -244,23 +244,39 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
} }
activeAvatarId := world.GetPlayerActiveAvatarId(player) activeAvatarId := world.GetPlayerActiveAvatarId(player)
activeAvatarEntityId := world.GetPlayerWorldAvatarEntityId(player, activeAvatarId) activeWorldAvatar := world.GetPlayerWorldAvatar(player, activeAvatarId)
g.AddSceneEntityNotify(player, visionType, []uint32{activeAvatarEntityId}, true, false) g.AddSceneEntityNotify(player, visionType, []uint32{
activeWorldAvatar.GetAvatarEntityId(),
}, true, false)
// 加载附近的group // 加载附近的group
for _, groupConfig := range g.GetNeighborGroup(scene.GetId(), player.Pos) { for _, groupConfig := range g.GetNeighborGroup(scene.GetId(), player.Pos) {
g.AddSceneGroup(player, scene, groupConfig) g.AddSceneGroup(player, scene, groupConfig)
} }
// 同步客户端视野内的场景实体 // 同步客户端视野内的场景实体
entityIdList := make([]uint32, 0)
visionEntityMap := g.GetVisionEntity(scene, player.Pos) visionEntityMap := g.GetVisionEntity(scene, player.Pos)
for _, entity := range visionEntityMap { entityIdList := make([]uint32, 0)
if entity.GetId() == activeAvatarEntityId { for entityId, entity := range visionEntityMap {
if entityId == activeWorldAvatar.GetAvatarEntityId() {
continue continue
} }
entityIdList = append(entityIdList, entity.GetId()) if WORLD_MANAGER.IsBigWorld(world) {
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
continue
}
}
entityIdList = append(entityIdList, entityId)
} }
g.AddSceneEntityNotify(player, visionType, entityIdList, false, false) g.AddSceneEntityNotify(player, visionType, entityIdList, false, false)
if WORLD_MANAGER.IsBigWorld(world) {
otherWorldAvatarMap := world.bigWorldAoi.GetObjectListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
entityIdList := make([]uint32, 0)
for _, otherWorldAvatarAny := range otherWorldAvatarMap {
otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar)
entityIdList = append(entityIdList, otherWorldAvatar.GetAvatarEntityId())
}
g.AddSceneEntityNotify(player, visionType, entityIdList, false, false)
}
sceneAreaWeatherNotify := &proto.SceneAreaWeatherNotify{ sceneAreaWeatherNotify := &proto.SceneAreaWeatherNotify{
WeatherAreaId: 0, WeatherAreaId: 0,
@@ -335,7 +351,7 @@ func (g *Game) AddSceneEntityNotifyToPlayer(player *model.Player, visionType pro
} }
// AddSceneEntityNotifyBroadcast 添加的场景实体广播 // AddSceneEntityNotifyBroadcast 添加的场景实体广播
func (g *Game) AddSceneEntityNotifyBroadcast(player *model.Player, scene *Scene, visionType proto.VisionType, entityList []*proto.SceneEntityInfo, aec bool) { func (g *Game) AddSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityList []*proto.SceneEntityInfo, aec bool, player *model.Player) {
sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{ sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{
AppearType: visionType, AppearType: visionType,
EntityList: entityList, EntityList: entityList,
@@ -362,12 +378,15 @@ func (g *Game) RemoveSceneEntityNotifyToPlayer(player *model.Player, visionType
} }
// RemoveSceneEntityNotifyBroadcast 移除的场景实体广播 // RemoveSceneEntityNotifyBroadcast 移除的场景实体广播
func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityIdList []uint32) { func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityIdList []uint32, aec bool, player *model.Player) {
sceneEntityDisappearNotify := &proto.SceneEntityDisappearNotify{ sceneEntityDisappearNotify := &proto.SceneEntityDisappearNotify{
EntityList: entityIdList, EntityList: entityIdList,
DisappearType: visionType, DisappearType: visionType,
} }
for _, scenePlayer := range scene.GetAllPlayer() { for _, scenePlayer := range scene.GetAllPlayer() {
if aec && scenePlayer.PlayerID == player.PlayerID {
continue
}
g.SendMsg(cmd.SceneEntityDisappearNotify, scenePlayer.PlayerID, scenePlayer.ClientSeq, sceneEntityDisappearNotify) g.SendMsg(cmd.SceneEntityDisappearNotify, scenePlayer.PlayerID, scenePlayer.ClientSeq, sceneEntityDisappearNotify)
logger.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v", logger.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
scenePlayer.PlayerID, sceneEntityDisappearNotify.DisappearType, len(sceneEntityDisappearNotify.EntityList)) scenePlayer.PlayerID, sceneEntityDisappearNotify.DisappearType, len(sceneEntityDisappearNotify.EntityList))
@@ -426,7 +445,7 @@ func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.Visio
} }
} }
if broadcast { if broadcast {
g.AddSceneEntityNotifyBroadcast(player, scene, visionType, entityList, aec) g.AddSceneEntityNotifyBroadcast(scene, visionType, entityList, aec, player)
} else { } else {
g.AddSceneEntityNotifyToPlayer(player, visionType, entityList) g.AddSceneEntityNotifyToPlayer(player, visionType, entityList)
} }
@@ -529,7 +548,7 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
MoveReliableSeq: entity.GetLastMoveReliableSeq(), MoveReliableSeq: entity.GetLastMoveReliableSeq(),
} }
g.SendToWorldA(scene.world, cmd.LifeStateChangeNotify, 0, ntf) g.SendToWorldA(scene.world, cmd.LifeStateChangeNotify, 0, ntf)
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_DIE, []uint32{entity.GetId()}) g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_DIE, []uint32{entity.GetId()}, false, nil)
// 删除实体 // 删除实体
scene.DestroyEntity(entity.GetId()) scene.DestroyEntity(entity.GetId())
group := scene.GetGroupById(entity.GetGroupId()) group := scene.GetGroupById(entity.GetGroupId())

View File

@@ -140,7 +140,7 @@ func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
dbTeam.CurrAvatarIndex = uint8(currAvatarIndex) dbTeam.CurrAvatarIndex = uint8(currAvatarIndex)
world.SetPlayerAvatarIndex(player, currAvatarIndex) world.SetPlayerAvatarIndex(player, currAvatarIndex)
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world) sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerID, player.ClientSeq, sceneTeamUpdateNotify) g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerID, player.ClientSeq, sceneTeamUpdateNotify)
} }
@@ -173,7 +173,7 @@ func (g *Game) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb.Messag
world.UpdateMultiplayerTeam() world.UpdateMultiplayerTeam()
world.InitPlayerWorldAvatar(player) world.InitPlayerWorldAvatar(player)
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world) sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerID, player.ClientSeq, sceneTeamUpdateNotify) g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerID, player.ClientSeq, sceneTeamUpdateNotify)
chooseCurAvatarTeamRsp := &proto.ChooseCurAvatarTeamRsp{ chooseCurAvatarTeamRsp := &proto.ChooseCurAvatarTeamRsp{
@@ -186,7 +186,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq) req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
avatarGuidList := req.AvatarGuidList avatarGuidList := req.AvatarGuidList
world := WORLD_MANAGER.GetWorldByID(player.WorldId) world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if !world.GetMultiplayer() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 { if WORLD_MANAGER.IsBigWorld(world) || !world.GetMultiplayer() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 {
g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{}) g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
return return
} }
@@ -215,7 +215,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
world.SetPlayerAvatarIndex(player, newAvatarIndex) world.SetPlayerAvatarIndex(player, newAvatarIndex)
for _, worldPlayer := range world.GetAllPlayer() { for _, worldPlayer := range world.GetAllPlayer() {
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world) sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
g.SendMsg(cmd.SceneTeamUpdateNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneTeamUpdateNotify) g.SendMsg(cmd.SceneTeamUpdateNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneTeamUpdateNotify)
} }
@@ -226,12 +226,15 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
g.SendMsg(cmd.ChangeMpTeamAvatarRsp, player.PlayerID, player.ClientSeq, changeMpTeamAvatarRsp) g.SendMsg(cmd.ChangeMpTeamAvatarRsp, player.PlayerID, player.ClientSeq, changeMpTeamAvatarRsp)
} }
func (g *Game) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeamUpdateNotify { func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) *proto.SceneTeamUpdateNotify {
sceneTeamUpdateNotify := &proto.SceneTeamUpdateNotify{ sceneTeamUpdateNotify := &proto.SceneTeamUpdateNotify{
IsInMp: world.GetMultiplayer(), IsInMp: world.GetMultiplayer(),
} }
empty := new(proto.AbilitySyncStateInfo) empty := new(proto.AbilitySyncStateInfo)
for _, worldAvatar := range world.GetWorldAvatarList() { for _, worldAvatar := range world.GetWorldAvatarList() {
if WORLD_MANAGER.IsBigWorld(world) && worldAvatar.uid != player.PlayerID {
continue
}
worldPlayer := USER_MANAGER.GetOnlineUser(worldAvatar.GetUid()) worldPlayer := USER_MANAGER.GetOnlineUser(worldAvatar.GetUid())
if worldPlayer == nil { if worldPlayer == nil {
logger.Error("player is nil, uid: %v", worldAvatar.GetUid()) logger.Error("player is nil, uid: %v", worldAvatar.GetUid())

View File

@@ -120,7 +120,7 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
} }
// 删除已创建的载具 // 删除已创建的载具
scene.DestroyEntity(entity.GetId()) scene.DestroyEntity(entity.GetId())
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{entity.GetId()}) g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{entity.GetId()}, false, nil)
} }
// EnterVehicle 进入载具 // EnterVehicle 进入载具

View File

@@ -518,7 +518,7 @@ func (g *Game) TeleportPlayer(
return return
} }
activeAvatarId := world.GetPlayerActiveAvatarId(player) activeAvatarId := world.GetPlayerActiveAvatarId(player)
g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}) g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}, false, nil)
if jumpScene { if jumpScene {
delTeamEntityNotify := g.PacketDelTeamEntityNotify(oldScene, player) delTeamEntityNotify := g.PacketDelTeamEntityNotify(oldScene, player)
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerID, player.ClientSeq, delTeamEntityNotify) g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerID, player.ClientSeq, delTeamEntityNotify)