mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
big world mmorpg mode
This commit is contained in:
@@ -311,7 +311,7 @@ func UpdateFrame(rgb bool) {
|
||||
for _, v := range SCREEN_ENTITY_ID_LIST {
|
||||
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)
|
||||
leftTopPos := &model.Vector{
|
||||
X: BASE_POS.X + float64(SCREEN_WIDTH)*SCREEN_DPI/2,
|
||||
|
||||
@@ -90,10 +90,7 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
|
||||
USER_MANAGER.SetRemoteUserOnlineState(BigWorldAiUid, true, mainGsAppid)
|
||||
if r.IsMainGs() {
|
||||
// TODO 测试
|
||||
r.ai.Pos.X -= random.GetRandomFloat64(25.0, 35.0)
|
||||
r.ai.Pos.Y += 1.0
|
||||
r.ai.Pos.Z += random.GetRandomFloat64(25.0, 35.0)
|
||||
for i := 1; i < 3; i++ {
|
||||
for i := 1; i < 100; i++ {
|
||||
uid := 1000000 + uint32(i)
|
||||
avatarId := uint32(0)
|
||||
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},
|
||||
CurAvatarGuid: dbAvatar.AvatarMap[avatarId].Guid,
|
||||
})
|
||||
robot.Pos.X -= random.GetRandomFloat64(25.0, 35.0)
|
||||
robot.Pos.Y += 1.0
|
||||
robot.Pos.Z += random.GetRandomFloat64(25.0, 35.0)
|
||||
pos := &model.Vector{
|
||||
X: 1800.0 + random.GetRandomFloat64(-100.0, 100.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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/pkg/random"
|
||||
"hk4e/protocol/cmd"
|
||||
@@ -190,33 +191,37 @@ func (t *TickManager) onTickMinute(now int64) {
|
||||
gdconf.LuaStateLruRemove()
|
||||
for _, world := range WORLD_MANAGER.GetAllWorld() {
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
// 随机物品
|
||||
allItemDataConfig := GAME.GetAllItemDataConfig()
|
||||
count := random.GetRandomInt32(0, 4)
|
||||
i := int32(0)
|
||||
for itemId := range allItemDataConfig {
|
||||
num := random.GetRandomInt32(1, 9)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0)
|
||||
i++
|
||||
if i > count {
|
||||
break
|
||||
if player.SceneLoadState == model.SceneEnterDone {
|
||||
// 随机物品
|
||||
allItemDataConfig := GAME.GetAllItemDataConfig()
|
||||
count := random.GetRandomInt32(0, 4)
|
||||
i := int32(0)
|
||||
for itemId := range allItemDataConfig {
|
||||
num := random.GetRandomInt32(1, 9)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0)
|
||||
i++
|
||||
if i > count {
|
||||
break
|
||||
}
|
||||
}
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 102, ChangeCount: 30}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 201, ChangeCount: 10}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 202, ChangeCount: 100}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 203, ChangeCount: 10}}, true, 0)
|
||||
// 蓝球粉球
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 223, ChangeCount: 1}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 224, ChangeCount: 1}}, true, 0)
|
||||
}
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 102, ChangeCount: 30}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 201, ChangeCount: 10}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 202, ChangeCount: 100}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 203, ChangeCount: 10}}, true, 0)
|
||||
// 蓝球粉球
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 223, ChangeCount: 1}}, true, 0)
|
||||
GAME.AddUserItem(player.PlayerID, []*ChangeItem{{ItemId: 224, ChangeCount: 1}}, true, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TickManager) onTick10Second(now int64) {
|
||||
for _, world := range WORLD_MANAGER.GetAllWorld() {
|
||||
GAME.SceneTimeNotify(world)
|
||||
GAME.PlayerTimeNotify(world)
|
||||
if world.GetOwner().SceneLoadState == model.SceneEnterDone {
|
||||
GAME.SceneTimeNotify(world)
|
||||
GAME.PlayerTimeNotify(world)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,16 +232,20 @@ func (t *TickManager) onTick5Second(now int64) {
|
||||
GAME.UserDealEnterWorld(world.owner, applyUid, true)
|
||||
}
|
||||
}
|
||||
// 多人世界其他玩家的坐标位置广播
|
||||
GAME.WorldPlayerLocationNotify(world)
|
||||
GAME.ScenePlayerLocationNotify(world)
|
||||
if world.GetOwner().SceneLoadState == model.SceneEnterDone {
|
||||
// 多人世界其他玩家的坐标位置广播
|
||||
GAME.WorldPlayerLocationNotify(world)
|
||||
GAME.ScenePlayerLocationNotify(world)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TickManager) onTickSecond(now int64) {
|
||||
for _, world := range WORLD_MANAGER.GetAllWorld() {
|
||||
// 世界里所有玩家的网络延迟广播
|
||||
GAME.WorldPlayerRTTNotify(world)
|
||||
if world.GetOwner().SceneLoadState == model.SceneEnterDone {
|
||||
// 世界里所有玩家的网络延迟广播
|
||||
GAME.WorldPlayerRTTNotify(world)
|
||||
}
|
||||
}
|
||||
// // GCG游戏Tick
|
||||
// for _, game := range GCG_MANAGER.gameMap {
|
||||
@@ -247,10 +256,12 @@ func (t *TickManager) onTickSecond(now int64) {
|
||||
func (t *TickManager) onTick200MilliSecond(now int64) {
|
||||
for _, world := range WORLD_MANAGER.GetAllWorld() {
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
// 耐力消耗
|
||||
GAME.SustainStaminaHandler(player)
|
||||
GAME.VehicleRestoreStaminaHandler(player)
|
||||
GAME.DrownBackHandler(player)
|
||||
if player.SceneLoadState == model.SceneEnterDone {
|
||||
// 耐力消耗
|
||||
GAME.SustainStaminaHandler(player)
|
||||
GAME.VehicleRestoreStaminaHandler(player)
|
||||
GAME.DrownBackHandler(player)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,16 @@ func (w *WorldManager) CreateWorld(owner *model.Player) *World {
|
||||
waitEnterPlayerMap: make(map[uint32]int64),
|
||||
multiplayerTeam: CreateMultiplayerTeam(),
|
||||
peerList: make([]*model.Player, 0),
|
||||
bigWorldAoi: nil,
|
||||
}
|
||||
world.mpLevelEntityId = world.GetNextWorldEntityId(constant.ENTITY_TYPE_MP_LEVEL)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -94,15 +101,11 @@ func (w *WorldManager) InitAiWorld(owner *model.Player) {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -216,6 +219,7 @@ type World struct {
|
||||
waitEnterPlayerMap map[uint32]int64 // 进入世界的玩家等待列表 key:uid value:开始时间
|
||||
multiplayerTeam *MultiplayerTeam // 多人队伍
|
||||
peerList []*model.Player // 玩家编号列表
|
||||
bigWorldAoi *alg.AoiManager // 大世界的aoi管理器
|
||||
}
|
||||
|
||||
func (w *World) GetId() uint32 {
|
||||
@@ -335,11 +339,7 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
|
||||
activeAvatarId := dbTeam.GetActiveAvatarId()
|
||||
w.SetPlayerLocalTeam(player, []uint32{activeAvatarId})
|
||||
}
|
||||
playerNum := w.GetWorldPlayerNum()
|
||||
if playerNum > 4 {
|
||||
if !WORLD_MANAGER.IsBigWorld(w) {
|
||||
return
|
||||
}
|
||||
if WORLD_MANAGER.IsBigWorld(w) {
|
||||
w.AddMultiplayerTeam(player)
|
||||
} else {
|
||||
w.UpdateMultiplayerTeam()
|
||||
@@ -362,6 +362,12 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
|
||||
}
|
||||
scene.AddPlayer(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) {
|
||||
@@ -374,12 +380,10 @@ func (w *World) RemovePlayer(player *model.Player) {
|
||||
delete(w.multiplayerTeam.localTeamMap, player.PlayerID)
|
||||
delete(w.multiplayerTeam.localAvatarIndexMap, player.PlayerID)
|
||||
delete(w.multiplayerTeam.localTeamEntityMap, player.PlayerID)
|
||||
playerNum := w.GetWorldPlayerNum()
|
||||
if playerNum > 4 {
|
||||
if !WORLD_MANAGER.IsBigWorld(w) {
|
||||
return
|
||||
}
|
||||
if WORLD_MANAGER.IsBigWorld(w) {
|
||||
w.RemoveMultiplayerTeam(player)
|
||||
w.bigWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerID),
|
||||
float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
|
||||
} else {
|
||||
if player.PlayerID != w.owner.PlayerID {
|
||||
w.UpdateMultiplayerTeam()
|
||||
@@ -663,9 +667,6 @@ func (w *World) copyLocalTeamToWorld(start int, end int, peerId uint32) {
|
||||
// 看来还是不能简单的走通用逻辑 需要对大世界场景队伍做特殊处理 欺骗客户端其他玩家仅仅以场景角色实体的形式出现
|
||||
|
||||
func (w *World) AddMultiplayerTeam(player *model.Player) {
|
||||
if !WORLD_MANAGER.IsBigWorld(w) {
|
||||
return
|
||||
}
|
||||
localTeam := w.GetPlayerLocalTeam(player)
|
||||
w.multiplayerTeam.worldTeam = append(w.multiplayerTeam.worldTeam, localTeam...)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
if oldGid != newGid {
|
||||
// 跨越了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
|
||||
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)
|
||||
newVisionEntityMap := g.GetVisionEntity(scene, newPos)
|
||||
delEntityIdList := make([]uint32, 0)
|
||||
for entityId := range oldVisionEntityMap {
|
||||
for entityId, entity := range oldVisionEntityMap {
|
||||
_, exist := newVisionEntityMap[entityId]
|
||||
if exist {
|
||||
continue
|
||||
}
|
||||
if WORLD_MANAGER.IsBigWorld(world) {
|
||||
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// 旧有新没有的实体即为消失的
|
||||
delEntityIdList = append(delEntityIdList, entityId)
|
||||
}
|
||||
addEntityIdList := make([]uint32, 0)
|
||||
for entityId := range newVisionEntityMap {
|
||||
for entityId, entity := range newVisionEntityMap {
|
||||
_, exist := oldVisionEntityMap[entityId]
|
||||
if exist {
|
||||
continue
|
||||
}
|
||||
if WORLD_MANAGER.IsBigWorld(world) {
|
||||
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// 新有旧没有的实体即为出现的
|
||||
addEntityIdList = append(addEntityIdList, entityId)
|
||||
}
|
||||
@@ -318,6 +328,60 @@ func (g *Game) AoiPlayerMove(player *model.Player, oldPos *model.Vector, newPos
|
||||
if len(addEntityIdList) > 0 {
|
||||
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) {
|
||||
@@ -535,7 +599,7 @@ func (g *Game) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb.Messag
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
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) {
|
||||
|
||||
@@ -149,10 +149,6 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player
|
||||
}
|
||||
g.SendMsg(cmd.PlayerLoginRsp, userId, clientSeq, playerLoginRsp)
|
||||
|
||||
if userId < PlayerBaseUid {
|
||||
return
|
||||
}
|
||||
|
||||
MESSAGE_QUEUE.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerUserOnlineStateChangeNotify,
|
||||
@@ -161,6 +157,9 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player
|
||||
IsOnline: true,
|
||||
},
|
||||
})
|
||||
if userId < PlayerBaseUid {
|
||||
return
|
||||
}
|
||||
atomic.AddInt32(&ONLINE_PLAYER_NUM, 1)
|
||||
|
||||
SELF = nil
|
||||
|
||||
@@ -348,9 +348,12 @@ func (g *Game) HostEnterMpWorld(hostPlayer *model.Player) {
|
||||
)
|
||||
g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify)
|
||||
|
||||
// 仅仅把当前的场上角色的实体消失掉
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(hostPlayer)
|
||||
g.RemoveSceneEntityNotifyToPlayer(hostPlayer, proto.VisionType_VISION_MISS, []uint32{world.GetPlayerWorldAvatarEntityId(hostPlayer, activeAvatarId)})
|
||||
scene := world.GetSceneById(hostPlayer.SceneId)
|
||||
entityIdList := make([]uint32, 0)
|
||||
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 {
|
||||
@@ -412,7 +415,7 @@ func (g *Game) UserWorldRemovePlayer(world *World, player *model.Player) {
|
||||
g.SendMsg(cmd.PlayerQuitFromMpNotify, player.PlayerID, player.ClientSeq, playerQuitFromMpNotify)
|
||||
|
||||
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)
|
||||
@@ -488,7 +491,7 @@ func (g *Game) UpdateWorldScenePlayerInfo(player *model.Player, world *World) {
|
||||
}
|
||||
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)
|
||||
|
||||
syncTeamEntityNotify := &proto.SyncTeamEntityNotify{
|
||||
|
||||
@@ -244,23 +244,39 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
activeAvatarEntityId := world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)
|
||||
g.AddSceneEntityNotify(player, visionType, []uint32{activeAvatarEntityId}, true, false)
|
||||
activeWorldAvatar := world.GetPlayerWorldAvatar(player, activeAvatarId)
|
||||
g.AddSceneEntityNotify(player, visionType, []uint32{
|
||||
activeWorldAvatar.GetAvatarEntityId(),
|
||||
}, true, false)
|
||||
|
||||
// 加载附近的group
|
||||
for _, groupConfig := range g.GetNeighborGroup(scene.GetId(), player.Pos) {
|
||||
g.AddSceneGroup(player, scene, groupConfig)
|
||||
}
|
||||
// 同步客户端视野内的场景实体
|
||||
entityIdList := make([]uint32, 0)
|
||||
visionEntityMap := g.GetVisionEntity(scene, player.Pos)
|
||||
for _, entity := range visionEntityMap {
|
||||
if entity.GetId() == activeAvatarEntityId {
|
||||
entityIdList := make([]uint32, 0)
|
||||
for entityId, entity := range visionEntityMap {
|
||||
if entityId == activeWorldAvatar.GetAvatarEntityId() {
|
||||
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)
|
||||
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{
|
||||
WeatherAreaId: 0,
|
||||
@@ -335,7 +351,7 @@ func (g *Game) AddSceneEntityNotifyToPlayer(player *model.Player, visionType pro
|
||||
}
|
||||
|
||||
// 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{
|
||||
AppearType: visionType,
|
||||
EntityList: entityList,
|
||||
@@ -362,12 +378,15 @@ func (g *Game) RemoveSceneEntityNotifyToPlayer(player *model.Player, visionType
|
||||
}
|
||||
|
||||
// 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{
|
||||
EntityList: entityIdList,
|
||||
DisappearType: visionType,
|
||||
}
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
if aec && scenePlayer.PlayerID == player.PlayerID {
|
||||
continue
|
||||
}
|
||||
g.SendMsg(cmd.SceneEntityDisappearNotify, scenePlayer.PlayerID, scenePlayer.ClientSeq, sceneEntityDisappearNotify)
|
||||
logger.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
|
||||
scenePlayer.PlayerID, sceneEntityDisappearNotify.DisappearType, len(sceneEntityDisappearNotify.EntityList))
|
||||
@@ -426,7 +445,7 @@ func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.Visio
|
||||
}
|
||||
}
|
||||
if broadcast {
|
||||
g.AddSceneEntityNotifyBroadcast(player, scene, visionType, entityList, aec)
|
||||
g.AddSceneEntityNotifyBroadcast(scene, visionType, entityList, aec, player)
|
||||
} else {
|
||||
g.AddSceneEntityNotifyToPlayer(player, visionType, entityList)
|
||||
}
|
||||
@@ -529,7 +548,7 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
|
||||
MoveReliableSeq: entity.GetLastMoveReliableSeq(),
|
||||
}
|
||||
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())
|
||||
group := scene.GetGroupById(entity.GetGroupId())
|
||||
|
||||
@@ -140,7 +140,7 @@ func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
|
||||
dbTeam.CurrAvatarIndex = uint8(currAvatarIndex)
|
||||
world.SetPlayerAvatarIndex(player, currAvatarIndex)
|
||||
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world)
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
|
||||
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.InitPlayerWorldAvatar(player)
|
||||
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world)
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
|
||||
g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerID, player.ClientSeq, sceneTeamUpdateNotify)
|
||||
|
||||
chooseCurAvatarTeamRsp := &proto.ChooseCurAvatarTeamRsp{
|
||||
@@ -186,7 +186,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
|
||||
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
|
||||
avatarGuidList := req.AvatarGuidList
|
||||
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{})
|
||||
return
|
||||
}
|
||||
@@ -215,7 +215,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
|
||||
world.SetPlayerAvatarIndex(player, newAvatarIndex)
|
||||
|
||||
for _, worldPlayer := range world.GetAllPlayer() {
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world)
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
|
||||
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)
|
||||
}
|
||||
|
||||
func (g *Game) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeamUpdateNotify {
|
||||
func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) *proto.SceneTeamUpdateNotify {
|
||||
sceneTeamUpdateNotify := &proto.SceneTeamUpdateNotify{
|
||||
IsInMp: world.GetMultiplayer(),
|
||||
}
|
||||
empty := new(proto.AbilitySyncStateInfo)
|
||||
for _, worldAvatar := range world.GetWorldAvatarList() {
|
||||
if WORLD_MANAGER.IsBigWorld(world) && worldAvatar.uid != player.PlayerID {
|
||||
continue
|
||||
}
|
||||
worldPlayer := USER_MANAGER.GetOnlineUser(worldAvatar.GetUid())
|
||||
if worldPlayer == nil {
|
||||
logger.Error("player is nil, uid: %v", worldAvatar.GetUid())
|
||||
|
||||
@@ -120,7 +120,7 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
|
||||
}
|
||||
// 删除已创建的载具
|
||||
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 进入载具
|
||||
|
||||
@@ -518,7 +518,7 @@ func (g *Game) TeleportPlayer(
|
||||
return
|
||||
}
|
||||
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 {
|
||||
delTeamEntityNotify := g.PacketDelTeamEntityNotify(oldScene, player)
|
||||
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerID, player.ClientSeq, delTeamEntityNotify)
|
||||
|
||||
Reference in New Issue
Block a user