From 721a87189066eb54e6a7d1e5c954580ac85649ab Mon Sep 17 00:00:00 2001 From: flswld Date: Wed, 24 Apr 2024 18:09:46 +0800 Subject: [PATCH] *** --- common/constant/player_prop.go | 12 ++++++------ gs/game/game_local_event_manager.go | 2 +- gs/game/game_user_manager.go | 12 ++++++------ gs/game/game_world_manager.go | 19 +++++++++++-------- gs/game/player_base.go | 27 +++++++++++++++++++++++++++ gs/game/player_chat.go | 3 +++ gs/game/player_common.go | 4 +--- gs/game/player_login.go | 4 ++++ gs/game/player_scene.go | 5 ++++- gs/game/player_world.go | 8 +------- 10 files changed, 64 insertions(+), 32 deletions(-) diff --git a/common/constant/player_prop.go b/common/constant/player_prop.go index c3074a99..e14914c7 100644 --- a/common/constant/player_prop.go +++ b/common/constant/player_prop.go @@ -21,17 +21,17 @@ const ( PLAYER_PROP_CUR_TEMPORARY_STAMINA = 10012 // 当前临时耐力 暂不确定 PLAYER_PROP_PLAYER_LEVEL = 10013 // 冒险等级 PLAYER_PROP_PLAYER_EXP = 10014 // 冒险经验 - PLAYER_PROP_PLAYER_HCOIN = 10015 // 原石 可以为负数 + PLAYER_PROP_PLAYER_HCOIN = 10015 // 原石 PLAYER_PROP_PLAYER_SCOIN = 10016 // 摩拉 PLAYER_PROP_PLAYER_MP_SETTING_TYPE = 10017 // 多人游戏世界权限 0禁止加入 1直接加入 2需要申请 PLAYER_PROP_IS_MP_MODE_AVAILABLE = 10018 // 玩家当前的世界是否可加入 0 1 例如任务中就不可加入 PLAYER_PROP_PLAYER_WORLD_LEVEL = 10019 // 世界等级 0-8 PLAYER_PROP_PLAYER_RESIN = 10020 // 树脂 0-2000 - PLAYER_PROP_PLAYER_WAIT_SUB_HCOIN = 10022 // 暂存的原石 暂不确定 - PLAYER_PROP_PLAYER_WAIT_SUB_SCOIN = 10023 // 暂存的摩拉 暂不确定 + PLAYER_PROP_PLAYER_WAIT_SUB_HCOIN = 10022 // 扣到负数的原石 + PLAYER_PROP_PLAYER_WAIT_SUB_SCOIN = 10023 // 扣到负数的摩拉 PLAYER_PROP_IS_ONLY_MP_WITH_PS_PLAYER = 10024 // 当前玩家多人世界里是否有PS主机玩家 0 1 - PLAYER_PROP_PLAYER_MCOIN = 10025 // 创世结晶 可以为负数 - PLAYER_PROP_PLAYER_WAIT_SUB_MCOIN = 10026 // 暂存的创世结晶 暂不确定 + PLAYER_PROP_PLAYER_MCOIN = 10025 // 创世结晶 + PLAYER_PROP_PLAYER_WAIT_SUB_MCOIN = 10026 // 扣到负数的创世结晶 PLAYER_PROP_PLAYER_LEGENDARY_KEY = 10027 // 传说任务钥匙 PLAYER_PROP_IS_HAS_FIRST_SHARE = 10028 // 是否拥有抽卡结果首次分享奖励 暂不确定 PLAYER_PROP_PLAYER_FORGE_POINT = 10029 // 锻造相关 @@ -43,7 +43,7 @@ const ( PLAYER_PROP_PLAYER_WORLD_LEVEL_ADJUST_CD = 10040 // 降低世界等级的CD PLAYER_PROP_PLAYER_LEGENDARY_DAILY_TASK_NUM = 10041 // 传说每日任务数量 暂不确定 PLAYER_PROP_PLAYER_HOME_COIN = 10042 // 洞天宝钱 - PLAYER_PROP_PLAYER_WAIT_SUB_HOME_COIN = 10043 // 暂存的洞天宝钱 暂不确定 + PLAYER_PROP_PLAYER_WAIT_SUB_HOME_COIN = 10043 // 扣到负数的洞天宝钱 PLAYER_PROP_IS_AUTO_UNLOCK_SPECIFIC_EQUIP = 10044 // 是否自动解锁特殊装备 暂不确定 PLAYER_PROP_PLAYER_GCG_COIN = 10045 // 七圣召唤相关 PLAYER_PROP_PLAYER_WAIT_SUB_GCG_COIN = 10046 // 七圣召唤相关 diff --git a/gs/game/game_local_event_manager.go b/gs/game/game_local_event_manager.go index 16502558..127b62f8 100644 --- a/gs/game/game_local_event_manager.go +++ b/gs/game/game_local_event_manager.go @@ -62,7 +62,7 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) { } }() gdconf.ReloadGameDataConfig(reloadSceneLua) - LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{ + l.localEventChan <- &LocalEvent{ EventId: ReloadGameDataConfigFinish, } }() diff --git a/gs/game/game_user_manager.go b/gs/game/game_user_manager.go index 31b971cd..e0c39fb0 100644 --- a/gs/game/game_user_manager.go +++ b/gs/game/game_user_manager.go @@ -171,7 +171,7 @@ func (u *UserManager) UserLoginLoad(userId uint32, clientSeq uint32, gateAppId s func (u *UserManager) OnlineUser(player *model.Player) { player.Online = true player.OnlineTime = uint32(time.Now().Unix()) - USER_MANAGER.AddUser(player) + u.AddUser(player) GAME.messageQueue.SendToAll(&mq.NetMsg{ MsgType: mq.MsgTypeServer, EventId: mq.ServerUserOnlineStateChangeNotify, @@ -269,7 +269,7 @@ func (u *UserManager) UserOfflineSave(player *model.Player, changeGsInfo *Change // OfflineUser 玩家离线 func (u *UserManager) OfflineUser(player *model.Player, changeGsInfo *ChangeGsInfo) { - USER_MANAGER.DeleteUser(player.PlayerId) + u.DeleteUser(player.PlayerId) GAME.messageQueue.SendToAll(&mq.NetMsg{ MsgType: mq.MsgTypeServer, EventId: mq.ServerUserOnlineStateChangeNotify, @@ -280,7 +280,7 @@ func (u *UserManager) OfflineUser(player *model.Player, changeGsInfo *ChangeGsIn }) atomic.AddInt32(&ONLINE_PLAYER_NUM, -1) if changeGsInfo.IsChangeGs { - gsAppId := USER_MANAGER.GetRemoteUserGsAppId(changeGsInfo.JoinHostUserId) + gsAppId := u.GetRemoteUserGsAppId(changeGsInfo.JoinHostUserId) GAME.messageQueue.SendToGate(player.GateAppId, &mq.NetMsg{ MsgType: mq.MsgTypeServer, EventId: mq.ServerUserGsChangeNotify, @@ -621,7 +621,7 @@ func (p PlayerLastSaveTimeSortList) Swap(i, j int) { func (u *UserManager) UserCopyAndSave(exitSave bool) { startTime := time.Now().UnixNano() playerList := make(PlayerLastSaveTimeSortList, 0) - for _, player := range USER_MANAGER.GetAllOnlineUserList() { + for _, player := range u.GetAllOnlineUserList() { if player.PlayerId < PlayerBaseUid { continue } @@ -688,7 +688,7 @@ func (u *UserManager) UserCopyAndSave(exitSave bool) { player.LastSaveTime = uint32(time.Now().UnixMilli()) saveCount++ case model.DbDelete: - USER_MANAGER.DeleteUser(player.PlayerId) + u.DeleteUser(player.PlayerId) case model.DbNormal: updatePlayerList = append(updatePlayerList, playerData) player.LastSaveTime = uint32(time.Now().UnixMilli()) @@ -701,7 +701,7 @@ func (u *UserManager) UserCopyAndSave(exitSave bool) { updatePlayerList: updatePlayerList, exitSave: exitSave, } - USER_MANAGER.GetSaveUserChan() <- saveUserData + u.GetSaveUserChan() <- saveUserData endTime := time.Now().UnixNano() costTime := endTime - startTime logger.Info("run save user copy cost time: %v ns, save user count: %v", costTime, saveCount) diff --git a/gs/game/game_world_manager.go b/gs/game/game_world_manager.go index b11f6fe4..e725698e 100644 --- a/gs/game/game_world_manager.go +++ b/gs/game/game_world_manager.go @@ -51,6 +51,7 @@ func (w *WorldManager) CreateWorld(owner *model.Player) *World { worldId := uint64(w.snowflake.GenId()) world := &World{ id: worldId, + worldManager: w, owner: owner, playerMap: make(map[uint32]*model.Player), sceneMap: make(map[uint32]*Scene), @@ -193,7 +194,7 @@ func (w *WorldManager) LoadSceneAoi() { } func (w *World) IsValidScenePos(sceneId uint32, x, y, z float32) bool { - aoiManager, exist := WORLD_MANAGER.sceneBlockAoiMap[sceneId] + aoiManager, exist := w.worldManager.sceneBlockAoiMap[sceneId] if !exist { return false } @@ -222,6 +223,7 @@ type EnterSceneContext struct { // World 世界数据结构 type World struct { id uint64 + worldManager *WorldManager owner *model.Player playerMap map[uint32]*model.Player sceneMap map[uint32]*Scene @@ -248,6 +250,10 @@ func (w *World) GetId() uint64 { return w.id } +func (w *World) GetWorldManager() *WorldManager { + return w.worldManager +} + func (w *World) GetOwner() *model.Player { return w.owner } @@ -369,13 +375,13 @@ func (w *World) AddPlayer(player *model.Player) { // 将玩家自身当前的队伍角色信息复制到世界的玩家本地队伍 dbTeam := player.GetDbTeam() team := dbTeam.GetActiveTeam() - if WORLD_MANAGER.IsAiWorld(w) { + if w.worldManager.IsAiWorld(w) { w.SetPlayerLocalTeam(player, []uint32{dbTeam.GetActiveAvatarId()}) } else { w.SetPlayerLocalTeam(player, team.GetAvatarIdList()) } w.SetPlayerActiveAvatarId(player, dbTeam.GetActiveAvatarId()) - if WORLD_MANAGER.IsAiWorld(w) { + if w.worldManager.IsAiWorld(w) { w.AddMultiplayerTeam(player) } else { w.UpdateMultiplayerTeam() @@ -397,7 +403,7 @@ func (w *World) RemovePlayer(player *model.Player) { delete(w.multiplayerTeam.localTeamMap, player.PlayerId) delete(w.multiplayerTeam.localTeamEntityMap, player.PlayerId) delete(w.multiplayerTeam.localActiveAvatarMap, player.PlayerId) - if WORLD_MANAGER.IsAiWorld(w) { + if w.worldManager.IsAiWorld(w) { w.RemoveMultiplayerTeam(player) } else { if player.PlayerId != w.owner.PlayerId { @@ -810,9 +816,6 @@ func (w *World) AddChat(chatInfo *proto.ChatInfo) { w.chatMsgList = w.chatMsgList[1:] } w.chatMsgList = append(w.chatMsgList, chatInfo) - chatMsg := GAME.ConvChatInfoToChatMsg(chatInfo) - chatMsg.IsDelete = true - go USER_MANAGER.SaveUserChatMsgToDbSync(chatMsg) } func (w *World) GetChatList() []*proto.ChatInfo { @@ -821,7 +824,7 @@ func (w *World) GetChatList() []*proto.ChatInfo { // ChangeToMultiplayer 转换为多人世界 func (w *World) ChangeToMultiplayer() { - WORLD_MANAGER.multiplayerWorldNum++ + w.worldManager.multiplayerWorldNum++ w.multiplayer = true w.owner.IsInMp = true } diff --git a/gs/game/player_base.go b/gs/game/player_base.go index f6fe34ca..2c8bb273 100644 --- a/gs/game/player_base.go +++ b/gs/game/player_base.go @@ -88,15 +88,42 @@ func (g *Game) HandlePlayerExpAdd(userId uint32) { player.PropMap[constant.PLAYER_PROP_PLAYER_LEVEL]++ player.PropMap[constant.PLAYER_PROP_PLAYER_EXP] -= uint32(playerLevelConfig.Exp) } + // TODO 完善的世界等级机制 + player.PropMap[constant.PLAYER_PROP_PLAYER_WORLD_LEVEL] = g.GetWorldLevelByPlayerLevel(player.PropMap[constant.PLAYER_PROP_PLAYER_LEVEL]) // 更新玩家属性 g.SendMsg(cmd.PlayerPropNotify, player.PlayerId, player.ClientSeq, g.PacketPlayerPropNotify( player, constant.PLAYER_PROP_PLAYER_LEVEL, constant.PLAYER_PROP_PLAYER_EXP, + constant.PLAYER_PROP_PLAYER_WORLD_LEVEL, )) g.TriggerOpenState(userId) } +func (g *Game) GetWorldLevelByPlayerLevel(playerLevel uint32) uint32 { + if playerLevel < 20 { + return 0 + } else if playerLevel < 25 { + return 1 + } else if playerLevel < 30 { + return 2 + } else if playerLevel < 35 { + return 3 + } else if playerLevel < 40 { + return 4 + } else if playerLevel < 45 { + return 5 + } else if playerLevel < 50 { + return 6 + } else if playerLevel < 55 { + return 7 + } else if playerLevel < 60 { + return 8 + } else { + return 8 + } +} + // TriggerOpenState 触发检测功能开放状态更新 func (g *Game) TriggerOpenState(userId uint32) { player := USER_MANAGER.GetOnlineUser(userId) diff --git a/gs/game/player_chat.go b/gs/game/player_chat.go index 4cdd114d..ef4c9971 100644 --- a/gs/game/player_chat.go +++ b/gs/game/player_chat.go @@ -168,6 +168,9 @@ func (g *Game) PlayerChatReq(player *model.Player, payloadMsg pb.Message) { return } world.AddChat(sendChatInfo) + chatMsg := g.ConvChatInfoToChatMsg(chatInfo) + chatMsg.IsDelete = true + go USER_MANAGER.SaveUserChatMsgToDbSync(chatMsg) ntf := &proto.PlayerChatNotify{ ChannelId: channelId, diff --git a/gs/game/player_common.go b/gs/game/player_common.go index 76a4a607..c69a1383 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -21,9 +21,7 @@ func (g *Game) PingReq(player *model.Player, payloadMsg pb.Message) { player.ClientTime = req.ClientTime now := uint32(time.Now().Unix()) // 客户端与服务器时间相差太过严重 - max := math.Max(float64(now), float64(player.ClientTime)) - min := math.Min(float64(now), float64(player.ClientTime)) - if math.Abs(max-min) > 600.0 { + if math.Abs(math.Max(float64(now), float64(player.ClientTime))-math.Min(float64(now), float64(player.ClientTime))) > 600.0 { logger.Error("abs of client time and server time above 600s, clientTime: %v, uid: %v", player.ClientTime, player.PlayerId) } player.LastKeepaliveTime = now diff --git a/gs/game/player_login.go b/gs/game/player_login.go index 5fe269ed..cfa094f0 100644 --- a/gs/game/player_login.go +++ b/gs/game/player_login.go @@ -53,8 +53,12 @@ func (g *Game) SetPlayerBornDataReq(player *model.Player, payloadMsg pb.Message) dbWeapon.AddWeapon(player, uint32(avatarDataConfig.InitialWeapon), weaponId) weapon := dbWeapon.GetWeaponById(weaponId) dbAvatar.WearWeapon(dbAvatar.MainCharAvatarId, weapon) + // 主角添加进队伍 dbTeam := player.GetDbTeam() dbTeam.GetActiveTeam().SetAvatarIdList([]uint32{dbAvatar.MainCharAvatarId}) + // 主角面板 + avatar := dbAvatar.GetAvatarById(dbAvatar.MainCharAvatarId) + dbAvatar.UpdateAvatarFightProp(avatar) g.AcceptQuest(player, false) diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index c40afdbd..6511a93c 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -1271,10 +1271,13 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any switch entityConfig.(type) { case *gdconf.Monster: monster := entityConfig.(*gdconf.Monster) + // TODO 怪物等级与世界等级的关联 + worldLevel := owner.PropMap[constant.PLAYER_PROP_PLAYER_WORLD_LEVEL] + monsterLevel := uint8(float32(monster.Level) * float32(worldLevel+1) * 0.25) return scene.CreateEntityMonster( &model.Vector{X: float64(monster.Pos.X), Y: float64(monster.Pos.Y), Z: float64(monster.Pos.Z)}, &model.Vector{X: float64(monster.Rot.X), Y: float64(monster.Rot.Y), Z: float64(monster.Rot.Z)}, - uint32(monster.MonsterId), uint8(monster.Level), uint32(monster.ConfigId), groupId, int(monster.VisionLevel), + uint32(monster.MonsterId), monsterLevel, uint32(monster.ConfigId), groupId, int(monster.VisionLevel), ) case *gdconf.Npc: npc := entityConfig.(*gdconf.Npc) diff --git a/gs/game/player_world.go b/gs/game/player_world.go index ce70f5c3..49775b32 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -562,13 +562,7 @@ func (g *Game) UnlockPlayerSceneArea(player *model.Player, sceneId uint32, areaI // ChangeGameTime 修改游戏时间 func (g *Game) ChangeGameTime(world *World, gameTime uint32) { world.ChangeGameTime(gameTime) - for _, player := range world.GetAllPlayer() { - playerGameTimeNotify := &proto.PlayerGameTimeNotify{ - GameTime: world.GetGameTime(), - Uid: player.PlayerId, - } - g.SendMsg(cmd.PlayerGameTimeNotify, player.PlayerId, player.ClientSeq, playerGameTimeNotify) - } + g.PlayerGameTimeNotify(world) } const (