| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package mainQuest
- import (
- "f1-game/internal/data"
- facade "f1-game/internal/facade"
- nameRoute "f1-game/internal/name/route"
- "f1-game/internal/pb"
- "f1-game/internal/sessions"
- "f1-game/nodes/map/internal/db"
- "f1-game/nodes/map/player/quest"
- clog "github.com/cherry-game/cherry/logger"
- cproto "github.com/cherry-game/cherry/net/proto"
- )
- func Service() *service {
- return &service{}
- }
- type service struct {
- facade.PlayerServiceBase[*db.MapPlayerTable]
- }
- func (p *service) OnInit(playerTable *db.MapPlayerTable) {
- // 初始化主线章节任务
- p.checkAndInitMainQuest(playerTable)
- }
- func (p *service) OnLogin(playerTable *db.MapPlayerTable, session *cproto.Session) {
- if session.Contains(sessions.IsNewPlayer) || playerTable.MainChapterID <= 0 {
- clog.Infof("map main quest init: PlayerID = %d", playerTable.PlayerID)
- // 初始化主线章节任务
- p.checkAndInitMainQuest(playerTable)
- }
- // 检测是否需要添加下一章节任务列表
- p.CheckAddNextMainChapterQuest(playerTable)
- }
- // 检测是否添加主线章节任务
- func (p *service) checkAndInitMainQuest(playerTable *db.MapPlayerTable) {
- if playerTable.MainChapterID > 0 {
- return
- }
- list := data.MapMainQuest.List()
- if len(list) < 1 {
- clog.Warnf("add main quest fail, config not exist. playerID:%d", playerTable.PlayerID)
- return
- }
- first := list[0]
- // 添加任务组
- if quest.Service().TriggerOpenGroup(playerTable.PlayerID, first.QuestGroupID) {
- playerTable.MainChapterID = first.ChapterID
- playerTable.IsMainReward = false
- playerTable.Save2Queue()
- }
- }
- // 检测是否需要添加下一章节任务
- func (*service) CheckAddNextMainChapterQuest(playerTable *db.MapPlayerTable) {
- if !playerTable.IsMainReward {
- return
- }
- var (
- playerID = playerTable.PlayerID
- mainChapterID = playerTable.MainChapterID
- )
- mainQuestRow, found := data.MapMainQuest.GetByChapterID(mainChapterID)
- if !found {
- clog.Warnf("[CheckAddNextMainChapterQuest] fail, config not exist. playerID:%d, chapterID:%d",
- playerID, mainChapterID)
- return
- }
- nextChapterID := mainQuestRow.NextChapterID
- if nextChapterID <= 0 {
- return
- }
- // 下一章节任务配置
- nextMainQuestRow, found := data.MapMainQuest.GetByChapterID(nextChapterID)
- if !found {
- clog.Warnf("[CheckAddNextMainChapterQuest] fail, next quest config not exist. playerID:%d, chapterID:%d",
- playerID, mainChapterID)
- return
- }
- if nextMainQuestRow.QuestGroupID <= 0 {
- clog.Warnf("[CheckAddNextMainChapterQuest] fail, groupId <= 0. playerID:%d, chapterID:%d, nextChapterID:%d",
- playerID, mainChapterID, nextChapterID)
- return
- }
- // 添加任务组任务
- success := quest.Service().TriggerOpenGroup(playerID, nextMainQuestRow.QuestGroupID)
- if !success {
- clog.Warnf("[CheckAddNextMainChapterQuest] fail, trigger open group fail. playerID:%d, nextChapterID:%d",
- playerID, mainQuestRow.NextChapterID)
- return
- }
- // 删除旧的任务组
- playerTable.Quests.DeleteQuestWithGroupID(mainQuestRow.QuestGroupID)
- // 添加成功后更新当前章节ID
- playerTable.MainChapterID = nextChapterID
- playerTable.IsMainReward = false
- playerTable.Save2Queue()
- }
- // Push 推送地图主线信息
- func (p *service) Push(mapPlayerTable *db.MapPlayerTable, session *cproto.Session) {
- // 推送地图主线列表
- resp := &pb.QuestChapterReward{
- ChapterID: mapPlayerTable.MainChapterID,
- IsMainReward: mapPlayerTable.IsMainReward,
- }
- sessions.PushWithSession(session, nameRoute.PushMapPlayer_MainQuest, resp)
- }
|