From 1b27b54237f6c0b9beeb1f8e58ba98eec5957215 Mon Sep 17 00:00:00 2001 From: flswld Date: Wed, 27 Sep 2023 18:04:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4AI=E4=B8=96=E7=95=8C=E7=9A=84?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdconf/vehicle_data.go | 3 +- gs/game/game.go | 43 +++++--------- gs/game/game_command_controller.go | 5 +- gs/game/game_command_gm.go | 33 +++++------ gs/game/game_route_manager.go | 2 + gs/game/game_tick_manager.go | 88 +++++++++++++--------------- gs/game/game_user_manager.go | 29 +++++++-- gs/game/game_world_manager.go | 32 ++++------ gs/game/game_world_scene.go | 26 ++++---- gs/game/player_common.go | 19 +++--- gs/game/player_fight_sync.go | 60 ++++++++----------- gs/game/player_multiplayer.go | 8 +-- gs/game/player_scene.go | 58 ++++++++---------- gs/game/player_social.go | 41 +++++++------ gs/game/player_stamina.go | 2 +- gs/game/player_team.go | 8 +-- gs/game/player_world.go | 51 ++++++++++++---- protocol/cmd/cmd_id_proto_obj_map.go | 2 + 18 files changed, 262 insertions(+), 248 deletions(-) diff --git a/gdconf/vehicle_data.go b/gdconf/vehicle_data.go index ed919973..02331a31 100644 --- a/gdconf/vehicle_data.go +++ b/gdconf/vehicle_data.go @@ -2,10 +2,11 @@ package gdconf import ( "fmt" - "hk4e/pkg/logger" "os" "strings" + "hk4e/pkg/logger" + "github.com/hjson/hjson-go/v4" ) diff --git a/gs/game/game.go b/gs/game/game.go index d80d257b..0137ac6d 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -23,11 +23,8 @@ const ( PlayerBaseUid = 100000000 MaxPlayerBaseUid = 200000000 AiBaseUid = 10000 - AiName = "GM" + AiName = "小可爱" AiSign = "快捷指令" - BigWorldAiUid = 100 - BigWorldAiName = "小可爱" - BigWorldAiSign = "UnKownOwO" ) var GAME *Game = nil @@ -77,17 +74,9 @@ func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppi uid := AiBaseUid + gsId name := AiName sign := AiSign + " GS:" + strconv.Itoa(int(gsId)) - if r.IsMainGs() { - // 约定MainGameServer的Ai的AiWorld叫BigWorld - // 此世界会出现在全服的在线玩家列表中 所有的玩家都可以进入到此世界里来 - uid = BigWorldAiUid - name = BigWorldAiName - sign = BigWorldAiSign - } r.ai = r.CreateRobot(uid, name, sign) WORLD_MANAGER.InitAiWorld(r.ai) COMMAND_MANAGER.SetSystem(r.ai) - USER_MANAGER.SetRemoteUserOnlineState(BigWorldAiUid, true, mainGsAppid) r.run() r.isStop = false return r @@ -134,17 +123,13 @@ func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player { g.PostEnterSceneReq(robot, &proto.PostEnterSceneReq{ EnterSceneToken: world.GetEnterSceneToken(), }) - if uid == BigWorldAiUid { - g.EntityForceSyncReq(robot, &proto.EntityForceSyncReq{ - MotionInfo: &proto.MotionInfo{ - Pos: &proto.Vector{X: 500.0, Y: 900.0, Z: -500.0}, - Rot: new(proto.Vector), - }, - EntityId: world.GetPlayerWorldAvatarEntityId(robot, 10000007), - }) - } else { - COMMAND_MANAGER.gmCmd.GMUnlockAllPoint(uid, 3) - } + g.EntityForceSyncReq(robot, &proto.EntityForceSyncReq{ + MotionInfo: &proto.MotionInfo{ + Pos: &proto.Vector{X: 500.0, Y: 900.0, Z: -500.0}, + Rot: new(proto.Vector), + }, + EntityId: world.GetPlayerWorldAvatarEntityId(robot, 10000007), + }) return robot } @@ -426,9 +411,9 @@ func (g *Game) SendToWorldH(world *World, cmdId uint16, seq uint32, msg pb.Messa // SendToSceneA 给场景内所有玩家发消息 func (g *Game) SendToSceneA(scene *Scene, cmdId uint16, seq uint32, msg pb.Message) { world := scene.GetWorld() - if WORLD_MANAGER.IsBigWorld(world) && SELF != nil { - bigWorldAoi := world.GetBigWorldAoi() - otherWorldAvatarMap := bigWorldAoi.GetObjectListByPos(float32(SELF.Pos.X), float32(SELF.Pos.Y), float32(SELF.Pos.Z)) + if WORLD_MANAGER.IsAiWorld(world) && SELF != nil { + aiWorldAoi := world.GetAiWorldAoi() + otherWorldAvatarMap := aiWorldAoi.GetObjectListByPos(float32(SELF.Pos.X), float32(SELF.Pos.Y), float32(SELF.Pos.Z)) for uid := range otherWorldAvatarMap { g.SendMsg(cmdId, uint32(uid), seq, msg) } @@ -442,9 +427,9 @@ func (g *Game) SendToSceneA(scene *Scene, cmdId uint16, seq uint32, msg pb.Messa // SendToSceneAEC 给场景内除某玩家(一般是自己)以外的所有玩家发消息 func (g *Game) SendToSceneAEC(scene *Scene, cmdId uint16, seq uint32, msg pb.Message, aecUid uint32) { world := scene.GetWorld() - if WORLD_MANAGER.IsBigWorld(world) && SELF != nil { - bigWorldAoi := world.GetBigWorldAoi() - otherWorldAvatarMap := bigWorldAoi.GetObjectListByPos(float32(SELF.Pos.X), float32(SELF.Pos.Y), float32(SELF.Pos.Z)) + if WORLD_MANAGER.IsAiWorld(world) && SELF != nil { + aiWorldAoi := world.GetAiWorldAoi() + otherWorldAvatarMap := aiWorldAoi.GetObjectListByPos(float32(SELF.Pos.X), float32(SELF.Pos.Y), float32(SELF.Pos.Z)) for uid := range otherWorldAvatarMap { if aecUid == uint32(uid) { continue diff --git a/gs/game/game_command_controller.go b/gs/game/game_command_controller.go index d91ebe4c..fb9ba477 100644 --- a/gs/game/game_command_controller.go +++ b/gs/game/game_command_controller.go @@ -2,10 +2,11 @@ package game import ( "fmt" - "hk4e/gdconf" - "hk4e/pkg/logger" "strconv" "strings" + + "hk4e/gdconf" + "hk4e/pkg/logger" ) // 玩家游戏内GM命令格式解析模块 diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go index 8851f551..6afa9579 100644 --- a/gs/game/game_command_gm.go +++ b/gs/game/game_command_gm.go @@ -2,6 +2,7 @@ package game import ( "encoding/base64" + "hk4e/common/constant" "hk4e/gdconf" "hk4e/gs/model" @@ -407,7 +408,8 @@ func (g *GMCmd) ChangePlayerCmdPerm(userId uint32, cmdPerm uint8) { player.CmdPerm = cmdPerm } -func (g *GMCmd) ReloadGameDataConfig() { +func (g *GMCmd) ReloadGameDataConfig(v bool) { + // TODO 不知道为什么0个参数的函数会反射调用失败 LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{ EventId: ReloadGameDataConfig, } @@ -451,10 +453,7 @@ func (g *GMCmd) UpdateFrame(rgb bool) { var RobotUidCounter uint32 = 0 -func (g *GMCmd) CreateRobotInBigWorld(uid uint32, name string, avatarId uint32) { - if !GAME.IsMainGs() { - return - } +func (g *GMCmd) CreateRobotInAiWorld(uid uint32, name string, avatarId uint32) { if uid == 0 { RobotUidCounter++ uid = 1000000 + RobotUidCounter @@ -560,27 +559,23 @@ func (g *GMCmd) SendMsgToPlayer(cmdName string, userId uint32, msgJson string) { } func (g *GMCmd) StartPubg(v bool) { - if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { - world.StartPubg() - } + world := WORLD_MANAGER.GetAiWorld() + world.StartPubg() } func (g *GMCmd) StopPubg(v bool) { - if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { - world.StopPubg() - } + world := WORLD_MANAGER.GetAiWorld() + world.StopPubg() } func (g *GMCmd) SetPhysicsEngineParam(pathTracing bool, acc float32, drag float32, pao float32, is float32, ayo float32) { - if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { - engine := world.GetBulletPhysicsEngine() - engine.SetPhysicsEngineParam(pathTracing, acc, drag, pao, is, ayo) - } + world := WORLD_MANAGER.GetAiWorld() + engine := world.GetBulletPhysicsEngine() + engine.SetPhysicsEngineParam(pathTracing, acc, drag, pao, is, ayo) } func (g *GMCmd) ShowAvatarCollider(v bool) { - if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { - engine := world.GetBulletPhysicsEngine() - engine.ShowAvatarCollider() - } + world := WORLD_MANAGER.GetAiWorld() + engine := world.GetBulletPhysicsEngine() + engine.ShowAvatarCollider() } diff --git a/gs/game/game_route_manager.go b/gs/game/game_route_manager.go index f65417dd..49beb5ad 100644 --- a/gs/game/game_route_manager.go +++ b/gs/game/game_route_manager.go @@ -119,6 +119,8 @@ func (r *RouteManager) initRoute() { r.registerRouter(cmd.AvatarDieAnimationEndReq, GAME.AvatarDieAnimationEndReq) r.registerRouter(cmd.WorldPlayerReviveReq, GAME.WorldPlayerReviveReq) r.registerRouter(cmd.UseItemReq, GAME.UseItemReq) + r.registerRouter(cmd.EnterTransPointRegionNotify, GAME.EnterTransPointRegionNotify) + r.registerRouter(cmd.ExitTransPointRegionNotify, GAME.ExitTransPointRegionNotify) } type HandlerFunc func(player *model.Player, payloadMsg pb.Message) diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index 1d7aee1e..0689b529 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -157,7 +157,6 @@ func (t *TickManager) userTimerHandle(userId uint32, action int, data []any) { } pubg := world.GetPubg() if pubg == nil { - logger.Error("pubg is nil, worldId: %v, uid: %v", player.WorldId, userId) return } pubg.phase++ @@ -255,12 +254,11 @@ func (t *TickManager) onDayChange(now int64) { func (t *TickManager) onHourChange(now int64) { logger.Info("on hour change, time: %v", now) - if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { - if world.GetPubg() != nil { - return - } - world.StartPubg() + world := WORLD_MANAGER.GetAiWorld() + if world.GetPubg() != nil { + return } + world.StartPubg() } func (t *TickManager) onTickHour(now int64) { @@ -289,7 +287,7 @@ func (t *TickManager) onTick5Second(now int64) { } } aiWorld := WORLD_MANAGER.GetAiWorld() - if WORLD_MANAGER.IsBigWorld(aiWorld) { + if WORLD_MANAGER.IsAiWorld(aiWorld) { if aiWorld.GetPubg() != nil { return } @@ -314,32 +312,31 @@ func (t *TickManager) onTickSecond(now int64) { game.onTick() } // PUBG游戏 - if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { - pubg := world.GetPubg() - if pubg == nil { - return + world := WORLD_MANAGER.GetAiWorld() + pubg := world.GetPubg() + if pubg == nil { + return + } + pubg.UpdateArea() + scene := world.GetSceneById(world.GetOwner().SceneId) + for _, scenePlayer := range scene.GetAllPlayer() { + if !pubg.IsInBlueArea(scenePlayer.Pos) { + GAME.handleEvtBeingHit(scenePlayer, scene, &proto.EvtBeingHitInfo{ + AttackResult: &proto.AttackResult{ + AttackerId: 0, + DefenseId: world.GetPlayerWorldAvatarEntityId(scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer)), + Damage: 10, + }, + }) } - pubg.UpdateArea() - scene := world.GetSceneById(world.GetOwner().SceneId) - for _, scenePlayer := range scene.GetAllPlayer() { - if !pubg.IsInBlueArea(scenePlayer.Pos) { - GAME.handleEvtBeingHit(scenePlayer, scene, &proto.EvtBeingHitInfo{ - AttackResult: &proto.AttackResult{ - AttackerId: 0, - DefenseId: world.GetPlayerWorldAvatarEntityId(scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer)), - Damage: 10, - }, - }) - } - } - alivePlayerList := pubg.GetAlivePlayerList() - if len(alivePlayerList) <= 1 { - if len(alivePlayerList) == 1 { - info := fmt.Sprintf("『%v』大吉大利,今晚吃鸡。", alivePlayerList[0].NickName) - GAME.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}}) - } - world.StopPubg() + } + alivePlayerList := pubg.GetAlivePlayerList() + if len(alivePlayerList) <= 1 { + if len(alivePlayerList) == 1 { + info := fmt.Sprintf("『%v』大吉大利,今晚吃鸡。", alivePlayerList[0].NickName) + GAME.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}}) } + world.StopPubg() } } @@ -364,21 +361,20 @@ func (t *TickManager) onTick100MilliSecond(now int64) { } } } - if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { - bulletPhysicsEngine := world.GetBulletPhysicsEngine() - hitList := bulletPhysicsEngine.Update(now) - for _, rigidBody := range hitList { - scene := world.GetSceneById(rigidBody.sceneId) - defAvatarEntity := scene.GetEntity(rigidBody.hitAvatarEntityId) - defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid()) - GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{ - AttackResult: &proto.AttackResult{ - AttackerId: rigidBody.avatarEntityId, - DefenseId: rigidBody.hitAvatarEntityId, - Damage: 100, - }, - }) - } + world := WORLD_MANAGER.GetAiWorld() + bulletPhysicsEngine := world.GetBulletPhysicsEngine() + hitList := bulletPhysicsEngine.Update(now) + for _, rigidBody := range hitList { + scene := world.GetSceneById(rigidBody.sceneId) + defAvatarEntity := scene.GetEntity(rigidBody.hitAvatarEntityId) + defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid()) + GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{ + AttackResult: &proto.AttackResult{ + AttackerId: rigidBody.avatarEntityId, + DefenseId: rigidBody.hitAvatarEntityId, + Damage: 100, + }, + }) } } diff --git a/gs/game/game_user_manager.go b/gs/game/game_user_manager.go index 88077823..dcfba71b 100644 --- a/gs/game/game_user_manager.go +++ b/gs/game/game_user_manager.go @@ -276,6 +276,20 @@ func (u *UserManager) SetRemoteUserOnlineState(userId uint32, isOnline bool, app u.remotePlayerMapLock.Unlock() } +func (u *UserManager) GetAllRemoteAiUidList() []uint32 { + userIdList := make([]uint32, 0) + u.remotePlayerMapLock.RLock() + for userId := uint32(AiBaseUid); userId < AiBaseUid+1000; userId++ { + _, exist := u.remotePlayerMap[userId] + if !exist { + continue + } + userIdList = append(userIdList, userId) + } + u.remotePlayerMapLock.RUnlock() + return userIdList +} + // GetRemoteOnlineUserList 获取指定数量的远程在线玩家 玩家数据只读禁止修改 func (u *UserManager) GetRemoteOnlineUserList(total int) map[uint32]*model.Player { if total > 50 { @@ -286,6 +300,9 @@ func (u *UserManager) GetRemoteOnlineUserList(total int) map[uint32]*model.Playe userIdList := make([]uint32, 0) u.remotePlayerMapLock.RLock() for userId := range u.remotePlayerMap { + if userId < PlayerBaseUid || userId > MaxPlayerBaseUid { + continue + } userIdList = append(userIdList, userId) count++ if count >= total { @@ -335,6 +352,10 @@ func (u *UserManager) LoadGlobalPlayer(userId uint32) (player *model.Player, onl // LoadTempOfflineUser 加载临时离线玩家 // 正常情况速度较快可以同步阻塞调用 func (u *UserManager) LoadTempOfflineUser(userId uint32, lock bool) *model.Player { + if userId < PlayerBaseUid || userId > MaxPlayerBaseUid { + logger.Error("try to load a not exist uid, uid: %v", userId) + return nil + } player := u.GetOnlineUser(userId) if player != nil { logger.Error("not allow get a online player as offline player, uid: %v", userId) @@ -353,10 +374,6 @@ func (u *UserManager) LoadTempOfflineUser(userId uint32, lock bool) *model.Playe // 玩家可能不存在于redis 尝试从db查询出来然后写入redis // 大多数情况下活跃玩家都在redis 所以不会走到下面 // TODO 防止恶意攻击造成redis缓存穿透 - if userId < PlayerBaseUid || userId > MaxPlayerBaseUid { - logger.Error("try to load a not exist uid, uid: %v", userId) - return nil - } startTime := time.Now().UnixNano() player = u.LoadUserFromDbSync(userId) endTime := time.Now().UnixNano() @@ -377,6 +394,10 @@ func (u *UserManager) LoadTempOfflineUser(userId uint32, lock bool) *model.Playe // SaveTempOfflineUser 保存临时离线玩家 // 如果调用LoadTempOfflineUser获取了离线玩家数据 则必须在逻辑完成后立即调用此函数回写并解锁 func (u *UserManager) SaveTempOfflineUser(player *model.Player) { + if player.PlayerId < PlayerBaseUid || player.PlayerId > MaxPlayerBaseUid { + logger.Error("try to save a not exist uid, uid: %v", player.PlayerId) + return + } // 主协程同步写入redis u.SaveUserToRedisSync(player) // 另一个协程异步的写回db diff --git a/gs/game/game_world_manager.go b/gs/game/game_world_manager.go index 512bfbe0..893f465a 100644 --- a/gs/game/game_world_manager.go +++ b/gs/game/game_world_manager.go @@ -16,9 +16,9 @@ import ( // 世界管理器 const ( - ENTITY_NUM_UNLIMIT = true // 是否不限制场景内实体数量 - ENTITY_MAX_SEND_NUM = 1000 // 场景内最大实体数量 - MAX_MULTIPLAYER_WORLD_NUM = 10 // 本服务器最大多人世界数量 + ENTITY_NUM_UNLIMIT = false // 是否不限制场景内实体数量 + ENTITY_MAX_SEND_NUM = 10000 // 场景内最大实体数量 + MAX_MULTIPLAYER_WORLD_NUM = 10 // 本服务器最大多人世界数量 ) type WorldManager struct { @@ -64,17 +64,17 @@ func (w *WorldManager) CreateWorld(owner *model.Player) *World { waitEnterPlayerMap: make(map[uint32]int64), multiplayerTeam: CreateMultiplayerTeam(), peerList: make([]*model.Player, 0), - bigWorldAoi: nil, + aiWorldAoi: nil, } world.mpLevelEntityId = world.GetNextWorldEntityId(constant.ENTITY_TYPE_MP_LEVEL) w.worldMap[worldId] = world - if w.IsBigWorld(world) { + if w.IsAiWorld(world) { aoiManager := alg.NewAoiManager() aoiManager.SetAoiRange(-8000, 4000, -200, 1000, -5500, 6500) aoiManager.Init3DRectAoiManager(120, 12, 120, true) - world.bigWorldAoi = aoiManager - logger.Info("big world aoi init finish") + world.aiWorldAoi = aoiManager + logger.Info("ai world aoi init finish") } return world @@ -101,19 +101,13 @@ func (w *WorldManager) GetAiWorld() *World { func (w *WorldManager) InitAiWorld(owner *model.Player) { w.aiWorld = w.GetWorldById(owner.WorldId) w.aiWorld.ChangeToMultiplayer() - if w.IsBigWorld(w.aiWorld) { - w.aiWorld.NewPhysicsEngine(w.sceneBlockAoiMap) - } + w.aiWorld.NewPhysicsEngine(w.sceneBlockAoiMap) } func (w *WorldManager) IsAiWorld(world *World) bool { return world.owner.PlayerId < PlayerBaseUid } -func (w *WorldManager) IsBigWorld(world *World) bool { - return world.owner.PlayerId == BigWorldAiUid -} - func (w *WorldManager) GetSceneBlockAoiMap() map[uint32]*alg.AoiManager { return w.sceneBlockAoiMap } @@ -225,7 +219,7 @@ type World struct { waitEnterPlayerMap map[uint32]int64 // 进入世界的玩家等待列表 key:uid value:开始时间 multiplayerTeam *MultiplayerTeam // 多人队伍 peerList []*model.Player // 玩家编号列表 - bigWorldAoi *alg.AoiManager // 大世界的aoi管理器 + aiWorldAoi *alg.AoiManager // ai世界的aoi管理器 bulletPhysicsEngine *PhysicsEngine // 蓄力箭子弹物理引擎 pubg *Pubg } @@ -352,8 +346,8 @@ func (w *World) GetWorldPlayerNum() int { return len(w.playerMap) } -func (w *World) GetBigWorldAoi() *alg.AoiManager { - return w.bigWorldAoi +func (w *World) GetAiWorldAoi() *alg.AoiManager { + return w.aiWorldAoi } func (w *World) AddPlayer(player *model.Player, sceneId uint32) { @@ -368,7 +362,7 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) { activeAvatarId := dbTeam.GetActiveAvatarId() w.SetPlayerLocalTeam(player, []uint32{activeAvatarId}) } - if WORLD_MANAGER.IsBigWorld(w) { + if WORLD_MANAGER.IsAiWorld(w) { w.AddMultiplayerTeam(player) } else { w.UpdateMultiplayerTeam() @@ -400,7 +394,7 @@ 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) - if WORLD_MANAGER.IsBigWorld(w) { + if WORLD_MANAGER.IsAiWorld(w) { w.RemoveMultiplayerTeam(player) } else { if player.PlayerId != w.owner.PlayerId { diff --git a/gs/game/game_world_scene.go b/gs/game/game_world_scene.go index e91a636d..e0f28bdc 100644 --- a/gs/game/game_world_scene.go +++ b/gs/game/game_world_scene.go @@ -99,7 +99,7 @@ func (s *Scene) CreateEntityAvatar(player *model.Player, avatarId uint32) uint32 id: entityId, scene: s, lifeState: avatar.LifeState, - pos: player.Pos, + pos: player.Pos, // 所有角色实体暂时公用玩家的位置信息 rot: player.Rot, moveState: uint16(proto.MotionState_MOTION_NONE), lastMoveSceneTimeMs: 0, @@ -143,8 +143,8 @@ func (s *Scene) CreateEntityMonster(pos, rot *model.Vector, monsterId uint32, le id: entityId, scene: s, lifeState: constant.LIFE_STATE_ALIVE, - pos: pos, - rot: rot, + 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, @@ -167,8 +167,8 @@ func (s *Scene) CreateEntityNpc(pos, rot *model.Vector, npcId, roomId, parentQue id: entityId, scene: s, lifeState: constant.LIFE_STATE_ALIVE, - pos: pos, - rot: rot, + 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, @@ -197,8 +197,8 @@ func (s *Scene) CreateEntityGadgetNormal(pos, rot *model.Vector, gadgetId, gadge id: entityId, scene: s, lifeState: constant.LIFE_STATE_ALIVE, - pos: pos, - rot: rot, + 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, @@ -226,8 +226,8 @@ func (s *Scene) CreateEntityGadgetClient(pos, rot *model.Vector, entityId, confi id: entityId, scene: s, lifeState: constant.LIFE_STATE_ALIVE, - pos: pos, - rot: rot, + 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, @@ -264,8 +264,8 @@ func (s *Scene) CreateEntityGadgetVehicle(ownerUid uint32, pos, rot *model.Vecto id: entityId, scene: s, lifeState: constant.LIFE_STATE_ALIVE, - pos: pos, - rot: rot, + 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, @@ -460,11 +460,11 @@ func (e *Entity) GetLastDieType() int32 { } func (e *Entity) GetPos() *model.Vector { - return e.pos + return &model.Vector{X: e.pos.X, Y: e.pos.Y, Z: e.pos.Z} } func (e *Entity) GetRot() *model.Vector { - return e.rot + return &model.Vector{X: e.rot.X, Y: e.rot.Y, Z: e.rot.Z} } func (e *Entity) GetMoveState() uint16 { diff --git a/gs/game/player_common.go b/gs/game/player_common.go index bec23888..77231097 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -1,11 +1,12 @@ package game import ( - "hk4e/gdconf" "math" "strings" "time" + "hk4e/gdconf" + "hk4e/common/constant" "hk4e/gs/model" "hk4e/pkg/logger" @@ -154,7 +155,7 @@ func (g *Game) WorldPlayerLocationNotify(world *World) { }, } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { playerWorldLocationInfo.PlayerLoc.Pos = new(proto.Vector) playerWorldLocationInfo.PlayerLoc.Rot = new(proto.Vector) } @@ -187,7 +188,7 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { }, } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { playerLocationInfo.Pos = new(proto.Vector) playerLocationInfo.Rot = new(proto.Vector) } @@ -200,17 +201,17 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { if entity != nil && entity.GetEntityType() == constant.ENTITY_TYPE_GADGET && entity.gadgetEntity.gadgetVehicleEntity != nil { vehicleLocationInfo := &proto.VehicleLocationInfo{ Rot: &proto.Vector{ - X: float32(entity.rot.X), - Y: float32(entity.rot.Y), - Z: float32(entity.rot.Z), + X: float32(entity.GetRot().X), + Y: float32(entity.GetRot().Y), + Z: float32(entity.GetRot().Z), }, EntityId: entity.id, CurHp: entity.fightProp[constant.FIGHT_PROP_CUR_HP], OwnerUid: entity.gadgetEntity.gadgetVehicleEntity.ownerUid, Pos: &proto.Vector{ - X: float32(entity.pos.X), - Y: float32(entity.pos.Y), - Z: float32(entity.pos.Z), + X: float32(entity.GetPos().X), + Y: float32(entity.GetPos().Y), + Z: float32(entity.GetPos().Z), }, UidList: make([]uint32, 0, len(entity.gadgetEntity.gadgetVehicleEntity.memberMap)), GadgetId: entity.gadgetEntity.gadgetVehicleEntity.vehicleId, diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index e7bb2575..b5c74200 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -148,7 +148,7 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr return } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { if world.GetPubg() == nil { return } @@ -183,7 +183,7 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr defAvatarEntity := defEntity.GetAvatarEntity() g.KillPlayerAvatar(player, defAvatarEntity.GetAvatarId(), proto.PlayerDieType_PLAYER_DIE_GM) - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetUid()) if defPlayer == nil { return @@ -223,26 +223,17 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene } if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { // 玩家实体在移动 - g.SceneBlockAoiPlayerMove(player, world, scene, player.Pos, - &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - entity.GetId(), - ) - - if WORLD_MANAGER.IsBigWorld(world) { - g.BigWorldAoiPlayerMove(player, world, scene, player.Pos, - &model.Vector{X: pos.X, Y: pos.Y, Z: pos.Z}, - ) + g.SceneBlockAoiPlayerMove(player, world, scene, player.Pos, pos, entity.GetId()) + if WORLD_MANAGER.IsAiWorld(world) { + g.AiWorldAoiPlayerMove(player, world, scene, player.Pos, pos) } - // 更新玩家的位置信息 player.Pos.X, player.Pos.Y, player.Pos.Z = pos.X, pos.Y, pos.Z player.Rot.X, player.Rot.Y, player.Rot.Z = rot.X, rot.Y, rot.Z } // 更新场景实体的位置信息 - entityPos := entity.GetPos() - entityPos.X, entityPos.Y, entityPos.Z = pos.X, pos.Y, pos.Z - entityRot := entity.GetRot() - entityRot.X, entityRot.Y, entityRot.Z = rot.X, rot.Y, rot.Z + entity.pos.X, entity.pos.Y, entity.pos.Z = pos.X, pos.Y, pos.Z + entity.rot.X, entity.rot.Y, entity.rot.Z = rot.X, rot.Y, rot.Z if !force { motionInfo := moveInfo.MotionInfo switch entity.GetEntityType() { @@ -281,7 +272,7 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene } func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene *Scene, oldPos *model.Vector, newPos *model.Vector, entityId uint32) { - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { return } @@ -355,7 +346,7 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene continue } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { continue } @@ -371,7 +362,7 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene continue } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { continue } @@ -391,16 +382,17 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene g.SceneRegionTriggerCheck(player, oldPos, newPos, entityId) } -func (g *Game) BigWorldAoiPlayerMove(player *model.Player, world *World, scene *Scene, oldPos *model.Vector, newPos *model.Vector) { - bigWorldAoi := world.GetBigWorldAoi() - oldGid := bigWorldAoi.GetGidByPos(float32(oldPos.X), float32(oldPos.Y), float32(oldPos.Z)) - newGid := bigWorldAoi.GetGidByPos(float32(newPos.X), float32(newPos.Y), float32(newPos.Z)) +func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *Scene, oldPos *model.Vector, newPos *model.Vector) { + aiWorldAoi := world.GetAiWorldAoi() + oldGid := aiWorldAoi.GetGidByPos(float32(oldPos.X), float32(oldPos.Y), float32(oldPos.Z)) + newGid := aiWorldAoi.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) + logger.Debug("player cross ai world aoi grid, oldGid: %v, oldPos: %+v, newGid: %v, newPos: %+v, uid: %v", + oldGid, oldPos, newGid, newPos, player.PlayerId) // 找出本次移动所带来的消失和出现的格子 - oldGridList := bigWorldAoi.GetSurrGridListByGid(oldGid) - newGridList := bigWorldAoi.GetSurrGridListByGid(newGid) + oldGridList := aiWorldAoi.GetSurrGridListByGid(oldGid) + newGridList := aiWorldAoi.GetSurrGridListByGid(newGid) delGridIdList := make([]uint32, 0) for _, oldGrid := range oldGridList { exist := false @@ -432,11 +424,11 @@ func (g *Game) BigWorldAoiPlayerMove(player *model.Player, world *World, scene * activeAvatarId := world.GetPlayerActiveAvatarId(player) activeWorldAvatar := world.GetPlayerWorldAvatar(player, activeAvatarId) // 老格子移除玩家 - bigWorldAoi.RemoveObjectFromGrid(int64(player.PlayerId), oldGid) + aiWorldAoi.RemoveObjectFromGrid(int64(player.PlayerId), oldGid) // 处理消失的格子 for _, delGridId := range delGridIdList { // 通知自己 老格子里的其它玩家消失 - oldOtherWorldAvatarMap := bigWorldAoi.GetObjectListByGid(delGridId) + oldOtherWorldAvatarMap := aiWorldAoi.GetObjectListByGid(delGridId) delEntityIdList := make([]uint32, 0) for _, otherWorldAvatarAny := range oldOtherWorldAvatarMap { otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar) @@ -458,7 +450,7 @@ func (g *Game) BigWorldAoiPlayerMove(player *model.Player, world *World, scene * // 处理出现的格子 for _, addGridId := range addGridIdList { // 通知自己 新格子里的其他玩家出现 - newOtherWorldAvatarMap := bigWorldAoi.GetObjectListByGid(addGridId) + newOtherWorldAvatarMap := aiWorldAoi.GetObjectListByGid(addGridId) addEntityIdList := make([]uint32, 0) for _, otherWorldAvatarAny := range newOtherWorldAvatarMap { otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar) @@ -479,11 +471,7 @@ func (g *Game) BigWorldAoiPlayerMove(player *model.Player, world *World, scene * } } // 新格子添加玩家 - bigWorldAoi.AddObjectToGrid(int64(player.PlayerId), activeWorldAvatar, newGid) - // aoi区域玩家数量限制 - if len(bigWorldAoi.GetObjectListByGid(newGid)) > 8 { - g.LogoutPlayer(player.PlayerId) - } + aiWorldAoi.AddObjectToGrid(int64(player.PlayerId), activeWorldAvatar, newGid) } } @@ -717,7 +705,7 @@ func (g *Game) EvtBulletHitNotify(player *model.Player, payloadMsg pb.Message) { scene := world.GetSceneById(player.SceneId) g.SendToSceneA(scene, cmd.EvtBulletHitNotify, player.ClientSeq, req) - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { bulletPhysicsEngine := world.GetBulletPhysicsEngine() if bulletPhysicsEngine.IsRigidBody(req.EntityId) { logger.Debug("[FPS] EvtBulletHitNotify: %+v", req) @@ -766,7 +754,7 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message }, req.EntityId, req.ConfigId, req.CampId, req.CampType, req.OwnerEntityId, req.TargetEntityId, req.PropOwnerEntityId) g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{req.EntityId}, true, true) - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { gadgetDataConfig := gdconf.GetGadgetDataById(int32(req.ConfigId)) if gadgetDataConfig == nil { logger.Error("gadget data config is nil, gadgetId: %v", req.ConfigId) diff --git a/gs/game/player_multiplayer.go b/gs/game/player_multiplayer.go index e1156d09..7dff7fa3 100644 --- a/gs/game/player_multiplayer.go +++ b/gs/game/player_multiplayer.go @@ -387,7 +387,7 @@ func (g *Game) PlayerLeaveWorld(player *model.Player) bool { } func (g *Game) WorldAddPlayer(world *World, player *model.Player) { - if world.GetWorldPlayerNum() >= 4 && !WORLD_MANAGER.IsBigWorld(world) { + if world.GetWorldPlayerNum() >= 4 && !WORLD_MANAGER.IsAiWorld(world) { return } _, exist := world.GetAllPlayer()[player.PlayerId] @@ -443,9 +443,9 @@ func (g *Game) WorldRemovePlayer(world *World, player *model.Player) { world.RemovePlayer(player) - if WORLD_MANAGER.IsBigWorld(world) { - bigWorldAoi := world.GetBigWorldAoi() - bigWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerId), float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) + if WORLD_MANAGER.IsAiWorld(world) { + aiWorldAoi := world.GetAiWorldAoi() + aiWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerId), float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) } player.WorldId = 0 diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 321a6d83..49998938 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -60,7 +60,7 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) { } g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_MISS, delEntityIdList) - if !WORLD_MANAGER.IsBigWorld(world) { + if !WORLD_MANAGER.IsAiWorld(world) { // 卸载旧位置附近的group for _, groupConfig := range g.GetNeighborGroup(ctx.OldSceneId, ctx.OldPos) { if !world.GetMultiplayer() { @@ -309,14 +309,14 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { activeAvatarId := world.GetPlayerActiveAvatarId(player) activeWorldAvatar := world.GetPlayerWorldAvatar(player, activeAvatarId) - if WORLD_MANAGER.IsBigWorld(world) { - bigWorldAoi := world.GetBigWorldAoi() - bigWorldAoi.AddObjectToGridByPos(int64(player.PlayerId), activeWorldAvatar, float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) + if WORLD_MANAGER.IsAiWorld(world) { + aiWorldAoi := world.GetAiWorldAoi() + aiWorldAoi.AddObjectToGridByPos(int64(player.PlayerId), activeWorldAvatar, float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) } g.AddSceneEntityNotify(player, visionType, []uint32{activeWorldAvatar.GetAvatarEntityId()}, true, false) - if !WORLD_MANAGER.IsBigWorld(world) { + if !WORLD_MANAGER.IsAiWorld(world) { // 加载附近的group for _, groupConfig := range g.GetNeighborGroup(scene.GetId(), player.Pos) { g.AddSceneGroup(player, scene, groupConfig) @@ -335,7 +335,7 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { continue } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { continue } @@ -350,9 +350,9 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { g.AddSceneEntityNotify(player, visionType, vehicleEntityIdList, false, false) } - if WORLD_MANAGER.IsBigWorld(world) { - bigWorldAoi := world.GetBigWorldAoi() - otherWorldAvatarMap := bigWorldAoi.GetObjectListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) + if WORLD_MANAGER.IsAiWorld(world) { + aiWorldAoi := world.GetAiWorldAoi() + otherWorldAvatarMap := aiWorldAoi.GetObjectListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) entityIdList := make([]uint32, 0) for _, otherWorldAvatarAny := range otherWorldAvatarMap { otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar) @@ -384,14 +384,6 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { } g.JoinOtherWorld(otherPlayer, player) } - - if WORLD_MANAGER.IsBigWorld(world) { - // aoi区域玩家数量限制 - bigWorldAoi := world.GetBigWorldAoi() - if len(bigWorldAoi.GetObjectListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))) > 8 { - g.LogoutPlayer(player.PlayerId) - } - } } func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) { @@ -639,7 +631,7 @@ func (g *Game) KillPlayerAvatar(player *model.Player, avatarId uint32, dieType p g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf) } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { TICK_MANAGER.CreateUserTimer(player.PlayerId, UserTimerActionPubgDieExit, 10) } } @@ -783,11 +775,11 @@ func (g *Game) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]*Enti ratio := float32(ENTITY_VISION_DISTANCE*ENTITY_VISION_DISTANCE) / float32(GROUP_LOAD_DISTANCE*GROUP_LOAD_DISTANCE) visionEntity := make(map[uint32]*Entity, int(float32(len(allEntityMap))*ratio)) for _, entity := range allEntityMap { - dx := int32(pos.X) - int32(entity.pos.X) + dx := int32(pos.X) - int32(entity.GetPos().X) if dx < 0 { dx *= -1 } - dy := int32(pos.Z) - int32(entity.pos.Z) + dy := int32(pos.Z) - int32(entity.GetPos().Z) if dy < 0 { dy *= -1 } @@ -869,10 +861,10 @@ func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gd return } g.AddSceneGroupSuiteCore(player, scene, uint32(groupConfig.Id), uint8(initSuiteId)) - ntf := &proto.GroupSuiteNotify{ - GroupMap: make(map[uint32]uint32), - } - ntf.GroupMap[uint32(groupConfig.Id)] = uint32(initSuiteId) + // ntf := &proto.GroupSuiteNotify{ + // GroupMap: make(map[uint32]uint32), + // } + // ntf.GroupMap[uint32(groupConfig.Id)] = uint32(initSuiteId) // g.SendMsg(cmd.GroupSuiteNotify, player.PlayerId, player.ClientSeq, ntf) world := scene.GetWorld() @@ -907,10 +899,10 @@ func (g *Game) RemoveSceneGroup(player *model.Player, scene *Scene, groupConfig for suiteId := range group.GetAllSuite() { scene.RemoveGroupSuite(uint32(groupConfig.Id), suiteId) } - ntf := &proto.GroupUnloadNotify{ - GroupList: make([]uint32, 0), - } - ntf.GroupList = append(ntf.GroupList, uint32(groupConfig.Id)) + // ntf := &proto.GroupUnloadNotify{ + // GroupList: make([]uint32, 0), + // } + // ntf.GroupList = append(ntf.GroupList, uint32(groupConfig.Id)) // g.SendMsg(cmd.GroupUnloadNotify, player.PlayerId, player.ClientSeq, ntf) } @@ -932,11 +924,11 @@ func (g *Game) AddSceneGroupSuite(player *model.Player, groupId uint32, suiteId } scene := world.GetSceneById(player.SceneId) g.AddSceneGroupSuiteCore(player, scene, groupId, suiteId) - ntf := &proto.GroupSuiteNotify{ - GroupMap: make(map[uint32]uint32), - } - ntf.GroupMap[uint32(groupConfig.Id)] = uint32(suiteId) - g.SendMsg(cmd.GroupSuiteNotify, player.PlayerId, player.ClientSeq, ntf) + // ntf := &proto.GroupSuiteNotify{ + // GroupMap: make(map[uint32]uint32), + // } + // ntf.GroupMap[uint32(groupConfig.Id)] = uint32(suiteId) + // g.SendMsg(cmd.GroupSuiteNotify, player.PlayerId, player.ClientSeq, ntf) group := scene.GetGroupById(groupId) suite := group.GetSuiteById(suiteId) entityIdList := make([]uint32, 0) diff --git a/gs/game/player_social.go b/gs/game/player_social.go index d51716b9..8e15c9c3 100644 --- a/gs/game/player_social.go +++ b/gs/game/player_social.go @@ -2,6 +2,7 @@ package game import ( "regexp" + "strconv" "time" "unicode/utf8" @@ -372,28 +373,34 @@ func (g *Game) DealAddFriendReq(player *model.Player, payloadMsg pb.Message) { func (g *Game) GetOnlinePlayerListReq(player *model.Player, payloadMsg pb.Message) { count := 0 - getOnlinePlayerListRsp := &proto.GetOnlinePlayerListRsp{ + rsp := &proto.GetOnlinePlayerListRsp{ PlayerInfoList: make([]*proto.OnlinePlayerInfo, 0), } - getOnlinePlayerListRsp.PlayerInfoList = append(getOnlinePlayerListRsp.PlayerInfoList, &proto.OnlinePlayerInfo{ - Uid: BigWorldAiUid, - Nickname: BigWorldAiName, - PlayerLevel: 1, - AvatarId: 10000007, - MpSettingType: proto.MpSettingType_MP_SETTING_ENTER_AFTER_APPLY, - NameCardId: 210001, - Signature: BigWorldAiSign, - ProfilePicture: &proto.ProfilePicture{AvatarId: 10000007}, - CurPlayerNumInWorld: 1, - }) - count++ + // 最先添加全服ai玩家 + aiUidList := USER_MANAGER.GetAllRemoteAiUidList() + aiUidList = append(aiUidList, g.GetAi().PlayerId) + for _, aiUid := range aiUidList { + sign := AiSign + " GS:" + strconv.Itoa(int(aiUid-AiBaseUid)) + rsp.PlayerInfoList = append(rsp.PlayerInfoList, &proto.OnlinePlayerInfo{ + Uid: aiUid, + Nickname: AiName, + PlayerLevel: 1, + AvatarId: 10000007, + MpSettingType: proto.MpSettingType_MP_SETTING_ENTER_AFTER_APPLY, + NameCardId: 210001, + Signature: sign, + ProfilePicture: &proto.ProfilePicture{AvatarId: 10000007}, + CurPlayerNumInWorld: 1, + }) + count++ + } onlinePlayerList := make([]*model.Player, 0) // 优先获取本地的在线玩家 for _, onlinePlayer := range USER_MANAGER.GetAllOnlineUserList() { - if onlinePlayer.PlayerId == player.PlayerId { + if onlinePlayer.PlayerId < PlayerBaseUid || onlinePlayer.PlayerId > MaxPlayerBaseUid { continue } - if g.IsMainGs() && onlinePlayer.PlayerId == g.GetAi().PlayerId { + if onlinePlayer.PlayerId == player.PlayerId { continue } onlinePlayerList = append(onlinePlayerList, onlinePlayer) @@ -418,9 +425,9 @@ func (g *Game) GetOnlinePlayerListReq(player *model.Player, payloadMsg pb.Messag for _, onlinePlayer := range onlinePlayerList { onlinePlayerInfo := g.PacketOnlinePlayerInfo(onlinePlayer) - getOnlinePlayerListRsp.PlayerInfoList = append(getOnlinePlayerListRsp.PlayerInfoList, onlinePlayerInfo) + rsp.PlayerInfoList = append(rsp.PlayerInfoList, onlinePlayerInfo) } - g.SendMsg(cmd.GetOnlinePlayerListRsp, player.PlayerId, player.ClientSeq, getOnlinePlayerListRsp) + g.SendMsg(cmd.GetOnlinePlayerListRsp, player.PlayerId, player.ClientSeq, rsp) } func (g *Game) GetOnlinePlayerInfoReq(player *model.Player, payloadMsg pb.Message) { diff --git a/gs/game/player_stamina.go b/gs/game/player_stamina.go index 1c360d68..9a27aa2a 100644 --- a/gs/game/player_stamina.go +++ b/gs/game/player_stamina.go @@ -335,7 +335,7 @@ func (g *Game) UpdatePlayerStamina(player *model.Player, staminaCost int32) { return } // 大世界不扣除耐力 但可以回复 - if WORLD_MANAGER.IsBigWorld(world) && staminaCost < 0 { + if WORLD_MANAGER.IsAiWorld(world) && staminaCost < 0 { return } // 耐力消耗为0代表不更改 仍然执行后面的话会导致回复出问题 diff --git a/gs/game/player_team.go b/gs/game/player_team.go index 49b49701..f3659410 100644 --- a/gs/game/player_team.go +++ b/gs/game/player_team.go @@ -153,7 +153,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId) return } - if WORLD_MANAGER.IsBigWorld(world) || !world.GetMultiplayer() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 { + if WORLD_MANAGER.IsAiWorld(world) || !world.GetMultiplayer() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 { g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{}) return } @@ -200,7 +200,7 @@ func (g *Game) AvatarDieAnimationEndReq(player *model.Player, payloadMsg pb.Mess } scene := world.GetSceneById(player.SceneId) - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { pubg := world.GetPubg() if pubg != nil { alivePlayerNum := len(pubg.GetAlivePlayerList()) @@ -262,7 +262,7 @@ func (g *Game) WorldPlayerReviveReq(player *model.Player, payloadMsg pb.Message) _ = req world := WORLD_MANAGER.GetWorldById(player.WorldId) - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { GAME.ReLoginPlayer(player.PlayerId, true) return } @@ -339,7 +339,7 @@ func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) * } empty := new(proto.AbilitySyncStateInfo) for _, worldAvatar := range world.GetWorldAvatarList() { - if WORLD_MANAGER.IsBigWorld(world) && worldAvatar.uid != player.PlayerId { + if WORLD_MANAGER.IsAiWorld(world) && worldAvatar.uid != player.PlayerId { continue } diff --git a/gs/game/player_world.go b/gs/game/player_world.go index e949ec35..49eec694 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -40,8 +40,8 @@ func (g *Game) SceneTransToPointReq(player *model.Player, payloadMsg pb.Message) } unlock := dbScene.CheckPointUnlock(req.PointId) if !unlock { - // g.SendError(cmd.SceneTransToPointRsp, player, &proto.SceneTransToPointRsp{}, proto.Retcode_RET_POINT_NOT_UNLOCKED) - // return + g.SendError(cmd.SceneTransToPointRsp, player, &proto.SceneTransToPointRsp{}, proto.Retcode_RET_POINT_NOT_UNLOCKED) + return } pointDataConfig := gdconf.GetScenePointBySceneIdAndPointId(int32(req.SceneId), int32(req.PointId)) if pointDataConfig == nil { @@ -147,7 +147,7 @@ func (g *Game) MarkMapReq(player *model.Player, payloadMsg pb.Message) { return } - if WORLD_MANAGER.IsBigWorld(world) { + if WORLD_MANAGER.IsAiWorld(world) { pubg := world.GetPubg() if pubg != nil { GAME.SendMsg(cmd.MarkMapRsp, player.PlayerId, player.ClientSeq, &proto.MarkMapRsp{MarkList: pubg.GetAreaPointList()}) @@ -473,6 +473,34 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) { g.SendMsg(cmd.GadgetInteractRsp, player.PlayerId, player.ClientSeq, rsp) } +func (g *Game) EnterTransPointRegionNotify(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.EnterTransPointRegionNotify) + _ = req + world := WORLD_MANAGER.GetWorldById(player.WorldId) + if world == nil || WORLD_MANAGER.IsAiWorld(world) { + return + } + dbAvatar := player.GetDbAvatar() + dbTeam := player.GetDbTeam() + activeTeam := dbTeam.GetActiveTeam() + for _, avatarId := range activeTeam.GetAvatarIdList() { + avatar := dbAvatar.AvatarMap[avatarId] + if avatar.LifeState == constant.LIFE_STATE_DEAD { + g.RevivePlayerAvatar(player, avatarId) + } + avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP] = avatar.FightPropMap[constant.FIGHT_PROP_MAX_HP] + g.SendMsg(cmd.AvatarFightPropUpdateNotify, player.PlayerId, player.ClientSeq, &proto.AvatarFightPropUpdateNotify{ + AvatarGuid: avatar.Guid, + FightPropMap: avatar.FightPropMap, + }) + } +} + +func (g *Game) ExitTransPointRegionNotify(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.ExitTransPointRegionNotify) + _ = req +} + /************************************************** 游戏功能 **************************************************/ func (g *Game) monsterDrop(player *model.Player, entity *Entity) { @@ -499,7 +527,7 @@ func (g *Game) monsterDrop(player *model.Player, entity *Entity) { logger.Error("get item data config is nil, itemId: %v, uid: %v", itemId, player.PlayerId) continue } - g.CreateDropGadget(player, entity.pos, uint32(itemDataConfig.GadgetId), itemId, count) + g.CreateDropGadget(player, entity.GetPos(), uint32(itemDataConfig.GadgetId), itemId, count) } } @@ -527,7 +555,7 @@ func (g *Game) chestDrop(player *model.Player, entity *Entity) { logger.Error("get item data config is nil, itemId: %v, uid: %v", itemId, player.PlayerId) continue } - g.CreateDropGadget(player, entity.pos, uint32(itemDataConfig.GadgetId), itemId, count) + g.CreateDropGadget(player, entity.GetPos(), uint32(itemDataConfig.GadgetId), itemId, count) } } @@ -610,8 +638,8 @@ func (g *Game) TeleportPlayer( return } - if WORLD_MANAGER.IsBigWorld(world) && sceneId != 3 { - logger.Error("big world scene not support now, sceneId: %v, uid: %v", sceneId, player.PlayerId) + if WORLD_MANAGER.IsAiWorld(world) && sceneId != 3 { + logger.Error("ai world scene not support now, sceneId: %v, uid: %v", sceneId, player.PlayerId) return } @@ -625,11 +653,12 @@ func (g *Game) TeleportPlayer( player.SceneJump = jumpScene oldScene := world.GetSceneById(oldSceneId) activeAvatarId := world.GetPlayerActiveAvatarId(player) - g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}, false, 0) + avatarEntityId := world.GetPlayerWorldAvatarEntityId(player, activeAvatarId) + g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{avatarEntityId}, false, 0) - if WORLD_MANAGER.IsBigWorld(world) { - bigWorldAoi := world.GetBigWorldAoi() - bigWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerId), float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) + if WORLD_MANAGER.IsAiWorld(world) { + aiWorldAoi := world.GetAiWorldAoi() + aiWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerId), float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) } if jumpScene { diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index 0c374af1..4b51d263 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -150,6 +150,8 @@ func (c *CmdProtoMap) registerMessage() { c.regMsg(WorldChestOpenNotify, func() any { return new(proto.WorldChestOpenNotify) }) // 宝箱开启通知 c.regMsg(EntityForceSyncReq, func() any { return new(proto.EntityForceSyncReq) }) // 场景实体强制同步请求 客户端强制同步 c.regMsg(EntityForceSyncRsp, func() any { return new(proto.EntityForceSyncRsp) }) // 场景实体强制同步响应 + c.regMsg(EnterTransPointRegionNotify, func() any { return new(proto.EnterTransPointRegionNotify) }) // 进入传送点区域通知 七天神像区域 + c.regMsg(ExitTransPointRegionNotify, func() any { return new(proto.ExitTransPointRegionNotify) }) // 离开传送点区域通知 // 战斗与同步 c.regMsg(AvatarFightPropNotify, func() any { return new(proto.AvatarFightPropNotify) }) // 角色战斗属性通知