package task import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" ) type ModuleTask struct { modules.ModuleBase modelTask *ModelTask modelTaskActive *ModelTaskActive api *apiComp configure *configureComp } func NewModule() core.IModule { return &ModuleTask{} } func (this *ModuleTask) GetType() core.M_Modules { return comm.ModuleTask } func (this *ModuleTask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) return } func (this *ModuleTask) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelTask = this.RegisterComp(new(ModelTask)).(*ModelTask) this.modelTaskActive = this.RegisterComp(new(ModelTaskActive)).(*ModelTaskActive) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } //模块启动接口 func (this *ModuleTask) Start() (err error) { err = this.ModuleBase.Start() return } //初始化任务 func (this *ModuleTask) InitTask(uid string, taskTag comm.TaskTag) { if err := this.modelTask.initTaskByTag(uid, taskTag); err != nil { log.Errorf("uid:%v tag:%v initTask err: %v", uid, taskTag, err) } } //初始化日常、周常、成就 func (this *ModuleTask) InitTaskAll(uid string) { this.InitTask(uid, comm.TASK_DAILY) this.InitTask(uid, comm.TASK_WEEKLY) this.InitTask(uid, comm.TASK_ACHIEVE) this.modelTaskActive.initActiveRewardByTag(uid, comm.TASK_DAILY) this.modelTaskActive.initActiveRewardByTag(uid, comm.TASK_WEEKLY) } //重置任务 func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) { if err := this.modelTask.clearTask(uid, taskTag); err != nil { log.Errorf("uid:%v tag:%v ResetTask err:%v", uid, taskTag, err) return } this.InitTask(uid, taskTag) if err := this.modelTaskActive.clearTask(uid, taskTag); err != nil { log.Errorf("uid:%v tag:%v ResetTaskActive err:%v", uid, taskTag, err) return } this.modelTaskActive.initActiveRewardByTag(uid, taskTag) } //任务处理 func (this *ModuleTask) SendToTask(uid string, taskType comm.TaskType, taskPram *pb.TaskParam) (code pb.ErrorCode) { if err := this.modelTask.taskHandle(uid, taskType, taskPram); err != nil { code = pb.ErrorCode_TaskHandle } return }