| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package mainQuest
- import (
- "f1-game/internal/data"
- "f1-game/internal/facade"
- nameRoute "f1-game/internal/name/route"
- "f1-game/internal/sessions"
- "f1-game/nodes/game/internal/db"
- "f1-game/nodes/game/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.PlayerTable]
- }
- func (p *service) OnLogin(playerTable *db.PlayerTable, session *cproto.Session) {
- // 初始化游戏主线任务
- if session.Contains(sessions.IsNewPlayer) || playerTable.MainQuest.NotInit() {
- // 初始化游戏主线任务
- list := data.GameMainQuest.List()
- if len(list) < 1 {
- clog.Warnf("add main quest fail, config not exist. playerID:%d", playerTable.PlayerID)
- return
- }
- first := list[0]
- // 添加任务组
- if success := quest.Service().TriggerOpenGroup(playerTable.PlayerID, first.QuestGroupID); success {
- playerTable.MainQuest.MainChapterID = first.ChapterID
- playerTable.MainQuest.IsMainReward = false
- playerTable.Save2Queue()
- }
- return
- }
- }
- // 检测是否需要添加下一章节任务
- func (*service) CheckAddNextMainChapterQuest(playerTable *db.PlayerTable) {
- if !playerTable.MainQuest.IsMainReward {
- return
- }
- var (
- questTable = db.GetQuestTable(playerTable.PlayerID)
- playerID = playerTable.PlayerID
- mainChapterID = playerTable.MainQuest.MainChapterID
- )
- mainQuestRow, found := data.GameMainQuest.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.GameMainQuest.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
- }
- // 删除旧的任务组
- questTable.Quests.DeleteQuestWithGroupID(mainQuestRow.QuestGroupID)
- // 添加成功后更新当前章节ID
- playerTable.MainQuest.MainChapterID = nextChapterID
- playerTable.MainQuest.IsMainReward = false
- playerTable.Save2Queue()
- }
- func (p *service) Push(playerTable *db.PlayerTable, session *cproto.Session) {
- proto := playerTable.MainQuest.ToProto()
- sessions.PushWithSession(session, nameRoute.PushGamePlayer_MainQuest, proto)
- }
|