go_dreamfactory/modules/linestory/module.go
2022-11-15 19:39:38 +08:00

85 lines
2.2 KiB
Go

// package
// 支线任务
// 赵长远
package linestory
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"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) {
err = this.ModuleBase.Init(service, module, options)
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) {
err = this.ModuleBase.Start()
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) TaskFinishNotify(uid string, taskId, groupId int32) error {
ls := this.modelLinestory.getLinestory(uid)
if v, ok := ls.TaskChapter[groupId]; ok {
if _, ok := utils.Findx(v.TaskIds, taskId); !ok {
v.TaskIds = append(v.TaskIds, taskId)
taskIds := this.configure.converArr(groupId)
// 校验当前组下的任务是否全部完成
if utils.ForContainer(taskIds, v.TaskIds) {
//说明组里的所有任务完成
v.Receive = 1
v.Status = 1
}
}
} 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
}
update := map[string]interface{}{
"taskChapter": ls.TaskChapter,
}
return this.modelLinestory.Change(uid, update)
}