From c5eb34723b742b8c789cbd617230ab62ad45e8a8 Mon Sep 17 00:00:00 2001 From: flswld Date: Fri, 17 Nov 2023 08:20:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=83=E5=A4=A9=E7=A5=9E=E5=83=8F=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E4=B8=8E=E5=9C=BA=E6=99=AF=E5=8C=BA=E5=9F=9F=E8=A7=A3?= =?UTF-8?q?=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdconf/open_state_data.go | 46 +++++++++++- gs/game/game.go | 9 +-- gs/game/game_command_gm.go | 22 +++--- gs/game/player_base.go | 74 ++++++++++++++++-- gs/game/player_item.go | 4 +- gs/game/player_login.go | 36 ++++----- gs/game/player_quest.go | 48 +++++++++++- gs/game/player_scene.go | 50 ++++++++++--- gs/game/player_world.go | 107 +++++++++++++++++---------- gs/model/db_world.go | 32 +++++++- protocol/cmd/cmd_id_proto_obj_map.go | 3 + 11 files changed, 325 insertions(+), 106 deletions(-) diff --git a/gdconf/open_state_data.go b/gdconf/open_state_data.go index 8527efde..680d4a44 100644 --- a/gdconf/open_state_data.go +++ b/gdconf/open_state_data.go @@ -4,11 +4,24 @@ import ( "hk4e/pkg/logger" ) +type OpenStateCond struct { + Type int32 + Param []int32 +} + // OpenStateData 开放状态配置表 type OpenStateData struct { - OpenStateId int32 `csv:"ID"` - DefaultOpen int32 `csv:"默认是否开启,omitempty"` - AllowClientReq int32 `csv:"客户端能否发起功能开启,omitempty"` + OpenStateId int32 `csv:"ID"` + DefaultOpen int32 `csv:"默认是否开启,omitempty"` + AllowClientReq int32 `csv:"客户端能否发起功能开启,omitempty"` + CondType1 int32 `csv:"条件1类型,omitempty"` + CondType1Param int32 `csv:"条件1参数,omitempty"` + CondType1Param2 int32 `csv:"条件1参数2,omitempty"` + CondType2 int32 `csv:"条件2类型,omitempty"` + CondType2Param int32 `csv:"条件2参数,omitempty"` + CondType2Param2 int32 `csv:"条件2参数2,omitempty"` + + OpenStateCondList []*OpenStateCond } func (g *GameDataConfig) loadOpenStateData() { @@ -16,6 +29,33 @@ func (g *GameDataConfig) loadOpenStateData() { openStateDataList := make([]*OpenStateData, 0) readTable[OpenStateData](g.txtPrefix+"OpenStateData.txt", &openStateDataList) for _, openStateData := range openStateDataList { + openStateData.OpenStateCondList = make([]*OpenStateCond, 0) + if openStateData.CondType1 != 0 { + paramList := make([]int32, 0) + if openStateData.CondType1Param != 0 { + paramList = append(paramList, openStateData.CondType1Param) + } + if openStateData.CondType1Param2 != 0 { + paramList = append(paramList, openStateData.CondType1Param2) + } + openStateData.OpenStateCondList = append(openStateData.OpenStateCondList, &OpenStateCond{ + Type: openStateData.CondType1, + Param: paramList, + }) + } + if openStateData.CondType2 != 0 { + paramList := make([]int32, 0) + if openStateData.CondType2Param != 0 { + paramList = append(paramList, openStateData.CondType2Param) + } + if openStateData.CondType2Param2 != 0 { + paramList = append(paramList, openStateData.CondType2Param2) + } + openStateData.OpenStateCondList = append(openStateData.OpenStateCondList, &OpenStateCond{ + Type: openStateData.CondType2, + Param: paramList, + }) + } g.OpenStateDataMap[openStateData.OpenStateId] = openStateData } logger.Info("OpenStateData count: %v", len(g.OpenStateDataMap)) diff --git a/gs/game/game.go b/gs/game/game.go index 44b4733e..f7a63f29 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -426,15 +426,10 @@ func (g *Game) SendError(cmdId uint16, player *model.Player, rsp pb.Message, ret if rsp == nil { return } - ret := int32(proto.Retcode_RET_FAIL) if len(retCode) == 0 { - ret = int32(proto.Retcode_RET_SVR_ERROR) - } else if len(retCode) == 1 { - ret = int32(retCode[0]) - } else { - return + retCode = []proto.Retcode{proto.Retcode_RET_SVR_ERROR} } - ok := reflection.SetStructFieldValue(rsp, "Retcode", ret) + ok := reflection.SetStructFieldValue(rsp, "Retcode", int32(retCode[0])) if !ok { return } diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go index ca5ae5bd..4a48ad54 100644 --- a/gs/game/game_command_gm.go +++ b/gs/game/game_command_gm.go @@ -258,8 +258,8 @@ func (g *GMCmd) GMKillAllMonster(userId uint32) { logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId) return } - // 杀死所有怪物实体 - for _, entity := range scene.GetAllEntity() { + // 杀死视野内所有怪物实体 + for _, entity := range GAME.GetVisionEntity(scene, GAME.GetPlayerPos(player)) { // 确保为怪物 if entity.GetEntityType() != constant.ENTITY_TYPE_MONSTER { continue @@ -504,24 +504,20 @@ func (g *GMCmd) GMFreeMode(userId uint32) { logger.Error("player is nil, uid: %v", userId) return } + player.PropMap[constant.PLAYER_PROP_IS_FLYABLE] = 1 + player.PropMap[constant.PLAYER_PROP_IS_TRANSFERABLE] = 1 player.PropMap[constant.PLAYER_PROP_IS_WEATHER_LOCKED] = 0 player.PropMap[constant.PLAYER_PROP_IS_GAME_TIME_LOCKED] = 0 - player.PropMap[constant.PLAYER_PROP_IS_TRANSFERABLE] = 1 - player.PropMap[constant.PLAYER_PROP_IS_MP_MODE_AVAILABLE] = 1 player.PropMap[constant.PLAYER_PROP_PLAYER_CAN_DIVE] = 1 player.PropMap[constant.PLAYER_PROP_DIVE_MAX_STAMINA] = 10000 player.PropMap[constant.PLAYER_PROP_DIVE_CUR_STAMINA] = 10000 + player.PropMap[constant.PLAYER_PROP_IS_MP_MODE_AVAILABLE] = 1 GAME.SendMsg(cmd.PlayerPropNotify, userId, player.ClientSeq, GAME.PacketPlayerPropNotify(player)) - for _, openStateData := range gdconf.GetOpenStateDataMap() { - player.OpenStateMap[uint32(openStateData.OpenStateId)] = 1 - } - GAME.SendMsg(cmd.OpenStateChangeNotify, player.PlayerId, player.ClientSeq, &proto.OpenStateChangeNotify{ - OpenStateMap: player.OpenStateMap, - }) - for _, sceneData := range gdconf.GetSceneDataMap() { - g.GMUnlockAllPoint(userId, uint32(sceneData.SceneId)) - } + + GAME.ChangePlayerOpenState(player.PlayerId, constant.OPEN_STATE_LIMIT_REGION_FRESHMEAT, 1) + GAME.ChangePlayerOpenState(player.PlayerId, constant.OPEN_STATE_LIMIT_REGION_GLOBAL, 1) + GAME.ChangePlayerOpenState(player.PlayerId, constant.OPEN_STATE_MULTIPLAYER, 1) } // GMChangeSkillDepot 切换当前角色技能库 diff --git a/gs/game/player_base.go b/gs/game/player_base.go index 5b143039..b697a4e4 100644 --- a/gs/game/player_base.go +++ b/gs/game/player_base.go @@ -3,6 +3,7 @@ package game import ( "time" + "hk4e/pkg/object" "hk4e/protocol/cmd" "hk4e/common/constant" @@ -39,7 +40,7 @@ func (g *Game) SetOpenStateReq(player *model.Player, payloadMsg pb.Message) { logger.Error("get open state data config is nil, key: %v", req.Key) return } - if openStateDataConfig.AllowClientReq == 0 { + if !object.ConvInt64ToBool(int64(openStateDataConfig.AllowClientReq)) { g.SendError(cmd.SetOpenStateRsp, player, &proto.SetOpenStateRsp{}) return } @@ -88,8 +89,74 @@ func (g *Game) HandlePlayerExpAdd(userId uint32) { constant.PLAYER_PROP_PLAYER_LEVEL, constant.PLAYER_PROP_PLAYER_EXP, )) + g.TriggerOpenState(userId) } +// TriggerOpenState 触发检测功能开放状态更新 +func (g *Game) TriggerOpenState(userId uint32) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + updateOpenStateMap := make(map[uint32]uint32) + for _, openStateDataConfig := range gdconf.GetOpenStateDataMap() { + if len(openStateDataConfig.OpenStateCondList) == 0 { + continue + } + if player.OpenStateMap[uint32(openStateDataConfig.OpenStateId)] == 1 { + continue + } + finish := true + for _, openStateCond := range openStateDataConfig.OpenStateCondList { + switch openStateCond.Type { + case constant.OPEN_STATE_COND_PLAYER_LEVEL: + if len(openStateCond.Param) != 1 { + finish = false + continue + } + if player.PropMap[constant.PLAYER_PROP_PLAYER_LEVEL] < uint32(openStateCond.Param[0]) { + finish = false + continue + } + case constant.OPEN_STATE_COND_QUEST: + if len(openStateCond.Param) != 1 { + finish = false + continue + } + dbQuest := player.GetDbQuest() + quest := dbQuest.GetQuestById(uint32(openStateCond.Param[0])) + if quest == nil { + finish = false + continue + } + if quest.State != constant.QUEST_STATE_FINISHED { + finish = false + continue + } + case constant.OPEN_STATE_COND_OFFERING_LEVEL: + finish = false + continue + case constant.OPEN_STATE_COND_CITY_REPUTATION_LEVEL: + finish = false + continue + case constant.OPEN_STATE_COND_PARENT_QUEST: + finish = false + continue + } + } + if finish { + logger.Debug("open state change to open, id: %v, uid: %v", openStateDataConfig.OpenStateId, player.PlayerId) + updateOpenStateMap[uint32(openStateDataConfig.OpenStateId)] = 1 + player.OpenStateMap[uint32(openStateDataConfig.OpenStateId)] = 1 + } + } + g.SendMsg(cmd.OpenStateChangeNotify, player.PlayerId, player.ClientSeq, &proto.OpenStateChangeNotify{ + OpenStateMap: updateOpenStateMap, + }) +} + +// ChangePlayerOpenState 修改功能开放状态 func (g *Game) ChangePlayerOpenState(userId uint32, key uint32, value uint32) { player := USER_MANAGER.GetOnlineUser(userId) if player == nil { @@ -147,10 +214,7 @@ func (g *Game) PacketPlayerPropNotify(player *model.Player, propList ...uint32) func (g *Game) PacketOpenStateUpdateNotify(player *model.Player) *proto.OpenStateUpdateNotify { ntf := &proto.OpenStateUpdateNotify{ - OpenStateMap: make(map[uint32]uint32), - } - for k, v := range player.OpenStateMap { - ntf.OpenStateMap[k] = v + OpenStateMap: player.OpenStateMap, } return ntf } diff --git a/gs/game/player_item.go b/gs/game/player_item.go index 22f1e7e6..221d495c 100644 --- a/gs/game/player_item.go +++ b/gs/game/player_item.go @@ -77,7 +77,7 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) { if avatar == nil { g.AddPlayerAvatar(userId, uint32(avatarId)) } else { - g.AddPlayerItem(userId, []*ChangeItem{{ItemId: itemId + 100, ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_ADD_AVATAR) + g.AddPlayerItem(userId, []*ChangeItem{{ItemId: itemId + 100, ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP) } case constant.ITEM_USE_RELIVE_AVATAR: // 复活角色 @@ -170,7 +170,7 @@ func (g *Game) UseItem(userId uint32, itemId uint32, targetParam ...uint64) { g.AddPlayerAvatarEnergy(player.PlayerId, worldAvatar.GetAvatarId(), float32(addEnergy), false) } default: - logger.Error("use option not support, useOption: %v, uid: %v", itemUse.UseOption, userId) + // logger.Error("use option not support, useOption: %v, uid: %v", itemUse.UseOption, userId) } } } diff --git a/gs/game/player_login.go b/gs/game/player_login.go index ea165a33..ccccf553 100644 --- a/gs/game/player_login.go +++ b/gs/game/player_login.go @@ -6,6 +6,7 @@ import ( "hk4e/gdconf" "hk4e/gs/model" "hk4e/pkg/logger" + "hk4e/pkg/object" "hk4e/protocol/cmd" "hk4e/protocol/proto" @@ -57,6 +58,8 @@ func (g *Game) SetPlayerBornDataReq(player *model.Player, payloadMsg pb.Message) g.AcceptQuest(player, false) + g.TriggerOpenState(player.PlayerId) + g.LoginNotify(player.PlayerId, player.ClientSeq, player) // 创建世界 @@ -91,7 +94,6 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player SELF = player - // 初始化 player.InitOnlineData() if player.GetSceneId() > 100 { @@ -110,6 +112,8 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player } } + g.TriggerOpenState(userId) + if player.IsBorn { g.LoginNotify(userId, clientSeq, player) if req.TargetUid != 0 { @@ -136,7 +140,7 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player clientVersion, _ := region.GetClientVersionByName(req.ChecksumClientVersion) player.ClientVersion = clientVersion - playerLoginRsp := &proto.PlayerLoginRsp{ + rsp := &proto.PlayerLoginRsp{ IsUseAbilityHash: true, AbilityHashCode: 0, IsEnableClientHashDebug: true, @@ -148,13 +152,14 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player CountryCode: "US", Birthday: "2000-01-01", } - g.SendMsg(cmd.PlayerLoginRsp, userId, clientSeq, playerLoginRsp) + g.SendMsg(cmd.PlayerLoginRsp, userId, clientSeq, rsp) SELF = nil } func (g *Game) CreatePlayer(userId uint32) *model.Player { player := new(model.Player) + player.IsBorn = false player.PlayerId = userId player.NickName = "旅行者" player.Signature = "" @@ -162,7 +167,6 @@ func (g *Game) CreatePlayer(userId uint32) *model.Player { player.PropMap = make(map[uint32]uint32) player.OpenStateMap = make(map[uint32]uint32) player.ChatMsgMap = make(map[uint32][]*model.ChatMsg) - player.SceneId = 3 player.PropMap[constant.PLAYER_PROP_PLAYER_WORLD_LEVEL] = 0 @@ -197,25 +201,11 @@ func (g *Game) CreatePlayer(userId uint32) *model.Player { player.PropMap[constant.PLAYER_PROP_IS_TRANSFERABLE] = 1 player.PropMap[constant.PLAYER_PROP_MAX_STAMINA] = 10000 - player.OpenStateMap[constant.OPEN_STATE_DERIVATIVE_MALL] = 1 - player.OpenStateMap[constant.OPEN_STATE_PHOTOGRAPH] = 1 - player.OpenStateMap[constant.OPEN_STATE_GUIDE_RELIC_PROM] = 1 - player.OpenStateMap[constant.OPEN_STATE_GUIDE_TALENT] = 1 - player.OpenStateMap[constant.OPEN_STATE_RELIQUARY_PROMOTE] = 1 - player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_RECOMMANDED] = 1 - player.OpenStateMap[constant.OPEN_STATE_RELIQUARY_UPGRADE] = 1 - player.OpenStateMap[constant.OPEN_STATE_WEAPON_AWAKEN] = 1 - player.OpenStateMap[constant.OPEN_STATE_WEAPON_PROMOTE] = 1 - player.OpenStateMap[constant.OPEN_STATE_WEAPON_UPGRADE] = 1 - player.OpenStateMap[constant.OPEN_STATE_AVATAR_TALENT] = 1 - player.OpenStateMap[constant.OPEN_STATE_AVATAR_PROMOTE] = 1 - player.OpenStateMap[constant.OPEN_STATE_RESIN] = 1 - player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_GENESISCRYSTAL] = 1 - player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_GIFTPACKAGE] = 1 - player.OpenStateMap[constant.OPEN_STATE_BATTLE_PASS] = 1 - player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_BLACKSMITH] = 1 - player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_PAIMON] = 1 - player.OpenStateMap[constant.OPEN_STATE_SHOP_TYPE_VIRTUAL_SHOP] = 1 + for _, openStateDataConfig := range gdconf.GetOpenStateDataMap() { + if object.ConvInt64ToBool(int64(openStateDataConfig.DefaultOpen)) { + player.OpenStateMap[uint32(openStateDataConfig.OpenStateId)] = 1 + } + } sceneLuaConfig := gdconf.GetSceneLuaConfigById(int32(player.GetSceneId())) if sceneLuaConfig != nil { diff --git a/gs/game/player_quest.go b/gs/game/player_quest.go index b1789934..08d77c83 100644 --- a/gs/game/player_quest.go +++ b/gs/game/player_quest.go @@ -183,9 +183,24 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) { if questData.QuestId == 35721 { // TODO 由于风龙任务进入秘境客户端会无限重连相关原因暂时屏蔽 // 直接福瑞 - COMMAND_MANAGER.gmCmd.GMFreeMode(player.PlayerId) + if player.OpenStateMap[constant.OPEN_STATE_LIMIT_REGION_FRESHMEAT] == 0 { + COMMAND_MANAGER.gmCmd.GMFreeMode(player.PlayerId) + for _, openStateData := range gdconf.GetOpenStateDataMap() { + player.OpenStateMap[uint32(openStateData.OpenStateId)] = 1 + } + GAME.SendMsg(cmd.OpenStateChangeNotify, player.PlayerId, player.ClientSeq, &proto.OpenStateChangeNotify{ + OpenStateMap: player.OpenStateMap, + }) + } continue } + if questData.QuestId == 36301 { + // TODO 懒得搞 + g.SendMsg(cmd.ChapterStateNotify, player.PlayerId, player.ClientSeq, &proto.ChapterStateNotify{ + ChapterState: proto.ChapterState_CHAPTER_STATE_BEGIN, + ChapterId: 1001, + }) + } dbQuest.AddQuest(uint32(questData.QuestId)) addQuestIdList = append(addQuestIdList, uint32(questData.QuestId)) } @@ -251,7 +266,9 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int for _, questExec := range questExecList { switch questExec.Type { case constant.QUEST_EXEC_TYPE_NOTIFY_GROUP_LUA: + // 通知LUA侧 case constant.QUEST_EXEC_TYPE_REFRESH_GROUP_SUITE: + // 刷新场景小组 if len(questExec.Param) != 2 { continue } @@ -269,6 +286,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int } g.RefreshSceneGroupSuite(player, uint32(groupId), uint8(suiteId)) case constant.QUEST_EXEC_TYPE_SET_OPEN_STATE: + // 设置游戏功能开放状态 if len(questExec.Param) != 2 { continue } @@ -282,6 +300,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int } g.ChangePlayerOpenState(player.PlayerId, uint32(key), uint32(value)) case constant.QUEST_EXEC_TYPE_UNLOCK_POINT: + // 解锁传送点 if len(questExec.Param) != 2 { continue } @@ -295,7 +314,21 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int } g.UnlockPlayerTransPoint(player, uint32(sceneId), uint32(pointId)) case constant.QUEST_EXEC_TYPE_UNLOCK_AREA: + // 解锁场景区域 + if len(questExec.Param) != 2 { + continue + } + sceneId, err := strconv.Atoi(questExec.Param[0]) + if err != nil { + continue + } + areaId, err := strconv.Atoi(questExec.Param[1]) + if err != nil { + continue + } + g.UnlockPlayerSceneArea(player, uint32(sceneId), uint32(areaId)) case constant.QUEST_EXEC_TYPE_CHANGE_AVATAR_ELEMET: + // 改变主角元素类型 if len(questExec.Param) != 1 { continue } @@ -306,6 +339,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int dbAvatar := player.GetDbAvatar() g.ChangePlayerAvatarSkillDepot(player.PlayerId, dbAvatar.MainCharAvatarId, 0, elementType) case constant.QUEST_EXEC_TYPE_SET_IS_FLYABLE: + // 设置允许飞行状态 if len(questExec.Param) != 1 { continue } @@ -316,6 +350,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int player.PropMap[constant.PLAYER_PROP_IS_FLYABLE] = uint32(value) g.SendMsg(cmd.PlayerPropNotify, player.PlayerId, player.ClientSeq, g.PacketPlayerPropNotify(player, constant.PLAYER_PROP_IS_FLYABLE)) case constant.QUEST_EXEC_TYPE_SET_IS_WEATHER_LOCKED: + // 设置天气锁定状态 if len(questExec.Param) != 1 { continue } @@ -326,6 +361,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int player.PropMap[constant.PLAYER_PROP_IS_WEATHER_LOCKED] = uint32(value) g.SendMsg(cmd.PlayerPropNotify, player.PlayerId, player.ClientSeq, g.PacketPlayerPropNotify(player, constant.PLAYER_PROP_IS_WEATHER_LOCKED)) case constant.QUEST_EXEC_TYPE_SET_IS_GAME_TIME_LOCKED: + // 设置游戏时间锁定状态 if len(questExec.Param) != 1 { continue } @@ -336,6 +372,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int player.PropMap[constant.PLAYER_PROP_IS_GAME_TIME_LOCKED] = uint32(value) g.SendMsg(cmd.PlayerPropNotify, player.PlayerId, player.ClientSeq, g.PacketPlayerPropNotify(player, constant.PLAYER_PROP_IS_GAME_TIME_LOCKED)) case constant.QUEST_EXEC_TYPE_SET_IS_TRANSFERABLE: + // 设置允许传送状态 if len(questExec.Param) != 1 { continue } @@ -346,6 +383,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int player.PropMap[constant.PLAYER_PROP_IS_TRANSFERABLE] = uint32(value) g.SendMsg(cmd.PlayerPropNotify, player.PlayerId, player.ClientSeq, g.PacketPlayerPropNotify(player, constant.PLAYER_PROP_IS_TRANSFERABLE)) case constant.QUEST_EXEC_TYPE_SET_GAME_TIME: + // 设置游戏时间 if len(questExec.Param) != 1 { continue } @@ -365,6 +403,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int } g.ChangeGameTime(scene, uint32(hour*60)) case constant.QUEST_EXEC_TYPE_ROLLBACK_QUEST: + // 回滚任务 if len(questExec.Param) != 1 { continue } @@ -376,6 +415,8 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int rollbackQuest := dbQuest.GetQuestById(uint32(rollbackQuestId)) rollbackQuest.State = constant.QUEST_STATE_UNSTARTED g.StartQuest(player, rollbackQuest.QuestId, true) + default: + logger.Error("not support quest exec type: %v, uid: %v", questExec.Type, player.PlayerId) } } } @@ -471,6 +512,10 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin } dbQuest.ForceFinishQuest(quest.QuestId) updateQuestIdList = append(updateQuestIdList, quest.QuestId) + case constant.QUEST_FINISH_COND_TYPE_UNLOCK_AREA: + // 解锁场景区域 参数1:场景id 参数2:场景区域id + default: + logger.Error("not support quest cond type: %v, uid: %v", cond, player.PlayerId) } } } @@ -514,6 +559,7 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin } } g.AcceptQuest(player, true) + g.TriggerOpenState(player.PlayerId) } } diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 9e7d696b..706c90fd 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -130,10 +130,10 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) { } g.SendMsg(cmd.EnterScenePeerNotify, player.PlayerId, player.ClientSeq, enterScenePeerNotify) - enterSceneReadyRsp := &proto.EnterSceneReadyRsp{ + rsp := &proto.EnterSceneReadyRsp{ EnterSceneToken: req.EnterSceneToken, } - g.SendMsg(cmd.EnterSceneReadyRsp, player.PlayerId, player.ClientSeq, enterSceneReadyRsp) + g.SendMsg(cmd.EnterSceneReadyRsp, player.PlayerId, player.ClientSeq, rsp) } // SceneInitFinishReq 场景初始化完成 @@ -191,6 +191,7 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) { worldDataNotify.WorldPropMap[2] = g.PacketPropValue(2, object.ConvBoolToInt64(world.IsMultiplayerWorld())) g.SendMsg(cmd.WorldDataNotify, player.PlayerId, player.ClientSeq, worldDataNotify) + // TODO 暂时先解锁全部场景和场景标签 看着喜庆 playerWorldSceneInfoListNotify := &proto.PlayerWorldSceneInfoListNotify{ InfoList: []*proto.PlayerWorldSceneInfo{ {SceneId: 1, IsLocked: false, SceneTagIdList: []uint32{}}, @@ -305,10 +306,10 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) { } } - SceneInitFinishRsp := &proto.SceneInitFinishRsp{ + rsp := &proto.SceneInitFinishRsp{ EnterSceneToken: req.EnterSceneToken, } - g.SendMsg(cmd.SceneInitFinishRsp, player.PlayerId, player.ClientSeq, SceneInitFinishRsp) + g.SendMsg(cmd.SceneInitFinishRsp, player.PlayerId, player.ClientSeq, rsp) player.SceneLoadState = model.SceneInitFinish } @@ -356,6 +357,33 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { groupConfig := gdconf.GetSceneGroup(triggerDataConfig.GroupId) g.AddSceneGroup(player, scene, groupConfig) } + // TODO 七天神像的group太远不加载的临时解决方案 + if player.GetSceneId() == 3 { + groupSuiteNotify := &proto.GroupSuiteNotify{ + GroupMap: map[uint32]uint32{ + // 不属于任何group的七天神像及其npc_id + // 1209 1276 1280 4904 4905 + // 包含七天神像npc的group及其npc_id + 133004001: 1, // 1201 1202 1203 1204 + 133107001: 1, // 1205 1206 1207 1208 + 133105279: 1, // 1268 + 133008051: 2, // 1272 + 133205002: 1, // 1273 1274 1275 + 133217159: 1, // 1277 + 133210213: 1, // 1278 + 133223052: 1, // 1279 + 133106438: 1, // 1281 + 133302001: 1, // 1282 1283 1285 1286 1288 + 133301642: 2, // 1284 + 133301641: 2, // 1287 + 133303649: 1, // 4900 + 133309184: 1, // 4901 + 133310355: 1, // 4902 + 133307014: 1, // 4903 + }, + } + g.SendMsg(cmd.GroupSuiteNotify, player.PlayerId, player.ClientSeq, groupSuiteNotify) + } } // 同步客户端视野内的场景实体 @@ -389,10 +417,10 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { } g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerId, player.ClientSeq, sceneAreaWeatherNotify) - enterSceneDoneRsp := &proto.EnterSceneDoneRsp{ + rsp := &proto.EnterSceneDoneRsp{ EnterSceneToken: req.EnterSceneToken, } - g.SendMsg(cmd.EnterSceneDoneRsp, player.PlayerId, player.ClientSeq, enterSceneDoneRsp) + g.SendMsg(cmd.EnterSceneDoneRsp, player.PlayerId, player.ClientSeq, rsp) player.SceneLoadState = model.SceneEnterDone @@ -428,10 +456,10 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) { world.PlayerEnter(player.PlayerId) - postEnterSceneRsp := &proto.PostEnterSceneRsp{ + rsp := &proto.PostEnterSceneRsp{ EnterSceneToken: req.EnterSceneToken, } - g.SendMsg(cmd.PostEnterSceneRsp, player.PlayerId, player.ClientSeq, postEnterSceneRsp) + g.SendMsg(cmd.PostEnterSceneRsp, player.PlayerId, player.ClientSeq, rsp) // 触发事件 if PLUGIN_MANAGER.TriggerEvent(PluginEventIdPostEnterScene, &PluginEventPostEnterScene{ @@ -453,10 +481,10 @@ func (g *Game) SceneEntityDrownReq(player *model.Player, payloadMsg pb.Message) scene := world.GetSceneById(player.GetSceneId()) g.KillEntity(player, scene, req.EntityId, proto.PlayerDieType_PLAYER_DIE_DRAWN) - sceneEntityDrownRsp := &proto.SceneEntityDrownRsp{ + rsp := &proto.SceneEntityDrownRsp{ EntityId: req.EntityId, } - g.SendMsg(cmd.SceneEntityDrownRsp, player.PlayerId, player.ClientSeq, sceneEntityDrownRsp) + g.SendMsg(cmd.SceneEntityDrownRsp, player.PlayerId, player.ClientSeq, rsp) } func (g *Game) EntityForceSyncReq(player *model.Player, payloadMsg pb.Message) { @@ -1426,6 +1454,7 @@ func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player) *proto.Pl strconv.Itoa(int(player.PlayerId)) + "-" + strconv.Itoa(int(time.Now().Unix())) + "-" + strconv.Itoa(int(SceneTransactionSeq)) + // TODO 暂时先解锁全部场景标签 看着喜庆 for _, sceneTagDataConfig := range gdconf.GetSceneTagDataMap() { if uint32(sceneTagDataConfig.SceneId) == player.GetSceneId() { playerEnterSceneNotify.SceneTagIdList = append(playerEnterSceneNotify.SceneTagIdList, uint32(sceneTagDataConfig.SceneTagId)) @@ -1491,6 +1520,7 @@ func (g *Game) PacketPlayerEnterSceneNotifyCore( strconv.Itoa(int(player.PlayerId)) + "-" + strconv.Itoa(int(time.Now().Unix())) + "-" + strconv.Itoa(int(SceneTransactionSeq)) + // TODO 暂时先解锁全部场景标签 看着喜庆 for _, sceneTagDataConfig := range gdconf.GetSceneTagDataMap() { if uint32(sceneTagDataConfig.SceneId) == sceneId { playerEnterSceneNotify.SceneTagIdList = append(playerEnterSceneNotify.SceneTagIdList, uint32(sceneTagDataConfig.SceneTagId)) diff --git a/gs/game/player_world.go b/gs/game/player_world.go index 6e2dcdf3..37bad165 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -60,11 +60,11 @@ func (g *Game) SceneTransToPointReq(player *model.Player, payloadMsg pb.Message) 0, ) - sceneTransToPointRsp := &proto.SceneTransToPointRsp{ + rsp := &proto.SceneTransToPointRsp{ PointId: req.PointId, SceneId: req.SceneId, } - g.SendMsg(cmd.SceneTransToPointRsp, player.PlayerId, player.ClientSeq, sceneTransToPointRsp) + g.SendMsg(cmd.SceneTransToPointRsp, player.PlayerId, player.ClientSeq, rsp) } // UnlockTransPointReq 解锁传送点请求 @@ -108,25 +108,14 @@ func (g *Game) GetScenePointReq(player *model.Player, payloadMsg pb.Message) { g.SendError(cmd.GetScenePointRsp, player, &proto.GetScenePointRsp{}) return } - // 区域 暂时解锁全部区域 - areaIdMap := make(map[uint32]bool) - for _, worldAreaData := range gdconf.GetWorldAreaDataMap() { - if uint32(worldAreaData.SceneId) == req.SceneId { - areaIdMap[uint32(worldAreaData.AreaId1)] = true - } - } - areaIdMap[1] = true - unlockAreaList := make([]uint32, 0) - for areaId := range areaIdMap { - unlockAreaList = append(unlockAreaList, areaId) - } - getScenePointRsp := &proto.GetScenePointRsp{ + + rsp := &proto.GetScenePointRsp{ SceneId: req.SceneId, - UnlockAreaList: unlockAreaList, + UnlockAreaList: dbScene.GetUnlockAreaList(), UnlockedPointList: dbScene.GetUnlockPointList(), UnhidePointList: dbScene.GetUnHidePointList(), } - g.SendMsg(cmd.GetScenePointRsp, player.PlayerId, player.ClientSeq, getScenePointRsp) + g.SendMsg(cmd.GetScenePointRsp, player.PlayerId, player.ClientSeq, rsp) } // MarkMapReq 地图标点请求 @@ -222,24 +211,38 @@ func (g *Game) MarkMapReq(player *model.Player, payloadMsg pb.Message) { func (g *Game) GetSceneAreaReq(player *model.Player, payloadMsg pb.Message) { req := payloadMsg.(*proto.GetSceneAreaReq) - getSceneAreaRsp := &proto.GetSceneAreaRsp{ - SceneId: req.SceneId, + world := WORLD_MANAGER.GetWorldById(player.WorldId) + if world == nil { + logger.Error("get world is nil, worldId: %v, uid: %v", world.GetId(), player.PlayerId) + g.SendError(cmd.GetSceneAreaRsp, player, &proto.GetSceneAreaRsp{}) + return } - // 区域 暂时解锁全部区域 - areaIdMap := make(map[uint32]bool) - for _, worldAreaData := range gdconf.GetWorldAreaDataMap() { - if uint32(worldAreaData.SceneId) == req.SceneId { - areaIdMap[uint32(worldAreaData.AreaId1)] = true - } + owner := world.GetOwner() + if owner == nil { + logger.Error("get owner is nil, worldId: %v", world.GetId()) + g.SendError(cmd.GetSceneAreaRsp, player, &proto.GetSceneAreaRsp{}) + return } - areaIdMap[1] = true - areaList := make([]uint32, 0) - for areaId := range areaIdMap { - areaList = append(areaList, areaId) + dbWorld := owner.GetDbWorld() + if dbWorld == nil { + logger.Error("get dbWorld is nil, uid: %v", player.PlayerId) + g.SendError(cmd.GetSceneAreaRsp, player, &proto.GetSceneAreaRsp{}) + return + } + dbScene := dbWorld.GetSceneById(req.SceneId) + if dbScene == nil { + logger.Error("get dbScene is nil, sceneId: %v, uid: %v", req.SceneId, player.PlayerId) + g.SendError(cmd.GetSceneAreaRsp, player, &proto.GetSceneAreaRsp{}) + return + } + + rsp := &proto.GetSceneAreaRsp{ + SceneId: req.SceneId, + AreaIdList: dbScene.GetUnlockAreaList(), + CityInfoList: nil, } - getSceneAreaRsp.AreaIdList = areaList if req.SceneId == 3 { - getSceneAreaRsp.CityInfoList = []*proto.CityInfo{ + rsp.CityInfoList = []*proto.CityInfo{ {CityId: 1, Level: 10}, {CityId: 2, Level: 10}, {CityId: 3, Level: 10}, @@ -247,7 +250,7 @@ func (g *Game) GetSceneAreaReq(player *model.Player, payloadMsg pb.Message) { {CityId: 5, Level: 10}, } } - g.SendMsg(cmd.GetSceneAreaRsp, player.PlayerId, player.ClientSeq, getSceneAreaRsp) + g.SendMsg(cmd.GetSceneAreaRsp, player.PlayerId, player.ClientSeq, rsp) } // EnterWorldAreaReq 进入世界区域请求 @@ -257,11 +260,11 @@ func (g *Game) EnterWorldAreaReq(player *model.Player, payloadMsg pb.Message) { logger.Debug("EnterWorldAreaReq: %v", req) - enterWorldAreaRsp := &proto.EnterWorldAreaRsp{ + rsp := &proto.EnterWorldAreaRsp{ AreaType: req.AreaType, AreaId: req.AreaId, } - g.SendMsg(cmd.EnterWorldAreaRsp, player.PlayerId, player.ClientSeq, enterWorldAreaRsp) + g.SendMsg(cmd.EnterWorldAreaRsp, player.PlayerId, player.ClientSeq, rsp) } // ChangeGameTimeReq 修改游戏时间请求 @@ -288,10 +291,10 @@ func (g *Game) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) { g.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType) } - changeGameTimeRsp := &proto.ChangeGameTimeRsp{ + rsp := &proto.ChangeGameTimeRsp{ CurGameTime: scene.GetGameTime(), } - g.SendMsg(cmd.ChangeGameTimeRsp, player.PlayerId, player.ClientSeq, changeGameTimeRsp) + g.SendMsg(cmd.ChangeGameTimeRsp, player.PlayerId, player.ClientSeq, rsp) } // NpcTalkReq npc对话请求 @@ -477,8 +480,9 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) { } func (g *Game) EnterTransPointRegionNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.EnterTransPointRegionNotify) - _ = req + ntf := payloadMsg.(*proto.EnterTransPointRegionNotify) + _ = ntf + world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -499,8 +503,8 @@ func (g *Game) EnterTransPointRegionNotify(player *model.Player, payloadMsg pb.M } func (g *Game) ExitTransPointRegionNotify(player *model.Player, payloadMsg pb.Message) { - req := payloadMsg.(*proto.ExitTransPointRegionNotify) - _ = req + ntf := payloadMsg.(*proto.ExitTransPointRegionNotify) + _ = ntf } /************************************************** 游戏功能 **************************************************/ @@ -519,7 +523,7 @@ func (g *Game) UnlockPlayerTransPoint(player *model.Player, sceneId uint32, poin return proto.Retcode_RET_POINT_ALREAY_UNLOCKED } dbScene.UnlockPoint(pointId) - GAME.SendMsg(cmd.ScenePointUnlockNotify, player.PlayerId, player.ClientSeq, &proto.ScenePointUnlockNotify{ + g.SendMsg(cmd.ScenePointUnlockNotify, player.PlayerId, player.ClientSeq, &proto.ScenePointUnlockNotify{ SceneId: sceneId, PointList: []uint32{pointId}, }) @@ -527,6 +531,27 @@ func (g *Game) UnlockPlayerTransPoint(player *model.Player, sceneId uint32, poin return proto.Retcode_RET_SUCC } +// UnlockPlayerSceneArea 解锁场景区域 +func (g *Game) UnlockPlayerSceneArea(player *model.Player, sceneId uint32, areaId uint32) { + dbWorld := player.GetDbWorld() + dbScene := dbWorld.GetSceneById(sceneId) + if dbScene == nil { + logger.Error("get dbScene is nil, sceneId: %v, uid: %v", sceneId, player.PlayerId) + return + } + unlock := dbScene.CheckAreaUnlock(areaId) + if unlock { + logger.Error("area already unlock, sceneId: %v, areaId: %v, uid: %v", sceneId, areaId, player.PlayerId) + return + } + dbScene.UnlockArea(areaId) + g.SendMsg(cmd.SceneAreaUnlockNotify, player.PlayerId, player.ClientSeq, &proto.SceneAreaUnlockNotify{ + SceneId: sceneId, + AreaList: []uint32{areaId}, + }) + g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_AREA, "", int32(sceneId), int32(areaId)) +} + // ChangeGameTime 修改游戏场景时间 func (g *Game) ChangeGameTime(scene *Scene, gameTime uint32) { scene.ChangeGameTime(gameTime) diff --git a/gs/model/db_world.go b/gs/model/db_world.go index 2d5b0b74..e164b2d3 100644 --- a/gs/model/db_world.go +++ b/gs/model/db_world.go @@ -14,6 +14,7 @@ type DbScene struct { SceneId uint32 UnlockPointMap map[uint32]bool UnHidePointMap map[uint32]bool + UnlockAreaMap map[uint32]bool SceneGroupMap map[uint32]*DbSceneGroup } @@ -58,13 +59,15 @@ func (w *DbWorld) GetSceneById(sceneId uint32) *DbScene { if scene.SceneId == 0 { scene.SceneId = sceneId } - if scene.UnlockPointMap == nil { scene.UnlockPointMap = make(map[uint32]bool) } if scene.UnHidePointMap == nil { scene.UnHidePointMap = make(map[uint32]bool) } + if scene.UnlockAreaMap == nil { + scene.UnlockAreaMap = make(map[uint32]bool) + } if scene.SceneGroupMap == nil { scene.SceneGroupMap = make(map[uint32]*DbSceneGroup) } @@ -104,6 +107,33 @@ func (s *DbScene) CheckPointUnlock(pointId uint32) bool { return exist } +func (s *DbScene) GetUnlockAreaList() []uint32 { + unlockAreaList := make([]uint32, 0, len(s.UnlockAreaMap)) + for areaId := range s.UnlockAreaMap { + unlockAreaList = append(unlockAreaList, areaId) + } + return unlockAreaList +} + +func (s *DbScene) UnlockArea(areaId uint32) { + exist := false + for _, worldAreaData := range gdconf.GetWorldAreaDataMap() { + if uint32(worldAreaData.SceneId) == s.SceneId && uint32(worldAreaData.AreaId1) == areaId { + exist = true + break + } + } + if !exist { + return + } + s.UnlockAreaMap[areaId] = true +} + +func (s *DbScene) CheckAreaUnlock(areaId uint32) bool { + _, exist := s.UnlockAreaMap[areaId] + return exist +} + func (s *DbScene) GetSceneGroupById(groupId uint32) *DbSceneGroup { dbSceneGroup, exist := s.SceneGroupMap[groupId] if !exist { diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index 0410980e..a2a61fe9 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -164,6 +164,7 @@ func (c *CmdProtoMap) registerMessage() { 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(SceneAreaUnlockNotify, func() any { return new(proto.SceneAreaUnlockNotify) }) // 场景区域解锁通知 // 战斗与同步 c.regMsg(AvatarFightPropNotify, func() any { return new(proto.AvatarFightPropNotify) }) // 角色战斗属性通知 @@ -324,6 +325,7 @@ func (c *CmdProtoMap) registerMessage() { c.regMsg(UnlockAvatarTalentReq, func() any { return new(proto.UnlockAvatarTalentReq) }) // 角色命座解锁请求 c.regMsg(UnlockAvatarTalentRsp, func() any { return new(proto.UnlockAvatarTalentRsp) }) // 角色命座解锁通知 c.regMsg(AvatarUnlockTalentNotify, func() any { return new(proto.AvatarUnlockTalentNotify) }) // 角色命座解锁通知 + c.regMsg(AddNoGachaAvatarCardNotify, func() any { return new(proto.AddNoGachaAvatarCardNotify) }) // 获得非抽卡角色通知 // 背包与道具 c.regMsg(PlayerStoreNotify, func() any { return new(proto.PlayerStoreNotify) }) // 玩家背包数据通知 @@ -411,6 +413,7 @@ func (c *CmdProtoMap) registerMessage() { c.regMsg(QuestDestroyEntityRsp, func() any { return new(proto.QuestDestroyEntityRsp) }) // 任务销毁实体响应 c.regMsg(QuestDestroyNpcReq, func() any { return new(proto.QuestDestroyNpcReq) }) // 任务销毁npc请求 c.regMsg(QuestDestroyNpcRsp, func() any { return new(proto.QuestDestroyNpcRsp) }) // 任务销毁npc响应 + c.regMsg(ChapterStateNotify, func() any { return new(proto.ChapterStateNotify) }) // 任务章节状态通知 // TODO 家园 c.regMsg(GetPlayerHomeCompInfoReq, func() any { return new(proto.GetPlayerHomeCompInfoReq) })