go_dreamfactory/modules/task/module.go
2022-07-22 11:45:09 +08:00

101 lines
2.8 KiB
Go

package task
import (
"fmt"
"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) InitTaskAll(uid string) {
this.modelTask.initTask(uid)
this.modelTaskActive.initActiveReward(uid)
}
//重置任务
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.InitTaskAll(uid)
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(session comm.IUserSession, taskType comm.TaskType, taskPram *pb.TaskParam) (code pb.ErrorCode) {
if task, err := this.modelTask.taskHandle(session.GetUserId(), taskType, taskPram); err != nil {
code = pb.ErrorCode_TaskHandle
} else {
if task != nil {
if err := session.SendMsg(string(comm.ModuleTask), TaskSubTypeFinishedPush, &pb.TaskFinishedPush{TaskId: task.TaskId}); err != nil {
this.modelTask.moduleTask.Errorf("SendToTask sendmsg err:%v", err)
}
}
}
return
}
//创建玩家攻略任务
func (this *ModuleTask) CreateTaskForStrategy(uid string, heroCfgId int32) {
//
ids := make(map[string]string)
ids, _ = this.modelTask.Redis.HGetAllToMapString(fmt.Sprintf("task:%v_%v", uid, comm.TASK_STRATEGY))
fmt.Println(ids)
//
}
func (this *ModuleTask) CleanData(uid string) {
this.modelTask.clearTask(uid, comm.TASK_DAILY)
this.modelTask.clearTask(uid, comm.TASK_WEEKLY)
this.modelTask.clearTask(uid, comm.TASK_ACHIEVE)
this.modelTask.clearTask(uid, comm.TASK_STRATEGY)
this.modelTaskActive.clearTask(uid, comm.TASK_DAILY)
this.modelTaskActive.clearTask(uid, comm.TASK_WEEKLY)
}