140 lines
4.0 KiB
Go
140 lines
4.0 KiB
Go
// package
|
|
// 支线任务
|
|
// 赵长远
|
|
package linestory
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
var _ comm.ILinestory = (*ModuleLinestory)(nil)
|
|
|
|
type ModuleLinestory struct {
|
|
modules.ModuleBase
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelLinestory *ModelLinestory
|
|
confTimeline *cfg.GameLinestoryTimeLine
|
|
confMaintask *cfg.GameLinestoryMainTask
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &ModuleLinestory{}
|
|
}
|
|
|
|
func (this *ModuleLinestory) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
if err = this.ModuleBase.Init(service, module, options); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ModuleLinestory) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelLinestory = this.RegisterComp(new(ModelLinestory)).(*ModelLinestory)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
func (this *ModuleLinestory) GetType() core.M_Modules {
|
|
return comm.ModuleLinestory
|
|
}
|
|
|
|
func (this *ModuleLinestory) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
if this.confTimeline, err = this.configure.getLinestoryTimelineCfg(); err != nil {
|
|
return err
|
|
}
|
|
if this.confMaintask, err = this.configure.getLinestoryMainTaskCfg(); err != nil {
|
|
return err
|
|
}
|
|
return
|
|
}
|
|
|
|
// 检查真实结局路径是否完成
|
|
func (this *ModuleLinestory) isOverRealline(finishTasks []int32) bool {
|
|
//真实结局节点ID
|
|
var realEndingTaskId int32
|
|
// for _, v := range this.confMaintask.GetDataList() {
|
|
// if v.Ending == 1 {
|
|
// realEndingTaskId = v.Id
|
|
// break
|
|
// }
|
|
// }
|
|
log.Debugln(realEndingTaskId)
|
|
// 存在真实结局节点
|
|
if _, ok := utils.Findx(finishTasks, realEndingTaskId); ok {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 世界任务完成通知
|
|
func (this *ModuleLinestory) TaskFinishNotify(uid string, taskId, groupId int32) error {
|
|
ls := this.modelLinestory.getLinestory(uid)
|
|
log.Debug("支线剧情任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "groupId", Value: groupId}, log.Field{Key: "taskId", Value: taskId})
|
|
|
|
// 校验groupId 或taskId是否合法
|
|
if _, ok := this.confTimeline.GetDataMap()[groupId]; !ok {
|
|
this.Debug("非支线剧情任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "groupId", Value: groupId}, log.Field{Key: "taskId", Value: taskId})
|
|
return comm.NewCustomError(pb.ErrorCode_ReqParameterError)
|
|
}
|
|
if _, ok := this.confMaintask.GetDataMap()[taskId]; !ok {
|
|
this.Debug("非支线剧情任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "groupId", Value: groupId}, log.Field{Key: "taskId", Value: taskId})
|
|
return comm.NewCustomError(pb.ErrorCode_ReqParameterError)
|
|
}
|
|
|
|
var isUpdate bool
|
|
if chapter, ok := ls.TaskChapter[groupId]; ok {
|
|
if !this.modelLinestory.isPreFinished(chapter.TaskIds, taskId) {
|
|
return comm.NewCustomError(pb.ErrorCode_LinestoryPreNoComplete)
|
|
}
|
|
if _, ok := utils.Findx(chapter.TaskIds, taskId); !ok {
|
|
chapter.TaskIds = append(chapter.TaskIds, taskId)
|
|
if this.isOverRealline(chapter.TaskIds) {
|
|
//说明组里的所有任务完成
|
|
chapter.Receive = 1
|
|
chapter.Status = 1
|
|
}
|
|
|
|
// 重置任务ID
|
|
if conf, ok := this.confMaintask.GetDataMap()[taskId]; ok {
|
|
if conf.Group == groupId {
|
|
// if len(conf.Resetto) > 0 {
|
|
// newTaskList := []int32{}
|
|
// for _, v := range conf.Resetto {
|
|
// newTaskList = utils.Deletex(chapter.TaskIds, v)
|
|
// }
|
|
// chapter.TaskIds = newTaskList
|
|
// }
|
|
}
|
|
}
|
|
isUpdate = true
|
|
}
|
|
} else {
|
|
tg := &pb.TaskChapter{}
|
|
// 设置完成的任务
|
|
tg.TaskIds = append(tg.TaskIds, taskId)
|
|
if ls.TaskChapter == nil {
|
|
ls.TaskChapter = make(map[int32]*pb.TaskChapter)
|
|
}
|
|
ls.TaskChapter[groupId] = tg
|
|
isUpdate = true
|
|
}
|
|
if isUpdate {
|
|
update := map[string]interface{}{
|
|
"taskChapter": ls.TaskChapter,
|
|
}
|
|
return this.modelLinestory.Change(uid, update)
|
|
}
|
|
return nil
|
|
}
|