diff --git a/common/constant/quest_type.go b/common/constant/quest_type.go index 31d78f87..d020a922 100644 --- a/common/constant/quest_type.go +++ b/common/constant/quest_type.go @@ -8,6 +8,13 @@ const ( QUEST_STATE_FAILED = 4 ) +const ( + PARENT_QUEST_STATE_NONE = 0 + PARENT_QUEST_STATE_FINISHED = 1 + PARENT_QUEST_STATE_FAILED = 2 + PARENT_QUEST_STATE_CANCELED = 3 +) + const ( QUEST_LOGIC_TYPE_NONE = 0 QUEST_LOGIC_TYPE_AND = 1 diff --git a/common/constant/refresh_type.go b/common/constant/refresh_type.go new file mode 100644 index 00000000..b6cf5311 --- /dev/null +++ b/common/constant/refresh_type.go @@ -0,0 +1,9 @@ +package constant + +const ( + REFRESH_NONE = 0 + REFRESH_INTERVAL = 1 + REFRESH_DAILY = 2 + REFRESH_WEEKlY = 3 + REFRESH_DAYBEGIN_INTERVAL = 4 +) diff --git a/gdconf/chapter_data.go b/gdconf/chapter_data.go new file mode 100644 index 00000000..7f346207 --- /dev/null +++ b/gdconf/chapter_data.go @@ -0,0 +1,36 @@ +package gdconf + +import ( + "hk4e/pkg/logger" +) + +// ChapterData 章节配置表 +type ChapterData struct { + ChapterId int32 `csv:"章节ID"` + StartQuestId int32 `csv:"开始子任务,omitempty"` + EndQuestId int32 `csv:"结束子任务,omitempty"` +} + +func (g *GameDataConfig) loadChapterData() { + g.ChapterDataMap = make(map[int32]*ChapterData) + fileNameList := []string{ + "ChapterData.txt", + "ChapterData_Exported.txt", + } + for _, fileName := range fileNameList { + chapterDataList := make([]*ChapterData, 0) + readTable[ChapterData](g.txtPrefix+fileName, &chapterDataList) + for _, chapterData := range chapterDataList { + g.ChapterDataMap[chapterData.ChapterId] = chapterData + } + } + logger.Info("ChapterData Count: %v", len(g.ChapterDataMap)) +} + +func GetChapterDataById(chapterId int32) *ChapterData { + return CONF.ChapterDataMap[chapterId] +} + +func GetChapterDataMap() map[int32]*ChapterData { + return CONF.ChapterDataMap +} diff --git a/gdconf/game_data_config.go b/gdconf/game_data_config.go index 88f78725..446e7980 100644 --- a/gdconf/game_data_config.go +++ b/gdconf/game_data_config.go @@ -89,6 +89,8 @@ type GameDataConfig struct { ReliquaryLevelDataMap map[int32]map[int32]*ReliquaryLevelData // 圣遗物等级 MonsterCurveDataMap map[int32]*MonsterCurveData // 怪物曲线 WidgetJsonConfigMap map[string]*ConfigWidget // 小道具JSON配置 + ChapterDataMap map[int32]*ChapterData // 章节 + MainQuestDataMap map[int32]*MainQuestData // 主线任务 } func InitGameDataConfig() { @@ -206,6 +208,8 @@ func (g *GameDataConfig) load(loadSceneLua bool) { g.loadReliquaryLevelData() // 圣遗物等级 g.loadMonsterCurveData() // 怪物曲线 g.loadWidgetJsonConfig() // 小道具JSON配置 + g.loadChapterData() // 章节 + g.loadMainQuestData() // 主线任务 if g.loadExt { g.loadGachaDropGroupData() // 卡池掉落组 临时的 g.loadPubgWorldGadgetData() // pubg世界物件 diff --git a/gdconf/main_quest_data.go b/gdconf/main_quest_data.go new file mode 100644 index 00000000..c64dc806 --- /dev/null +++ b/gdconf/main_quest_data.go @@ -0,0 +1,50 @@ +package gdconf + +import ( + "hk4e/pkg/logger" + "strconv" + "strings" +) + +// MainQuestData 主线任务配置表 +type MainQuestData struct { + ParentQuestId int32 `csv:"父任务ID"` + QuestReward string `csv:"任务奖励RewardID,omitempty"` + VideoKey uint64 `csv:"VideoKey,omitempty"` + + RewardIdList []int32 +} + +func (g *GameDataConfig) loadMainQuestData() { + g.MainQuestDataMap = make(map[int32]*MainQuestData) + fileNameList := []string{ + "MainQuestData.txt", + "MainQuestData_Exported.txt", + } + for _, fileName := range fileNameList { + mainQuestDataList := make([]*MainQuestData, 0) + readTable[MainQuestData](g.txtPrefix+fileName, &mainQuestDataList) + for _, mainQuestData := range mainQuestDataList { + mainQuestData.RewardIdList = make([]int32, 0) + if mainQuestData.QuestReward != "" { + for _, rewardIdStr := range strings.Split(mainQuestData.QuestReward, ",") { + rewardId, err := strconv.Atoi(rewardIdStr) + if err != nil { + panic(err) + } + mainQuestData.RewardIdList = append(mainQuestData.RewardIdList, int32(rewardId)) + } + } + g.MainQuestDataMap[mainQuestData.ParentQuestId] = mainQuestData + } + } + logger.Info("MainQuestData Count: %v", len(g.MainQuestDataMap)) +} + +func GetMainQuestDataById(parentQuestId int32) *MainQuestData { + return CONF.MainQuestDataMap[parentQuestId] +} + +func GetMainQuestDataMap() map[int32]*MainQuestData { + return CONF.MainQuestDataMap +} diff --git a/gdconf/monster_data.go b/gdconf/monster_data.go index 37c99fc6..b87ca1c3 100644 --- a/gdconf/monster_data.go +++ b/gdconf/monster_data.go @@ -3,6 +3,8 @@ package gdconf import ( "fmt" "os" + "strconv" + "strings" "hk4e/common/constant" "hk4e/pkg/logger" @@ -21,6 +23,7 @@ type MonsterData struct { MonsterId int32 `csv:"ID"` Name string `csv:"名称$text_name_Name,omitempty"` ConfigJson string `csv:"战斗Config,omitempty"` + Affix string `csv:"精英词缀,omitempty"` // 战斗属性 HpBase float32 `csv:"基础生命值,omitempty"` AttackBase float32 `csv:"基础攻击力,omitempty"` @@ -64,6 +67,7 @@ type MonsterData struct { PropGrowList []*PropGrow // 属性成长列表 HpDropList []*HpDrop // 血量掉落列表 ConfigAbility *ConfigAbilityJson // 能力配置 + AffixList []int32 // 词缀列表 } func (g *GameDataConfig) loadMonsterData() { @@ -261,6 +265,15 @@ func (g *GameDataConfig) loadMonsterData() { HpPercent: monsterData.Drop3HpPercent, }) } + if monsterData.Affix != "" { + for _, affixStr := range strings.Split(monsterData.Affix, ",") { + affix, err := strconv.Atoi(affixStr) + if err != nil { + panic(err) + } + monsterData.AffixList = append(monsterData.AffixList, int32(affix)) + } + } g.MonsterDataMap[monsterData.MonsterId] = monsterData } logger.Info("MonsterData Count: %v", len(g.MonsterDataMap)) diff --git a/gdconf/refresh_policy_data.go b/gdconf/refresh_policy_data.go index f2565575..64aa8cb9 100644 --- a/gdconf/refresh_policy_data.go +++ b/gdconf/refresh_policy_data.go @@ -2,20 +2,13 @@ package gdconf import ( "fmt" + "hk4e/common/constant" "strconv" "strings" "hk4e/pkg/logger" ) -const ( - RefreshTypeNone = 0 - RefreshTypeAfterTime = 1 - RefreshTypeDayTime = 2 - RefreshTypeDayTimeRange = 3 - RefreshTypeDay = 4 -) - // RefreshPolicyData 刷新策略配置表 type RefreshPolicyData struct { RefreshId int32 `csv:"刷新ID"` @@ -31,11 +24,11 @@ func (g *GameDataConfig) loadRefreshPolicyData() { refreshPolicyDataList := make([]*RefreshPolicyData, 0) readTable[RefreshPolicyData](g.txtPrefix+"RefreshPolicyData.txt", &refreshPolicyDataList) for _, refreshPolicyData := range refreshPolicyDataList { - if refreshPolicyData.RefreshType < RefreshTypeNone || refreshPolicyData.RefreshType > RefreshTypeDay { + if refreshPolicyData.RefreshType < constant.REFRESH_NONE || refreshPolicyData.RefreshType > constant.REFRESH_DAYBEGIN_INTERVAL { info := fmt.Sprintf("invalid refresh type: %v", refreshPolicyData) panic(info) } - if refreshPolicyData.RefreshType == RefreshTypeDayTimeRange { + if refreshPolicyData.RefreshType == constant.REFRESH_WEEKlY { split := strings.Split(refreshPolicyData.RefreshTimeStr, ";") if len(split) != 2 { info := fmt.Sprintf("refresh time format error: %v", refreshPolicyData) @@ -50,7 +43,7 @@ func (g *GameDataConfig) loadRefreshPolicyData() { panic(err) } refreshPolicyData.RefreshTimeRange = [2]int32{int32(startTime), int32(endTime)} - } else if refreshPolicyData.RefreshType == RefreshTypeNone { + } else if refreshPolicyData.RefreshType == constant.REFRESH_NONE { refreshPolicyData.RefreshTime = 0 } else { refreshTime, err := strconv.Atoi(refreshPolicyData.RefreshTimeStr) diff --git a/gs/game/player_avatar.go b/gs/game/player_avatar.go index 7687a881..986e4a45 100644 --- a/gs/game/player_avatar.go +++ b/gs/game/player_avatar.go @@ -211,27 +211,17 @@ func (g *Game) AvatarPromoteGetRewardReq(player *model.Player, payloadMsg pb.Mes g.SendError(cmd.AvatarPromoteGetRewardRsp, player, &proto.AvatarPromoteGetRewardRsp{}, proto.Retcode_RET_REWARD_HAS_TAKEN) return } - // 获取奖励配置表 - rewardConfig := gdconf.GetRewardDataById(int32(avatarDataConfig.PromoteRewardMap[req.PromoteLevel])) - if rewardConfig == nil { - logger.Error("reward config error, rewardId: %v", avatarDataConfig.PromoteRewardMap[req.PromoteLevel]) + // 发放奖励 + rewardId := avatarDataConfig.PromoteRewardMap[req.PromoteLevel] + ok = g.RewardItem(player.PlayerId, rewardId, proto.ActionReasonType_ACTION_REASON_AVATAR_PROMOTE) + if !ok { g.SendError(cmd.AvatarPromoteGetRewardRsp, player, &proto.AvatarPromoteGetRewardRsp{}) return } // 设置该奖励为已被获取状态 avatar.PromoteRewardMap[req.PromoteLevel] = true - // 给予突破奖励 - rewardItemList := make([]*ChangeItem, 0, len(rewardConfig.RewardItemMap)) - for itemId, count := range rewardConfig.RewardItemMap { - rewardItemList = append(rewardItemList, &ChangeItem{ - ItemId: itemId, - ChangeCount: count, - }) - } - g.AddPlayerItem(player.PlayerId, rewardItemList, proto.ActionReasonType_ACTION_REASON_AVATAR_PROMOTE) - avatarPromoteGetRewardRsp := &proto.AvatarPromoteGetRewardRsp{ - RewardId: uint32(rewardConfig.RewardId), + RewardId: rewardId, AvatarGuid: req.AvatarGuid, PromoteLevel: req.PromoteLevel, } diff --git a/gs/game/player_item.go b/gs/game/player_item.go index 221d495c..9515f09a 100644 --- a/gs/game/player_item.go +++ b/gs/game/player_item.go @@ -380,6 +380,24 @@ func (g *Game) CostPlayerItem(userId uint32, itemList []*ChangeItem) bool { return true } +// RewardItem 奖励玩家物品 +func (g *Game) RewardItem(userId uint32, rewardId uint32, hintReason proto.ActionReasonType) bool { + rewardConfig := gdconf.GetRewardDataById(int32(rewardId)) + if rewardConfig == nil { + logger.Error("reward config error, rewardId: %v", rewardId) + return false + } + rewardItemList := make([]*ChangeItem, 0, len(rewardConfig.RewardItemMap)) + for itemId, count := range rewardConfig.RewardItemMap { + rewardItemList = append(rewardItemList, &ChangeItem{ + ItemId: itemId, + ChangeCount: count, + }) + } + g.AddPlayerItem(userId, rewardItemList, hintReason) + return true +} + /************************************************** 打包封装 **************************************************/ // PacketStoreWeightLimitNotify 背包容量限制通知 diff --git a/gs/game/player_quest.go b/gs/game/player_quest.go index 8848432b..02135b31 100644 --- a/gs/game/player_quest.go +++ b/gs/game/player_quest.go @@ -4,8 +4,6 @@ import ( "strconv" "strings" - "hk4e/pkg/object" - "hk4e/common/constant" "hk4e/gdconf" "hk4e/gs/model" @@ -250,13 +248,6 @@ func (g *Game) AcceptQuest(player *model.Player, notify bool) { // TODO 由于风龙任务进入秘境客户端会无限重连相关原因暂时屏蔽 g.SendPrivateChat(COMMAND_MANAGER.system, player.PlayerId, "quest finish 35722") } - 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)) } @@ -289,15 +280,17 @@ func (g *Game) StartQuest(player *model.Player, questId uint32, notify bool) { g.QuestStartTriggerCheck(player, questId) if notify { - ntf := &proto.QuestListUpdateNotify{ - QuestList: make([]*proto.Quest, 0), + g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerId, player.ClientSeq, &proto.QuestListUpdateNotify{ + QuestList: []*proto.Quest{g.PacketQuest(player, questId)}, + }) + for _, chapterDataConfig := range gdconf.GetChapterDataMap() { + if uint32(chapterDataConfig.StartQuestId) == questId { + g.SendMsg(cmd.ChapterStateNotify, player.PlayerId, player.ClientSeq, &proto.ChapterStateNotify{ + ChapterState: proto.ChapterState_CHAPTER_STATE_BEGIN, + ChapterId: uint32(chapterDataConfig.ChapterId), + }) + } } - pbQuest := g.PacketQuest(player, questId) - if pbQuest == nil { - return - } - ntf.QuestList = append(ntf.QuestList, pbQuest) - g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerId, player.ClientSeq, ntf) } // 任务开始时主动触发检测是否完成 @@ -666,33 +659,13 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerId, player.ClientSeq, &proto.QuestListUpdateNotify{ QuestList: questList, }) - // 更新客户端父任务 - parentQuestList := g.PacketParentQuestList(player, object.ConvMapKeyToList[uint32, struct{}](updateQuestIdMap)) - if len(parentQuestList) > 0 { - g.SendMsg(cmd.FinishedParentQuestUpdateNotify, player.PlayerId, player.ClientSeq, &proto.FinishedParentQuestUpdateNotify{ - ParentQuestList: parentQuestList, - }) - } // 任务事件 for questId := range updateQuestIdMap { quest := dbQuest.GetQuestById(questId) if quest.State == constant.QUEST_STATE_FINISHED { - // 任务完成执行 - g.ExecQuest(player, quest.QuestId, QuestExecTypeFinish) - // 任务完成发奖 - questDataConfig := gdconf.GetQuestDataById(int32(quest.QuestId)) - if questDataConfig == nil { - continue - } - if len(questDataConfig.ItemIdList) != 0 { - for index, itemId := range questDataConfig.ItemIdList { - questItem := []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(questDataConfig.ItemCountList[index])}} - g.AddPlayerItem(player.PlayerId, questItem, proto.ActionReasonType_ACTION_REASON_QUEST_ITEM) - } - } + g.FinishQuest(player, quest.QuestId) } else if quest.State == constant.QUEST_STATE_FAILED { - // 任务失败执行 - g.ExecQuest(player, quest.QuestId, QuestExecTypeFail) + g.FailQuest(player, quest.QuestId) } } g.AcceptQuest(player, true) @@ -700,6 +673,56 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin } } +// FinishQuest 完成任务 +func (g *Game) FinishQuest(player *model.Player, questId uint32) { + // 任务完成执行 + g.ExecQuest(player, questId, QuestExecTypeFinish) + // 任务完成发奖 + questDataConfig := gdconf.GetQuestDataById(int32(questId)) + if questDataConfig == nil { + return + } + if len(questDataConfig.ItemIdList) != 0 { + for index, itemId := range questDataConfig.ItemIdList { + questItem := []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(questDataConfig.ItemCountList[index])}} + g.AddPlayerItem(player.PlayerId, questItem, proto.ActionReasonType_ACTION_REASON_QUEST_ITEM) + } + } + dbQuest := player.GetDbQuest() + parentQuest := dbQuest.GetParentQuestById(uint32(questDataConfig.ParentQuestId)) + if parentQuest == nil { + return + } + if parentQuest.State == constant.PARENT_QUEST_STATE_FINISHED { + // 父任务完成发奖 + mainQuestDataConfig := gdconf.GetMainQuestDataById(questDataConfig.ParentQuestId) + if mainQuestDataConfig == nil { + return + } + for _, rewardId := range mainQuestDataConfig.RewardIdList { + g.RewardItem(player.PlayerId, uint32(rewardId), proto.ActionReasonType_ACTION_REASON_QUEST_ITEM) + } + // 更新客户端父任务 + g.SendMsg(cmd.FinishedParentQuestUpdateNotify, player.PlayerId, player.ClientSeq, &proto.FinishedParentQuestUpdateNotify{ + ParentQuestList: g.PacketParentQuestList(player, []uint32{parentQuest.ParentQuestId}), + }) + } + for _, chapterDataConfig := range gdconf.GetChapterDataMap() { + if uint32(chapterDataConfig.EndQuestId) == questId { + g.SendMsg(cmd.ChapterStateNotify, player.PlayerId, player.ClientSeq, &proto.ChapterStateNotify{ + ChapterState: proto.ChapterState_CHAPTER_STATE_END, + ChapterId: uint32(chapterDataConfig.ChapterId), + }) + } + } +} + +// FailQuest 失败任务 +func (g *Game) FailQuest(player *model.Player, questId uint32) { + // 任务失败执行 + g.ExecQuest(player, questId, QuestExecTypeFail) +} + /************************************************** 打包封装 **************************************************/ // PacketQuest 打包一个任务 @@ -746,59 +769,46 @@ func (g *Game) PacketQuestListNotify(player *model.Player) *proto.QuestListNotif // PacketFinishedParentQuestNotify 打包已完成父任务列表通知 func (g *Game) PacketFinishedParentQuestNotify(player *model.Player) *proto.FinishedParentQuestNotify { dbQuest := player.GetDbQuest() - questIdList := make([]uint32, len(dbQuest.QuestMap)) - for questId := range dbQuest.GetQuestMap() { - questIdList = append(questIdList, questId) + parentQuestIdList := make([]uint32, len(dbQuest.GetParentQuestMap())) + for _, parentQuest := range dbQuest.GetParentQuestMap() { + if parentQuest.State != constant.PARENT_QUEST_STATE_FINISHED { + continue + } + parentQuestIdList = append(parentQuestIdList, parentQuest.ParentQuestId) } ntf := &proto.FinishedParentQuestNotify{ - ParentQuestList: g.PacketParentQuestList(player, questIdList), + ParentQuestList: g.PacketParentQuestList(player, parentQuestIdList), } return ntf } -func (g *Game) PacketParentQuestList(player *model.Player, questIdList []uint32) []*proto.ParentQuest { - dbQuest := player.GetDbQuest() - parentQuestIdMap := make(map[int32]bool) +func (g *Game) PacketParentQuestList(player *model.Player, parentQuestIdList []uint32) []*proto.ParentQuest { parentQuestList := make([]*proto.ParentQuest, 0) - for questId := range questIdList { - questDataConfig := gdconf.GetQuestDataById(int32(questId)) - if questDataConfig == nil { + dbQuest := player.GetDbQuest() + for _, parentQuestId := range parentQuestIdList { + parentQuest := dbQuest.GetParentQuestById(parentQuestId) + if parentQuest == nil { continue } - _, exist := parentQuestIdMap[questDataConfig.ParentQuestId] - if exist { - continue - } - parentQuestIdMap[questDataConfig.ParentQuestId] = true - finishedParentQuest := true - subQuestDataMap := gdconf.GetQuestDataMapByParentQuestId(questDataConfig.ParentQuestId) - for _, subQuestData := range subQuestDataMap { - quest := dbQuest.GetQuestById(uint32(subQuestData.QuestId)) + childQuestList := make([]*proto.ChildQuest, 0) + questDataMap := gdconf.GetQuestDataMapByParentQuestId(int32(parentQuestId)) + for _, questDataConfig := range questDataMap { + quest := dbQuest.GetQuestById(uint32(questDataConfig.QuestId)) if quest == nil { - finishedParentQuest = false - break + continue } - if quest.State != constant.QUEST_STATE_FINISHED { - finishedParentQuest = false - break - } - } - if finishedParentQuest { - childQuestList := make([]*proto.ChildQuest, 0) - for _, subQuestData := range subQuestDataMap { - childQuestList = append(childQuestList, &proto.ChildQuest{ - State: constant.QUEST_STATE_FINISHED, - QuestId: uint32(subQuestData.QuestId), - }) - } - parentQuestList = append(parentQuestList, &proto.ParentQuest{ - ParentQuestId: uint32(questDataConfig.ParentQuestId), - ParentQuestState: 1, - IsFinished: true, - ChildQuestList: childQuestList, - QuestVar: make([]int32, 5), + childQuestList = append(childQuestList, &proto.ChildQuest{ + State: uint32(quest.State), + QuestId: quest.QuestId, }) } + parentQuestList = append(parentQuestList, &proto.ParentQuest{ + ParentQuestId: parentQuest.ParentQuestId, + ParentQuestState: uint32(parentQuest.State), + IsFinished: parentQuest.State == constant.PARENT_QUEST_STATE_FINISHED, + ChildQuestList: childQuestList, + QuestVar: parentQuest.QuestVar[:], + }) } return parentQuestList } diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index b6784f5d..cd65bae9 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -2155,6 +2155,7 @@ func (g *Game) PacketSceneMonsterInfo(entity IEntity) *proto.SceneMonsterInfo { blockId := uint32(0) titleId := uint32(0) specialNameId := uint32(0) + affixList := make([]uint32, 0) if entity.GetGroupId() != 0 { groupConfig := gdconf.GetSceneGroup(int32(entity.GetGroupId())) if groupConfig == nil { @@ -2169,6 +2170,14 @@ func (g *Game) PacketSceneMonsterInfo(entity IEntity) *proto.SceneMonsterInfo { } titleId = uint32(monsterConfig.TitleId) specialNameId = uint32(monsterConfig.SpecialNameId) + monsterDataConfig := gdconf.GetMonsterDataById(monsterConfig.MonsterId) + if monsterDataConfig == nil { + logger.Error("monster data config not exist, monsterId: %v", monsterConfig.MonsterId) + return new(proto.SceneMonsterInfo) + } + for _, affix := range monsterDataConfig.AffixList { + affixList = append(affixList, uint32(affix)) + } } sceneMonsterInfo := &proto.SceneMonsterInfo{ MonsterId: entity.(*MonsterEntity).GetMonsterId(), @@ -2177,6 +2186,7 @@ func (g *Game) PacketSceneMonsterInfo(entity IEntity) *proto.SceneMonsterInfo { BlockId: blockId, TitleId: titleId, SpecialNameId: specialNameId, + AffixList: affixList, } return sceneMonsterInfo } diff --git a/gs/model/db_quest.go b/gs/model/db_quest.go index 4b7ffceb..8840d47e 100644 --- a/gs/model/db_quest.go +++ b/gs/model/db_quest.go @@ -10,7 +10,8 @@ import ( // DbQuest 玩家任务数据 type DbQuest struct { - QuestMap map[uint32]*Quest // 任务列表 key:任务id value:任务 + QuestMap map[uint32]*Quest // 任务列表 key:任务id value:任务 + ParentQuestMap map[uint32]*ParentQuest // 父任务列表 key:父任务id value:父任务 } // Quest 任务 @@ -22,6 +23,13 @@ type Quest struct { FinishCountList []uint32 // 任务完成进度 } +// ParentQuest 父任务 +type ParentQuest struct { + ParentQuestId uint32 // 父任务id + State uint8 // 任务状态 + QuestVar [5]int32 // 任务变量 +} + func (p *Player) GetDbQuest() *DbQuest { if p.DbQuest == nil { p.DbQuest = new(DbQuest) @@ -29,6 +37,9 @@ func (p *Player) GetDbQuest() *DbQuest { if p.DbQuest.QuestMap == nil { p.DbQuest.QuestMap = make(map[uint32]*Quest) } + if p.DbQuest.ParentQuestMap == nil { + p.DbQuest.ParentQuestMap = make(map[uint32]*ParentQuest) + } return p.DbQuest } @@ -61,6 +72,7 @@ func (q *DbQuest) AddQuest(questId uint32) { StartTime: 0, FinishCountList: make([]uint32, len(questDataConfig.FinishCondList)), } + q.AddParentQuest(uint32(questDataConfig.ParentQuestId)) } // StartQuest 开始执行一个任务 @@ -215,6 +227,7 @@ func (q *DbQuest) CheckQuestFinish(questId uint32) { } if finish { quest.State = constant.QUEST_STATE_FINISHED + q.CheckParentQuestFinish(uint32(questDataConfig.ParentQuestId)) } } @@ -226,6 +239,12 @@ func (q *DbQuest) ForceFinishQuest(questId uint32) { return } quest.State = constant.QUEST_STATE_FINISHED + questDataConfig := gdconf.GetQuestDataById(int32(questId)) + if questDataConfig == nil { + logger.Error("get quest data config is nil, questId: %v", questId) + return + } + q.CheckParentQuestFinish(uint32(questDataConfig.ParentQuestId)) } // FailQuest 失败一个任务 @@ -246,3 +265,61 @@ func (q *DbQuest) FailQuest(questId uint32) { } quest.FinishCountList = make([]uint32, len(questDataConfig.FinishCondList)) } + +// GetParentQuestMap 获取全部父任务 +func (q *DbQuest) GetParentQuestMap() map[uint32]*ParentQuest { + return q.ParentQuestMap +} + +// GetParentQuestById 获取一个父任务 +func (q *DbQuest) GetParentQuestById(parentQuestId uint32) *ParentQuest { + return q.ParentQuestMap[parentQuestId] +} + +// AddParentQuest 添加一个父任务 +func (q *DbQuest) AddParentQuest(parentQuestId uint32) { + _, exist := q.ParentQuestMap[parentQuestId] + if exist { + return + } + q.ParentQuestMap[parentQuestId] = &ParentQuest{ + ParentQuestId: parentQuestId, + State: constant.PARENT_QUEST_STATE_NONE, + QuestVar: [5]int32{0, 0, 0, 0, 0}, + } +} + +// CheckParentQuestFinish 检查父任务是否完成 +func (q *DbQuest) CheckParentQuestFinish(parentQuestId uint32) { + parentQuest, exist := q.ParentQuestMap[parentQuestId] + if !exist { + logger.Error("get parent quest is nil, parentQuestId: %v", parentQuestId) + return + } + finish := true + questDataMap := gdconf.GetQuestDataMapByParentQuestId(int32(parentQuestId)) + for _, questData := range questDataMap { + quest, exist := q.QuestMap[uint32(questData.QuestId)] + if !exist { + finish = false + break + } + if quest.State != constant.QUEST_STATE_FINISHED { + finish = false + break + } + } + if finish { + parentQuest.State = constant.PARENT_QUEST_STATE_FINISHED + } +} + +// ForceFinishParentQuest 强制完成一个父任务 +func (q *DbQuest) ForceFinishParentQuest(parentQuestId uint32) { + parentQuest, exist := q.ParentQuestMap[parentQuestId] + if !exist { + logger.Error("get parent quest is nil, parentQuestId: %v", parentQuestId) + return + } + parentQuest.State = constant.PARENT_QUEST_STATE_FINISHED +}