| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package mapPlayer
- import (
- capp "f1-game/internal/cherry_app"
- "f1-game/internal/code"
- "f1-game/internal/data"
- "f1-game/internal/enum"
- nameActor "f1-game/internal/name/actor"
- nameLocal "f1-game/internal/name/local"
- nameRemote "f1-game/internal/name/remote"
- "f1-game/internal/pb"
- "f1-game/internal/sessions"
- ao "f1-game/nodes/game/player/asset/origin"
- "f1-game/nodes/map/internal/db"
- dbMapPlayer "f1-game/nodes/map/internal/db/data/player"
- mapFacade "f1-game/nodes/map/internal/facade"
- mainQuest "f1-game/nodes/map/player/main_quest"
- "f1-game/nodes/map/player/quest"
- cfacade "github.com/cherry-game/cherry/facade"
- cproto "github.com/cherry-game/cherry/net/proto"
- )
- func (p *actorPlayer) initQuest() {
- p.Local().Register(nameLocal.MapPlayer_QuestReward, p.questReward)
- p.Local().Register(nameLocal.MapPlayer_QuestChapterReward, p.questChapterReward)
- p.Local().Register(nameLocal.MapPlayer_LeagueQuestReward, p.leagueQuestReward)
- p.Remote().Register(nameRemote.MapPlayer_QuestEvent, p.questEvent)
- //quest.Service().InitEvents(p.Event(), p.playerID)
- }
- // getReward 获取任务奖励 map.player.questReward
- func (p *actorPlayer) questReward(session *cproto.Session, req *pb.I32) {
- if req.Value < 1 {
- p.ResponseCode(session, code.IllegalArgument)
- return
- }
- var (
- questID = req.Value // quest id
- playerID = sessions.GetPlayerID(session) // player id
- playerTable = db.GetMapPlayerTable(playerID) // player table
- changeList []*dbMapPlayer.Quest // change list
- )
- questEntity, found := playerTable.Quests.GetQuest(questID)
- if !found {
- p.ResponseCode(session, code.QuestNotFound)
- return
- }
- // 任务已结束,不能领取
- if questEntity.Status == enum.QuestStatus_End {
- p.ResponseCode(session, code.QuestFinish)
- return
- }
- // 任务未完成,不能领取
- if questEntity.Status != enum.QuestStatus_Finish {
- p.ResponseCode(session, code.QuestNotFinished)
- return
- }
- // 任务配置未找到
- questRow, ok := data.Quest.GetByQuestGroupIDQuestID(questEntity.QuestGroupID, questID)
- if !ok {
- p.ResponseCode(session, code.ConfigNotFound_Quest)
- return
- }
- // 任务修改为已结束
- questEntity.Status = enum.QuestStatus_End
- if questRow.NextQuestID > 0 {
- // 如果有下一个任务,则添加
- nextQuestRow, _ := data.Quest.GetByQuestGroupIDQuestID(questRow.QuestGroupID, questRow.NextQuestID)
- nextQuestEntity, ok := quest.Service().AddQuest(playerTable, nextQuestRow)
- if ok {
- // 确保下一个任务添加成功后且需要删除上一个任务时 才删除上一个任务
- groupRow, ok := data.QuestGroup.GetByGroupID(questRow.QuestGroupID)
- if ok && groupRow.RemoveFinished {
- playerTable.Quests.DeleteQuest(questID)
- }
- changeList = append(changeList, nextQuestEntity)
- }
- }
- //save
- playerTable.Save2Queue()
- // change list
- changeList = append(changeList, questEntity)
- // 有奖励则发放奖励
- if len(questRow.Rewards) > 0 {
- _, errCode := mapFacade.Storage.AssetAdds(playerID, questRow.Rewards, ao.QuestReward)
- if code.IsFail(errCode) {
- p.Warn("[questReward] error. playerID = %d, questRow = %v", p.playerID, questRow)
- }
- }
- quest.Service().ChangePushWithSession(session, changeList)
- p.ResponseCode(session, code.OK)
- }
- // 领取主线章节奖励 // TODO 默认当前只有主线章节任务 如果后面有其他的类型再扩展
- func (p *actorPlayer) questChapterReward(session *cproto.Session, req *pb.I32) {
- mainChapterID := req.Value
- if mainChapterID < 1 {
- p.ResponseCode(session, code.RequestParamsError)
- return
- }
- mainChapterRow, found := data.MapMainQuest.GetByChapterID(mainChapterID)
- if !found {
- p.ResponseCode(session, code.MainChapterConfigNotFound)
- return
- }
- // 章节奖励
- if len(mainChapterRow.ChapterRewards) < 1 {
- p.ResponseCode(session, code.QuestGroupRewardNotExist)
- return
- }
- var (
- playerTable = db.GetMapPlayerTable(p.playerID)
- curMainChapterID = playerTable.MainChapterID
- isMainReward = playerTable.IsMainReward
- )
- // 章节奖励已领取
- if mainChapterID < curMainChapterID || isMainReward {
- p.ResponseCode(session, code.MainChapterRewardGot)
- return
- }
- // 分组任务未开启
- if mainChapterID > curMainChapterID {
- p.ResponseCode(session, code.MainChapterNotOpen)
- return
- }
- // 获取当前分组任务的任务ID列表 来判断是否所有任务都已完成
- questIDs, found := data.Quest.GetQuestIDsWithGroupID(mainChapterRow.QuestGroupID)
- if !found {
- p.ResponseCode(session, code.QuestNotFound)
- return
- }
- // 存在未完成/领取的任务,则不允许领取章节奖励
- if end := playerTable.Quests.CheckQuestsEnd(questIDs...); !end {
- p.ResponseCode(session, code.QuestNotFinished)
- return
- }
- // 发放章节奖励
- _, errCode := mapFacade.Storage.AssetAdds(p.playerID, mainChapterRow.ChapterRewards, ao.QuestChapterReward)
- if code.IsFail(errCode) {
- p.ResponseCode(session, errCode)
- return
- }
- // 设置当前章节奖励已领取
- playerTable.IsMainReward = true
- // 检测添加下一个任务组任务
- mainQuest.Service().CheckAddNextMainChapterQuest(playerTable)
- playerTable.Save2Queue()
- resp := &pb.QuestChapterReward{
- ChapterID: playerTable.MainChapterID,
- IsMainReward: playerTable.IsMainReward,
- }
- p.Response(session, resp)
- }
- // 联盟任务领取
- func (p *actorPlayer) leagueQuestReward(session *cproto.Session, req *pb.I32) {
- var (
- questID = req.Value
- playerTable = db.GetMapPlayerTable(p.playerID)
- leagueID = playerTable.LeagueID
- )
- questRow, found := data.Quest.GetByQuestID(questID)
- if !found {
- p.ResponseCode(session, code.QuestNotFound)
- return
- }
- if leagueID <= 0 {
- p.ResponseCode(session, code.LeagueNotJoin)
- return
- }
- // 任务已领取
- if got := playerTable.Quests.CheckLeagueQuestReward(questID); got {
- p.ResponseCode(session, code.QuestFinish)
- return
- }
- // 去联盟检测是否能领取奖励
- checkReq := &pb.I32{Value: questID}
- targetPath := cfacade.NewChildPath(capp.NodeID(), nameActor.Map_League, leagueID)
- errCode := p.CallWait(targetPath, nameRemote.MapLeague_QuestCheck, checkReq, nil)
- if code.IsFail(errCode) {
- p.ResponseCode(session, errCode)
- return
- }
- // 领取奖励
- _, errCode = mapFacade.Storage.AssetAdds(p.playerID, questRow.Rewards, ao.LeagueQuestReward)
- if code.IsFail(errCode) {
- p.Warn("[leagueQuestReward] error. playerID = %d, questRow = %v", p.playerID, questRow)
- return
- }
- playerTable.Quests.AddLeagueQuestID(questID)
- playerTable.Save2Queue()
- resp := &pb.I32{
- Value: questID,
- }
- p.Response(session, resp)
- }
- func (p *actorPlayer) questEvent(e cfacade.IEventData) {
- if e.UniqueID() != p.playerID {
- return
- }
- quest.Service().DoQuestEvent(p.playerID, e, p.isOnline)
- }
|