diff --git a/common/region/region.go b/common/region/region.go index bb6e2bbf..b16a47c4 100644 --- a/common/region/region.go +++ b/common/region/region.go @@ -2,6 +2,8 @@ package region import ( "os" + "regexp" + "strconv" "hk4e/pkg/logger" ) @@ -29,3 +31,34 @@ func LoadRegionRsaKey() (signRsaKey []byte, encRsaKeyMap map[string][]byte, pwdR } return signRsaKey, encRsaKeyMap, pwdRsaKey } + +// GetClientVersionByName 从客户端版本字符串中提取版本号 +func GetClientVersionByName(versionName string) (int, string) { + reg, err := regexp.Compile("[0-9]+") + if err != nil { + logger.Error("compile regexp error: %v", err) + return 0, "" + } + versionSlice := reg.FindAllString(versionName, -1) + version := 0 + for index, value := range versionSlice { + v, err := strconv.Atoi(value) + if err != nil { + logger.Error("parse client version error: %v", err) + return 0, "" + } + if v >= 10 { + // 测试版本 + if index != 2 { + logger.Error("invalid client version") + return 0, "" + } + v /= 10 + } + for i := 0; i < 2-index; i++ { + v *= 10 + } + version += v + } + return version, strconv.Itoa(version) +} diff --git a/dispatch/controller/dispatch_controller.go b/dispatch/controller/dispatch_controller.go index 5f6f2622..d522ae33 100644 --- a/dispatch/controller/dispatch_controller.go +++ b/dispatch/controller/dispatch_controller.go @@ -11,11 +11,10 @@ import ( "net/http" "net/url" "os" - "regexp" - "strconv" "hk4e/common/config" "hk4e/common/mq" + "hk4e/common/region" httpapi "hk4e/dispatch/api" "hk4e/node/api" "hk4e/pkg/endec" @@ -187,7 +186,7 @@ func (c *Controller) queryCurRegion(ctx *gin.Context) { c.dispatchReqErrorRsp(ctx, 2) return } - version, versionStr := c.getClientVersionByName(versionName) + version, versionStr := region.GetClientVersionByName(versionName) if version == 0 { c.dispatchReqErrorRsp(ctx, 2) return @@ -307,37 +306,6 @@ func (c *Controller) queryCurRegion(ctx *gin.Context) { ctx.JSON(http.StatusOK, rsp) } -// 从客户端版本字符串中提取版本号 -func (c *Controller) getClientVersionByName(versionName string) (int, string) { - reg, err := regexp.Compile("[0-9]+") - if err != nil { - logger.Error("compile regexp error: %v", err) - return 0, "" - } - versionSlice := reg.FindAllString(versionName, -1) - version := 0 - for index, value := range versionSlice { - v, err := strconv.Atoi(value) - if err != nil { - logger.Error("parse client version error: %v", err) - return 0, "" - } - if v >= 10 { - // 测试版本 - if index != 2 { - logger.Error("invalid client version") - return 0, "" - } - v /= 10 - } - for i := 0; i < 2-index; i++ { - v *= 10 - } - version += v - } - return version, strconv.Itoa(version) -} - func (c *Controller) querySecurityFile(ctx *gin.Context) { // 很早以前2.6.0版本的时候抓包为了完美还原写的 不清楚有没有副作用暂时不要了 return diff --git a/gs/game/audio_video.go b/gs/game/audio_video.go index 64a7d1a0..e004bd62 100644 --- a/gs/game/audio_video.go +++ b/gs/game/audio_video.go @@ -306,7 +306,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, false, 0) + GAME.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_REMOVE, SCREEN_ENTITY_ID_LIST) SCREEN_ENTITY_ID_LIST = make([]uint32, 0) leftTopPos := &model.Vector{ X: BASE_POS.X + float64(SCREEN_WIDTH)*SCREEN_DPI/2, diff --git a/gs/game/game.go b/gs/game/game.go index 34ebd6a5..d5dcbb97 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -110,7 +110,7 @@ func (g *Game) GetAi() *model.Player { } func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player { - g.OnLogin(uid, 0, "", nil, 0, true) + g.OnLogin(uid, 0, "", nil, new(proto.PlayerLoginReq), true) robot := USER_MANAGER.GetOnlineUser(uid) robot.DbState = model.DbNormal g.SetPlayerBornDataReq(robot, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: name}) @@ -395,14 +395,7 @@ func (g *Game) SendSucc(cmdId uint16, player *model.Player, rsp pb.Message) { } // SendToWorldA 给世界内所有玩家发消息 -func (g *Game) SendToWorldA(world *World, cmdId uint16, seq uint32, msg pb.Message) { - for _, v := range world.GetAllPlayer() { - g.SendMsg(cmdId, v.PlayerId, seq, msg) - } -} - -// SendToWorldAEC 给世界内除某玩家(一般是自己)以外的所有玩家发消息 -func (g *Game) SendToWorldAEC(world *World, cmdId uint16, seq uint32, msg pb.Message, aecUid uint32) { +func (g *Game) SendToWorldA(world *World, cmdId uint16, seq uint32, msg pb.Message, aecUid uint32) { for _, v := range world.GetAllPlayer() { if aecUid == v.PlayerId { continue @@ -417,23 +410,7 @@ 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.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) - } - } else { - for _, v := range scene.GetAllPlayer() { - g.SendMsg(cmdId, v.PlayerId, seq, msg) - } - } -} - -// SendToSceneAEC 给场景内除某玩家(一般是自己)以外的所有玩家发消息 -func (g *Game) SendToSceneAEC(scene *Scene, cmdId uint16, seq uint32, msg pb.Message, aecUid uint32) { +func (g *Game) SendToSceneA(scene *Scene, cmdId uint16, seq uint32, msg pb.Message, aecUid uint32) { world := scene.GetWorld() if WORLD_MANAGER.IsAiWorld(world) && SELF != nil { aiWorldAoi := world.GetAiWorldAoi() @@ -454,6 +431,35 @@ func (g *Game) SendToSceneAEC(scene *Scene, cmdId uint16, seq uint32, msg pb.Mes } } +// SendToSceneACV 给场景内所有指定客户端版本的玩家发消息 +func (g *Game) SendToSceneACV(scene *Scene, cmdId uint16, seq uint32, msg pb.Message, aecUid uint32, clientVersion int) { + world := scene.GetWorld() + 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 { + player := USER_MANAGER.GetOnlineUser(uint32(uid)) + if aecUid == player.PlayerId { + continue + } + if player.ClientVersion != clientVersion { + continue + } + g.SendMsg(cmdId, uint32(uid), seq, msg) + } + } else { + for _, v := range scene.GetAllPlayer() { + if aecUid == v.PlayerId { + continue + } + if v.ClientVersion != clientVersion { + continue + } + g.SendMsg(cmdId, v.PlayerId, seq, msg) + } + } +} + func (g *Game) ReLoginPlayer(userId uint32, isQuitMp bool) { reason := proto.ClientReconnectReason_CLIENT_RECONNNECT_NONE if isQuitMp { diff --git a/gs/game/game_local_event_manager.go b/gs/game/game_local_event_manager.go index 96273e25..6f13caa7 100644 --- a/gs/game/game_local_event_manager.go +++ b/gs/game/game_local_event_manager.go @@ -65,7 +65,7 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) { switch localEvent.EventId { case LoadLoginUserFromDbFinish: playerLoginInfo := localEvent.Msg.(*PlayerLoginInfo) - GAME.OnLogin(playerLoginInfo.UserId, playerLoginInfo.ClientSeq, playerLoginInfo.GateAppId, playerLoginInfo.Player, playerLoginInfo.JoinHostUserId, playerLoginInfo.Ok) + GAME.OnLogin(playerLoginInfo.UserId, playerLoginInfo.ClientSeq, playerLoginInfo.GateAppId, playerLoginInfo.Player, playerLoginInfo.Req, playerLoginInfo.Ok) case ExitRunUserCopyAndSave: fallthrough case RunUserCopyAndSave: diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index 5d7eafcf..0c9f5b9d 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -361,7 +361,7 @@ func (t *TickManager) onTick100MilliSecond(now int64) { ForwardType: proto.ForwardType_FORWARD_TO_ALL, ArgumentType: proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT, }}, - }) + }, 0) } } @@ -376,6 +376,6 @@ func (t *TickManager) onTick50MilliSecond(now int64) { Param1: []uint32{1, <-AUDIO_CHAN}, Param2: nil, Param3: nil, - }) + }, 0) } } diff --git a/gs/game/game_user_manager.go b/gs/game/game_user_manager.go index 31b04eb1..d7d68f3c 100644 --- a/gs/game/game_user_manager.go +++ b/gs/game/game_user_manager.go @@ -8,6 +8,7 @@ import ( "hk4e/gs/dao" "hk4e/gs/model" "hk4e/pkg/logger" + "hk4e/protocol/proto" "github.com/vmihailenco/msgpack/v5" ) @@ -90,16 +91,16 @@ func (u *UserManager) DeleteUser(userId uint32) { } type PlayerLoginInfo struct { - UserId uint32 - Player *model.Player - ClientSeq uint32 - GateAppId string - JoinHostUserId uint32 - Ok bool + UserId uint32 + Player *model.Player + ClientSeq uint32 + GateAppId string + Req *proto.PlayerLoginReq + Ok bool } // OnlineUser 玩家上线 -func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32, gateAppId string, joinHostUserId uint32) { +func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32, gateAppId string, req *proto.PlayerLoginReq) { _, exist := u.playerMap[userId] // 正常登录 if exist { @@ -148,12 +149,12 @@ func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32, gateAppId stri LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{ EventId: LoadLoginUserFromDbFinish, Msg: &PlayerLoginInfo{ - UserId: userId, - Player: player, - ClientSeq: clientSeq, - GateAppId: gateAppId, - JoinHostUserId: joinHostUserId, - Ok: true, + UserId: userId, + Player: player, + ClientSeq: clientSeq, + GateAppId: gateAppId, + Req: req, + Ok: true, }, } // 解离线玩家数据分布式锁 diff --git a/gs/game/player_avatar.go b/gs/game/player_avatar.go index f2e9fbcc..dedd4592 100644 --- a/gs/game/player_avatar.go +++ b/gs/game/player_avatar.go @@ -274,17 +274,17 @@ func (g *Game) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.Message // 设置角色风之翼 avatar.FlyCloak = req.FlycloakId - avatarFlycloakChangeNotify := &proto.AvatarFlycloakChangeNotify{ + ntf := &proto.AvatarFlycloakChangeNotify{ AvatarGuid: req.AvatarGuid, FlycloakId: req.FlycloakId, } - g.SendToSceneA(scene, cmd.AvatarFlycloakChangeNotify, player.ClientSeq, avatarFlycloakChangeNotify) + g.SendToSceneA(scene, cmd.AvatarFlycloakChangeNotify, player.ClientSeq, ntf, 0) - avatarWearFlycloakRsp := &proto.AvatarWearFlycloakRsp{ + rsp := &proto.AvatarWearFlycloakRsp{ AvatarGuid: req.AvatarGuid, FlycloakId: req.FlycloakId, } - g.SendMsg(cmd.AvatarWearFlycloakRsp, player.PlayerId, player.ClientSeq, avatarWearFlycloakRsp) + g.SendMsg(cmd.AvatarWearFlycloakRsp, player.PlayerId, player.ClientSeq, rsp) } // AvatarChangeCostumeReq 角色更换时装请求 @@ -327,24 +327,24 @@ func (g *Game) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb.Messag avatar.Costume = req.CostumeId // 角色更换时装通知 - avatarChangeCostumeNotify := new(proto.AvatarChangeCostumeNotify) + ntf := new(proto.AvatarChangeCostumeNotify) // 要更换时装的角色实体不存在代表更换的是仓库内的角色 if scene.GetWorld().GetPlayerWorldAvatarEntityId(player, avatar.AvatarId) == 0 { - avatarChangeCostumeNotify.EntityInfo = &proto.SceneEntityInfo{ + ntf.EntityInfo = &proto.SceneEntityInfo{ Entity: &proto.SceneEntityInfo_Avatar{ Avatar: g.PacketSceneAvatarInfo(scene, player, avatar.AvatarId), }, } } else { - avatarChangeCostumeNotify.EntityInfo = g.PacketSceneEntityInfoAvatar(scene, player, avatar.AvatarId) + ntf.EntityInfo = g.PacketSceneEntityInfoAvatar(scene, player, avatar.AvatarId) } - g.SendToSceneA(scene, cmd.AvatarChangeCostumeNotify, player.ClientSeq, avatarChangeCostumeNotify) + g.SendToSceneA(scene, cmd.AvatarChangeCostumeNotify, player.ClientSeq, ntf, 0) - avatarChangeCostumeRsp := &proto.AvatarChangeCostumeRsp{ + rsp := &proto.AvatarChangeCostumeRsp{ AvatarGuid: req.AvatarGuid, CostumeId: req.CostumeId, } - g.SendMsg(cmd.AvatarChangeCostumeRsp, player.PlayerId, player.ClientSeq, avatarChangeCostumeRsp) + g.SendMsg(cmd.AvatarChangeCostumeRsp, player.PlayerId, player.ClientSeq, rsp) } /************************************************** 游戏功能 **************************************************/ diff --git a/gs/game/player_chat.go b/gs/game/player_chat.go index cc7d6edf..63a748a7 100644 --- a/gs/game/player_chat.go +++ b/gs/game/player_chat.go @@ -169,11 +169,11 @@ func (g *Game) PlayerChatReq(player *model.Player, payloadMsg pb.Message) { } world.AddChat(sendChatInfo) - playerChatNotify := &proto.PlayerChatNotify{ + ntf := &proto.PlayerChatNotify{ ChannelId: channelId, ChatInfo: sendChatInfo, } - g.SendToWorldA(world, cmd.PlayerChatNotify, player.ClientSeq, playerChatNotify) + g.SendToWorldA(world, cmd.PlayerChatNotify, player.ClientSeq, ntf, 0) g.SendMsg(cmd.PlayerChatRsp, player.PlayerId, player.ClientSeq, new(proto.PlayerChatRsp)) } diff --git a/gs/game/player_common.go b/gs/game/player_common.go index 7ad0db4a..a582dba8 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -124,19 +124,19 @@ func (g *Game) ObstacleModifyNotify(player *model.Player, payloadMsg pb.Message) // WorldPlayerRTTNotify 世界里所有玩家的网络延迟广播 func (g *Game) WorldPlayerRTTNotify(world *World) { - worldPlayerRTTNotify := &proto.WorldPlayerRTTNotify{ + ntf := &proto.WorldPlayerRTTNotify{ PlayerRttList: make([]*proto.PlayerRTTInfo, 0), } for _, worldPlayer := range world.GetAllPlayer() { playerRTTInfo := &proto.PlayerRTTInfo{Uid: worldPlayer.PlayerId, Rtt: worldPlayer.ClientRTT} - worldPlayerRTTNotify.PlayerRttList = append(worldPlayerRTTNotify.PlayerRttList, playerRTTInfo) + ntf.PlayerRttList = append(ntf.PlayerRttList, playerRTTInfo) } - g.SendToWorldA(world, cmd.WorldPlayerRTTNotify, 0, worldPlayerRTTNotify) + g.SendToWorldA(world, cmd.WorldPlayerRTTNotify, 0, ntf, 0) } // WorldPlayerLocationNotify 多人世界其他玩家的坐标位置广播 func (g *Game) WorldPlayerLocationNotify(world *World) { - worldPlayerLocationNotify := &proto.WorldPlayerLocationNotify{ + ntf := &proto.WorldPlayerLocationNotify{ PlayerWorldLocList: make([]*proto.PlayerWorldLocationInfo, 0), } for _, worldPlayer := range world.GetAllPlayer() { @@ -162,14 +162,14 @@ func (g *Game) WorldPlayerLocationNotify(world *World) { playerWorldLocationInfo.PlayerLoc.Rot = new(proto.Vector) } - worldPlayerLocationNotify.PlayerWorldLocList = append(worldPlayerLocationNotify.PlayerWorldLocList, playerWorldLocationInfo) + ntf.PlayerWorldLocList = append(ntf.PlayerWorldLocList, playerWorldLocationInfo) } - g.SendToWorldA(world, cmd.WorldPlayerLocationNotify, 0, worldPlayerLocationNotify) + g.SendToWorldA(world, cmd.WorldPlayerLocationNotify, 0, ntf, 0) } func (g *Game) ScenePlayerLocationNotify(world *World) { for _, scene := range world.GetAllScene() { - scenePlayerLocationNotify := &proto.ScenePlayerLocationNotify{ + ntf := &proto.ScenePlayerLocationNotify{ SceneId: scene.id, PlayerLocList: make([]*proto.PlayerLocationInfo, 0), VehicleLocList: make([]*proto.VehicleLocationInfo, 0), @@ -195,7 +195,7 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { playerLocationInfo.Rot = new(proto.Vector) } - scenePlayerLocationNotify.PlayerLocList = append(scenePlayerLocationNotify.PlayerLocList, playerLocationInfo) + ntf.PlayerLocList = append(ntf.PlayerLocList, playerLocationInfo) // 载具位置 for _, entityId := range scenePlayer.VehicleInfo.CreateEntityIdMap { entity := scene.GetEntity(entityId) @@ -222,11 +222,11 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { for _, p := range entity.gadgetEntity.gadgetVehicleEntity.memberMap { vehicleLocationInfo.UidList = append(vehicleLocationInfo.UidList, p.PlayerId) } - scenePlayerLocationNotify.VehicleLocList = append(scenePlayerLocationNotify.VehicleLocList, vehicleLocationInfo) + ntf.VehicleLocList = append(ntf.VehicleLocList, vehicleLocationInfo) } } } - g.SendToSceneA(scene, cmd.ScenePlayerLocationNotify, 0, scenePlayerLocationNotify) + g.SendToSceneA(scene, cmd.ScenePlayerLocationNotify, 0, ntf, 0) } } diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index 75072cc3..699b2e59 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -38,13 +38,28 @@ func DoForward[IET model.InvokeEntryType](player *model.Player, invokeHandler *m if invokeHandler.AllLen() == 0 && invokeHandler.AllExceptCurLen() == 0 && invokeHandler.HostLen() == 0 { return } + if WORLD_MANAGER.IsAiWorld(world) && cmdId != cmd.CombatInvocationsNotify { + if invokeHandler.AllLen() > 0 { + reflection.SetStructFieldValue(newNtf, forwardField, invokeHandler.EntryListForwardAll) + GAME.SendToSceneACV(scene, cmdId, player.ClientSeq, newNtf, 0, player.ClientVersion) + } + if invokeHandler.AllExceptCurLen() > 0 { + reflection.SetStructFieldValue(newNtf, forwardField, invokeHandler.EntryListForwardAllExceptCur) + GAME.SendToSceneACV(scene, cmdId, player.ClientSeq, newNtf, player.PlayerId, player.ClientVersion) + } + if invokeHandler.HostLen() > 0 { + reflection.SetStructFieldValue(newNtf, forwardField, invokeHandler.EntryListForwardHost) + GAME.SendToWorldH(world, cmdId, player.ClientSeq, newNtf) + } + return + } if invokeHandler.AllLen() > 0 { reflection.SetStructFieldValue(newNtf, forwardField, invokeHandler.EntryListForwardAll) - GAME.SendToSceneA(scene, cmdId, player.ClientSeq, newNtf) + GAME.SendToSceneA(scene, cmdId, player.ClientSeq, newNtf, 0) } if invokeHandler.AllExceptCurLen() > 0 { reflection.SetStructFieldValue(newNtf, forwardField, invokeHandler.EntryListForwardAllExceptCur) - GAME.SendToSceneAEC(scene, cmdId, player.ClientSeq, newNtf, player.PlayerId) + GAME.SendToSceneA(scene, cmdId, player.ClientSeq, newNtf, player.PlayerId) } if invokeHandler.HostLen() > 0 { reflection.SetStructFieldValue(newNtf, forwardField, invokeHandler.EntryListForwardHost) @@ -53,8 +68,8 @@ func DoForward[IET model.InvokeEntryType](player *model.Player, invokeHandler *m } func (g *Game) UnionCmdNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.UnionCmdNotify) - _ = req + ntf := payloadMsg.(*proto.UnionCmdNotify) + _ = ntf if player.SceneLoadState != model.SceneEnterDone { return } @@ -69,7 +84,7 @@ func (g *Game) UnionCmdNotify(player *model.Player, payloadMsg pb.Message) { } func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.CombatInvocationsNotify) + ntf := payloadMsg.(*proto.CombatInvocationsNotify) if player.SceneLoadState != model.SceneEnterDone { return } @@ -78,7 +93,7 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa return } scene := world.GetSceneById(player.SceneId) - for _, entry := range req.InvokeList { + for _, entry := range ntf.InvokeList { switch entry.ArgumentType { case proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT: evtBeingHitInfo := new(proto.EvtBeingHitInfo) @@ -499,11 +514,11 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S } func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.AbilityInvocationsNotify) + ntf := payloadMsg.(*proto.AbilityInvocationsNotify) if player.SceneLoadState != model.SceneEnterDone { return } - for _, entry := range req.Invokes { + for _, entry := range ntf.Invokes { player.AbilityInvokeHandler.AddEntry(entry.ForwardType, entry) switch entry.ArgumentType { case proto.AbilityInvokeArgument_ABILITY_META_MODIFIER_CHANGE: @@ -540,38 +555,38 @@ func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Mess } func (g *Game) ClientAbilityInitFinishNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.ClientAbilityInitFinishNotify) + ntf := payloadMsg.(*proto.ClientAbilityInitFinishNotify) if player.SceneLoadState != model.SceneEnterDone { return } invokeHandler := model.NewInvokeHandler[proto.AbilityInvokeEntry]() - for _, entry := range req.Invokes { + for _, entry := range ntf.Invokes { // logger.Debug("ClientAbilityInitFinishNotify: %+v", entry) invokeHandler.AddEntry(entry.ForwardType, entry) } DoForward[proto.AbilityInvokeEntry](player, invokeHandler, cmd.ClientAbilityInitFinishNotify, new(proto.ClientAbilityInitFinishNotify), "Invokes", - req, []string{"EntityId"}) + ntf, []string{"EntityId"}) } func (g *Game) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.ClientAbilityChangeNotify) + ntf := payloadMsg.(*proto.ClientAbilityChangeNotify) if player.SceneLoadState != model.SceneEnterDone { return } invokeHandler := model.NewInvokeHandler[proto.AbilityInvokeEntry]() - for _, entry := range req.Invokes { + for _, entry := range ntf.Invokes { // logger.Debug("ClientAbilityChangeNotify: %+v", entry) invokeHandler.AddEntry(entry.ForwardType, entry) } DoForward[proto.AbilityInvokeEntry](player, invokeHandler, cmd.ClientAbilityChangeNotify, new(proto.ClientAbilityChangeNotify), "Invokes", - req, []string{"IsInitHash", "EntityId"}) + ntf, []string{"IsInitHash", "EntityId"}) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } - for _, abilityInvokeEntry := range req.Invokes { + for _, abilityInvokeEntry := range ntf.Invokes { switch abilityInvokeEntry.ArgumentType { case proto.AbilityInvokeArgument_ABILITY_META_ADD_NEW_ABILITY: abilityMetaAddAbility := new(proto.AbilityMetaAddAbility) @@ -620,7 +635,7 @@ func (g *Game) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Mes } func (g *Game) MassiveEntityElementOpBatchNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.MassiveEntityElementOpBatchNotify) + ntf := payloadMsg.(*proto.MassiveEntityElementOpBatchNotify) if player.SceneLoadState != model.SceneEnterDone { return } @@ -629,158 +644,158 @@ func (g *Game) MassiveEntityElementOpBatchNotify(player *model.Player, payloadMs return } scene := world.GetSceneById(player.SceneId) - req.OpIdx = scene.GetMeeoIndex() + ntf.OpIdx = scene.GetMeeoIndex() scene.SetMeeoIndex(scene.GetMeeoIndex() + 1) - g.SendToSceneA(scene, cmd.MassiveEntityElementOpBatchNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.MassiveEntityElementOpBatchNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtDoSkillSuccNotify) + ntf := payloadMsg.(*proto.EvtDoSkillSuccNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtDoSkillSuccNotify: %+v", req) + // logger.Debug("EvtDoSkillSuccNotify: %+v", ntf) // 处理技能开始的耐力消耗 - g.SkillStartStamina(player, req.CasterId, req.SkillId) - g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_SKILL, "", int32(req.SkillId)) + g.SkillStartStamina(player, ntf.CasterId, ntf.SkillId) + g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_SKILL, "", int32(ntf.SkillId)) } func (g *Game) EvtAvatarEnterFocusNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtAvatarEnterFocusNotify) + ntf := payloadMsg.(*proto.EvtAvatarEnterFocusNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAvatarEnterFocusNotify: %+v", req) + // logger.Debug("EvtAvatarEnterFocusNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtAvatarEnterFocusNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtAvatarEnterFocusNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtAvatarUpdateFocusNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtAvatarUpdateFocusNotify) + ntf := payloadMsg.(*proto.EvtAvatarUpdateFocusNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAvatarUpdateFocusNotify: %+v", req) + // logger.Debug("EvtAvatarUpdateFocusNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtAvatarUpdateFocusNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtAvatarUpdateFocusNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtAvatarExitFocusNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtAvatarExitFocusNotify) + ntf := payloadMsg.(*proto.EvtAvatarExitFocusNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAvatarExitFocusNotify: %+v", req) + // logger.Debug("EvtAvatarExitFocusNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtAvatarExitFocusNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtAvatarExitFocusNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtEntityRenderersChangedNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtEntityRenderersChangedNotify) + ntf := payloadMsg.(*proto.EvtEntityRenderersChangedNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtEntityRenderersChangedNotify: %+v", req) + // logger.Debug("EvtEntityRenderersChangedNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtEntityRenderersChangedNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtEntityRenderersChangedNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtBulletDeactiveNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtBulletDeactiveNotify) + ntf := payloadMsg.(*proto.EvtBulletDeactiveNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtBulletDeactiveNotify: %+v", req) + // logger.Debug("EvtBulletDeactiveNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtBulletDeactiveNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtBulletDeactiveNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtBulletHitNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtBulletHitNotify) + ntf := payloadMsg.(*proto.EvtBulletHitNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtBulletHitNotify: %+v", req) + // logger.Debug("EvtBulletHitNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtBulletHitNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtBulletHitNotify, player.ClientSeq, ntf, 0) if WORLD_MANAGER.IsAiWorld(world) { bulletPhysicsEngine := world.GetBulletPhysicsEngine() - if bulletPhysicsEngine.IsRigidBody(req.EntityId) { - logger.Debug("[FPS] EvtBulletHitNotify: %+v", req) - bulletPhysicsEngine.DestroyRigidBody(req.EntityId) - _ = req.HitPoint + if bulletPhysicsEngine.IsRigidBody(ntf.EntityId) { + logger.Debug("[FPS] EvtBulletHitNotify: %+v", ntf) + bulletPhysicsEngine.DestroyRigidBody(ntf.EntityId) + _ = ntf.HitPoint } } } func (g *Game) EvtBulletMoveNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtBulletMoveNotify) + ntf := payloadMsg.(*proto.EvtBulletMoveNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtBulletMoveNotify: %+v", req) + // logger.Debug("EvtBulletMoveNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtBulletMoveNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtBulletMoveNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtCreateGadgetNotify) + ntf := payloadMsg.(*proto.EvtCreateGadgetNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtCreateGadgetNotify: %+v", req) + // logger.Debug("EvtCreateGadgetNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - if req.InitPos == nil { + if ntf.InitPos == nil { return } scene.CreateEntityGadgetClient(&model.Vector{ - X: float64(req.InitPos.X), - Y: float64(req.InitPos.Y), - Z: float64(req.InitPos.Z), + X: float64(ntf.InitPos.X), + Y: float64(ntf.InitPos.Y), + Z: float64(ntf.InitPos.Z), }, &model.Vector{ - X: float64(req.InitEulerAngles.X), - Y: float64(req.InitEulerAngles.Y), - Z: float64(req.InitEulerAngles.Z), - }, 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) + X: float64(ntf.InitEulerAngles.X), + Y: float64(ntf.InitEulerAngles.Y), + Z: float64(ntf.InitEulerAngles.Z), + }, ntf.EntityId, ntf.ConfigId, ntf.CampId, ntf.CampType, ntf.OwnerEntityId, ntf.TargetEntityId, ntf.PropOwnerEntityId) + g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{ntf.EntityId}, true, true) if WORLD_MANAGER.IsAiWorld(world) { - gadgetDataConfig := gdconf.GetGadgetDataById(int32(req.ConfigId)) + gadgetDataConfig := gdconf.GetGadgetDataById(int32(ntf.ConfigId)) if gadgetDataConfig == nil { - logger.Error("gadget data config is nil, gadgetId: %v", req.ConfigId) + logger.Error("gadget data config is nil, gadgetId: %v", ntf.ConfigId) return } // 蓄力箭 @@ -788,8 +803,8 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_Venti_ArrowAiming" { return } - logger.Debug("[FPS] EvtCreateGadgetNotify: %+v", req) - pitchAngleRaw := req.InitEulerAngles.X + logger.Debug("[FPS] EvtCreateGadgetNotify: %+v", ntf) + pitchAngleRaw := ntf.InitEulerAngles.X pitchAngle := float32(0.0) if pitchAngleRaw < 90.0 { pitchAngle = -pitchAngleRaw @@ -799,83 +814,83 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message logger.Error("invalid raw pitch angle: %v, uid: %v", pitchAngleRaw, player.PlayerId) return } - yawAngle := req.InitEulerAngles.Y + yawAngle := ntf.InitEulerAngles.Y bulletPhysicsEngine := world.GetBulletPhysicsEngine() activeAvatarId := world.GetPlayerActiveAvatarId(player) bulletPhysicsEngine.CreateRigidBody( - req.EntityId, + ntf.EntityId, world.GetPlayerWorldAvatarEntityId(player, activeAvatarId), player.SceneId, - req.InitPos.X, req.InitPos.Y, req.InitPos.Z, + ntf.InitPos.X, ntf.InitPos.Y, ntf.InitPos.Z, pitchAngle, yawAngle, ) } } func (g *Game) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtDestroyGadgetNotify) + ntf := payloadMsg.(*proto.EvtDestroyGadgetNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtDestroyGadgetNotify: %+v", req) + // logger.Debug("EvtDestroyGadgetNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - scene.DestroyEntity(req.EntityId) - g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{req.EntityId}, false, 0) + scene.DestroyEntity(ntf.EntityId) + g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{ntf.EntityId}) } func (g *Game) EvtAiSyncSkillCdNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtAiSyncSkillCdNotify) + ntf := payloadMsg.(*proto.EvtAiSyncSkillCdNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAiSyncSkillCdNotify: %+v", req) + // logger.Debug("EvtAiSyncSkillCdNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtAiSyncSkillCdNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtAiSyncSkillCdNotify, player.ClientSeq, ntf, 0) } func (g *Game) EvtAiSyncCombatThreatInfoNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EvtAiSyncCombatThreatInfoNotify) + ntf := payloadMsg.(*proto.EvtAiSyncCombatThreatInfoNotify) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAiSyncCombatThreatInfoNotify: %+v", req) + // logger.Debug("EvtAiSyncCombatThreatInfoNotify: %+v", ntf) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } scene := world.GetSceneById(player.SceneId) - g.SendToSceneA(scene, cmd.EvtAiSyncCombatThreatInfoNotify, player.ClientSeq, req) + g.SendToSceneA(scene, cmd.EvtAiSyncCombatThreatInfoNotify, player.ClientSeq, ntf, 0) } func (g *Game) EntityConfigHashNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EntityConfigHashNotify) - _ = req + ntf := payloadMsg.(*proto.EntityConfigHashNotify) + _ = ntf } func (g *Game) MonsterAIConfigHashNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.MonsterAIConfigHashNotify) - _ = req + ntf := payloadMsg.(*proto.MonsterAIConfigHashNotify) + _ = ntf } func (g *Game) SetEntityClientDataNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.SetEntityClientDataNotify) - g.SendMsg(cmd.SetEntityClientDataNotify, player.PlayerId, player.ClientSeq, req) + ntf := payloadMsg.(*proto.SetEntityClientDataNotify) + g.SendMsg(cmd.SetEntityClientDataNotify, player.PlayerId, player.ClientSeq, ntf) } func (g *Game) EntityAiSyncNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EntityAiSyncNotify) + ntf := payloadMsg.(*proto.EntityAiSyncNotify) entityAiSyncNotify := &proto.EntityAiSyncNotify{ InfoList: make([]*proto.AiSyncInfo, 0), } - for _, monsterId := range req.LocalAvatarAlertedMonsterList { + for _, monsterId := range ntf.LocalAvatarAlertedMonsterList { entityAiSyncNotify.InfoList = append(entityAiSyncNotify.InfoList, &proto.AiSyncInfo{ EntityId: monsterId, HasPathToTarget: true, diff --git a/gs/game/player_login.go b/gs/game/player_login.go index 52b601ee..0ec4a0ff 100644 --- a/gs/game/player_login.go +++ b/gs/game/player_login.go @@ -6,6 +6,7 @@ import ( "hk4e/common/constant" "hk4e/common/mq" + "hk4e/common/region" "hk4e/gdconf" "hk4e/gs/model" "hk4e/pkg/logger" @@ -19,7 +20,7 @@ func (g *Game) PlayerLoginReq(userId uint32, clientSeq uint32, gateAppId string, logger.Info("player login req, uid: %v, gateAppId: %v", userId, gateAppId) req := payloadMsg.(*proto.PlayerLoginReq) logger.Debug("login data: %v", req) - USER_MANAGER.OnlineUser(userId, clientSeq, gateAppId, req.TargetUid) + USER_MANAGER.OnlineUser(userId, clientSeq, gateAppId, req) } func (g *Game) SetPlayerBornDataReq(player *model.Player, payloadMsg pb.Message) { @@ -75,7 +76,7 @@ func (g *Game) SetPlayerBornDataReq(player *model.Player, payloadMsg pb.Message) g.SendMsg(cmd.SetPlayerBornDataRsp, player.PlayerId, player.ClientSeq, new(proto.SetPlayerBornDataRsp)) } -func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player *model.Player, joinHostUserId uint32, ok bool) { +func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player *model.Player, req *proto.PlayerLoginReq, ok bool) { if !ok { g.SendMsgToGate(cmd.PlayerLoginRsp, userId, clientSeq, gateAppId, &proto.PlayerLoginRsp{Retcode: int32(proto.Retcode_RET_LOGIN_INIT_FAIL)}) return @@ -111,12 +112,12 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player if player.IsBorn { g.LoginNotify(userId, clientSeq, player) - if joinHostUserId != 0 { - hostPlayer := USER_MANAGER.GetOnlineUser(joinHostUserId) + if req.TargetUid != 0 { + hostPlayer := USER_MANAGER.GetOnlineUser(req.TargetUid) if hostPlayer != nil { g.JoinOtherWorld(player, hostPlayer) } else { - logger.Error("player is nil, uid: %v", joinHostUserId) + logger.Error("player is nil, uid: %v", req.TargetUid) } } else { // 创建世界 @@ -133,6 +134,9 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player g.SendMsg(cmd.DoSetPlayerBornDataNotify, userId, clientSeq, new(proto.DoSetPlayerBornDataNotify)) } + clientVersion, _ := region.GetClientVersionByName(req.ChecksumClientVersion) + player.ClientVersion = clientVersion + playerLoginRsp := &proto.PlayerLoginRsp{ IsUseAbilityHash: true, AbilityHashCode: 0, diff --git a/gs/game/player_multiplayer.go b/gs/game/player_multiplayer.go index 7dff7fa3..025bbd6a 100644 --- a/gs/game/player_multiplayer.go +++ b/gs/game/player_multiplayer.go @@ -438,7 +438,7 @@ func (g *Game) WorldRemovePlayer(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)}, false, 0) + g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}) } world.RemovePlayer(player) diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index f7e940e3..45e1b94e 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -121,7 +121,7 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) { SceneId: player.SceneId, Uid: player.PlayerId, } - g.SendToWorldAEC(world, cmd.GuestBeginEnterSceneNotify, 0, guestBeginEnterSceneNotify, player.PlayerId) + g.SendToWorldA(world, cmd.GuestBeginEnterSceneNotify, 0, guestBeginEnterSceneNotify, player.PlayerId) } serverTimeNotify := &proto.ServerTimeNotify{ @@ -403,7 +403,7 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) { SceneId: player.SceneId, Uid: player.PlayerId, } - g.SendToWorldAEC(world, cmd.GuestPostEnterSceneNotify, 0, guestPostEnterSceneNotify, player.PlayerId) + g.SendToWorldA(world, cmd.GuestPostEnterSceneNotify, 0, guestPostEnterSceneNotify, player.PlayerId) } world.PlayerEnter(player.PlayerId) @@ -483,19 +483,15 @@ func (g *Game) AddSceneEntityNotifyToPlayer(player *model.Player, visionType pro } // AddSceneEntityNotifyBroadcast 添加的场景实体广播 -func (g *Game) AddSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityList []*proto.SceneEntityInfo, aec bool, aecUid uint32) { +func (g *Game) AddSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityList []*proto.SceneEntityInfo, aecUid uint32) { ntf := &proto.SceneEntityAppearNotify{ AppearType: visionType, EntityList: entityList, } world := scene.GetWorld() owner := world.GetOwner() - // logger.Debug("[SceneEntityAppearNotify BC], type: %v, len: %v, uid: %v, aec: %v", ntf.AppearType, len(ntf.EntityList), owner.PlayerId, aec) - if aec { - g.SendToSceneAEC(scene, cmd.SceneEntityAppearNotify, owner.ClientSeq, ntf, aecUid) - } else { - g.SendToSceneA(scene, cmd.SceneEntityAppearNotify, owner.ClientSeq, ntf) - } + // logger.Debug("[SceneEntityAppearNotify BC], type: %v, len: %v, uid: %v", ntf.AppearType, len(ntf.EntityList), owner.PlayerId) + g.SendToSceneA(scene, cmd.SceneEntityAppearNotify, owner.ClientSeq, ntf, aecUid) } // RemoveSceneEntityNotifyToPlayer 移除的场景实体同步给玩家 @@ -509,19 +505,15 @@ func (g *Game) RemoveSceneEntityNotifyToPlayer(player *model.Player, visionType } // RemoveSceneEntityNotifyBroadcast 移除的场景实体广播 -func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityIdList []uint32, aec bool, aecUid uint32) { +func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityIdList []uint32) { ntf := &proto.SceneEntityDisappearNotify{ EntityList: entityIdList, DisappearType: visionType, } world := scene.GetWorld() owner := world.GetOwner() - // logger.Debug("[SceneEntityDisappearNotify BC], type: %v, len: %v, uid: %v, aec: %v", ntf.DisappearType, len(ntf.EntityList), owner.PlayerId, aec) - if aec { - g.SendToSceneAEC(scene, cmd.SceneEntityDisappearNotify, owner.ClientSeq, ntf, aecUid) - } else { - g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, owner.ClientSeq, ntf) - } + // logger.Debug("[SceneEntityDisappearNotify BC], type: %v, len: %v, uid: %v", ntf.DisappearType, len(ntf.EntityList), owner.PlayerId) + g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, owner.ClientSeq, ntf, 0) } // AddSceneEntityNotify 添加的场景实体同步 封装接口 @@ -574,7 +566,11 @@ func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.Visio } } if broadcast { - g.AddSceneEntityNotifyBroadcast(scene, visionType, entityList, aec, player.PlayerId) + if aec { + g.AddSceneEntityNotifyBroadcast(scene, visionType, entityList, player.PlayerId) + } else { + g.AddSceneEntityNotifyBroadcast(scene, visionType, entityList, 0) + } } else { g.AddSceneEntityNotifyToPlayer(player, visionType, entityList) } @@ -587,7 +583,7 @@ func (g *Game) EntityFightPropUpdateNotifyBroadcast(scene *Scene, entity *Entity FightPropMap: entity.GetFightProp(), EntityId: entity.GetId(), } - g.SendToSceneA(scene, cmd.EntityFightPropUpdateNotify, 0, ntf) + g.SendToSceneA(scene, cmd.EntityFightPropUpdateNotify, 0, ntf, 0) } // KillPlayerAvatar 杀死玩家角色实体 @@ -632,7 +628,7 @@ func (g *Game) KillPlayerAvatar(player *model.Player, avatarId uint32, dieType p DieType: dieType, MoveReliableSeq: entity.GetLastMoveReliableSeq(), } - g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf) + g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf, 0) } } @@ -669,7 +665,7 @@ func (g *Game) RevivePlayerAvatar(player *model.Player, avatarId uint32) { DieType: proto.PlayerDieType_PLAYER_DIE_NONE, MoveReliableSeq: 0, } - g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf) + g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf, 0) entity.lifeState = constant.LIFE_STATE_ALIVE entity.fightProp[constant.FIGHT_PROP_CUR_HP] = 100 @@ -691,7 +687,7 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d DieType: dieType, MoveReliableSeq: entity.GetLastMoveReliableSeq(), } - g.SendToSceneA(scene, cmd.LifeStateChangeNotify, 0, ntf) + g.SendToSceneA(scene, cmd.LifeStateChangeNotify, 0, ntf, 0) if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR { return @@ -699,7 +695,7 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d // 删除实体 g.EntityFightPropUpdateNotifyBroadcast(scene, entity) - g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_DIE, []uint32{entity.GetId()}, false, 0) + g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_DIE, []uint32{entity.GetId()}) scene.DestroyEntity(entity.GetId()) group := scene.GetGroupById(entity.GetGroupId()) if group == nil { diff --git a/gs/game/player_team.go b/gs/game/player_team.go index fb35076c..946586d9 100644 --- a/gs/game/player_team.go +++ b/gs/game/player_team.go @@ -180,7 +180,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message world.SetPlayerAvatarIndex(player, newAvatarIndex) sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player) - g.SendToWorldA(world, cmd.SceneTeamUpdateNotify, player.ClientSeq, sceneTeamUpdateNotify) + g.SendToWorldA(world, cmd.SceneTeamUpdateNotify, player.ClientSeq, sceneTeamUpdateNotify, 0) changeMpTeamAvatarRsp := &proto.ChangeMpTeamAvatarRsp{ CurAvatarGuid: req.CurAvatarGuid, @@ -314,7 +314,7 @@ func (g *Game) ChangeAvatar(player *model.Player, targetAvatarId uint32) { DisappearType: proto.VisionType_VISION_REPLACE, EntityList: []uint32{oldAvatarEntity.GetId()}, } - g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify) + g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify, 0) newAvatarId := world.GetPlayerActiveAvatarId(player) newAvatarEntity := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarId) @@ -323,7 +323,7 @@ func (g *Game) ChangeAvatar(player *model.Player, targetAvatarId uint32) { Param: oldAvatarEntity.GetId(), EntityList: []*proto.SceneEntityInfo{newAvatarEntity}, } - g.SendToSceneA(scene, cmd.SceneEntityAppearNotify, player.ClientSeq, sceneEntityAppearNotify) + g.SendToSceneA(scene, cmd.SceneEntityAppearNotify, player.ClientSeq, sceneEntityAppearNotify, 0) } /************************************************** 打包封装 **************************************************/ diff --git a/gs/game/player_vehicle.go b/gs/game/player_vehicle.go index 1d1b03af..453cb8cb 100644 --- a/gs/game/player_vehicle.go +++ b/gs/game/player_vehicle.go @@ -173,7 +173,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()}, false, 0) + g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{entity.GetId()}) // 删除玩家载具在线数据 delete(player.VehicleInfo.CreateEntityIdMap, vehicleId) // 删除房主的载具存档 diff --git a/gs/game/player_world.go b/gs/game/player_world.go index b5677a03..c8aad0c5 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -693,7 +693,7 @@ func (g *Game) TeleportPlayer( oldScene := world.GetSceneById(oldSceneId) activeAvatarId := world.GetPlayerActiveAvatarId(player) avatarEntityId := world.GetPlayerWorldAvatarEntityId(player, activeAvatarId) - g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{avatarEntityId}, false, 0) + g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{avatarEntityId}) if WORLD_MANAGER.IsAiWorld(world) { aiWorldAoi := world.GetAiWorldAoi() diff --git a/gs/model/player.go b/gs/model/player.go index 1726927c..c382e083 100644 --- a/gs/model/player.go +++ b/gs/model/player.go @@ -84,6 +84,7 @@ type Player struct { LastSceneBlockAoiMoveTime uint64 `bson:"-" msgpack:"-"` // 上一次移动处理场景区块aoi的时间 CommandAssignUid uint32 `bson:"-" msgpack:"-"` // 命令指定uid WeatherInfo *WeatherInfo `bson:"-" msgpack:"-"` // 天气信息 + ClientVersion int `bson:"-" msgpack:"-"` // 玩家在线的客户端版本 // 特殊数据 ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis }