// package // 日/周常成就任务 // 赵长远 package task import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" event_v2 "go_dreamfactory/lego/sys/event/v2" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "time" ) var _ comm.ITask = (*ModuleTask)(nil) 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) GetEventApp() *event_v2.App { return this.modelTask.EventApp } 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() event.RegisterGO(comm.EventUserOffline, this.CleanTask) return } //初始化日常、周常、成就 func (this *ModuleTask) InitTaskAll(uid string) { t := configure.Now() defer func() { log.Debugf("初始化任务 耗时:%v", time.Since(t)) }() this.modelTask.initTask(uid, comm.TASK_DAILY) this.modelTask.initTask(uid, comm.TASK_WEEKLY) this.modelTask.initTask(uid, comm.TASK_ACHIEVE) this.modelTaskActive.initActiveReward(uid, comm.TASK_DAILY) this.modelTaskActive.initActiveReward(uid, comm.TASK_WEEKLY) } // 初始化指定的任务 func (this *ModuleTask) InitTaskByTag(uid string, taskTag comm.TaskTag) { switch taskTag { case comm.TASK_DAILY: this.modelTask.initTask(uid, comm.TASK_DAILY) this.modelTaskActive.initActiveReward(uid, comm.TASK_DAILY) case comm.TASK_WEEKLY: this.modelTask.initTask(uid, comm.TASK_WEEKLY) this.modelTaskActive.initActiveReward(uid, comm.TASK_WEEKLY) case comm.TASK_ACHIEVE: this.modelTask.initTask(uid, comm.TASK_ACHIEVE) } } // 清除缓存 func (this *ModuleTask) CleanTask(session comm.IUserSession) { this.modelTask.BatchDelLists(session.GetUserId()) this.modelTaskActive.BatchDelLists(session.GetUserId()) } // 重置玩家活跃度 func (this *ModuleTask) resetActive(uid string, taskTag comm.TaskTag) { update := make(map[string]interface{}) if taskTag == comm.TASK_DAILY { update["activeday"] = 0 } else if taskTag == comm.TASK_WEEKLY { update["activeweek"] = 0 } if len(update) > 0 { this.ModuleUser.ChangeUserExpand(uid, update) } } // 获取玩家指定任务 func (this *ModuleTask) GetTaskById(uid string, taskTag, taskId int32) *pb.TaskData { var task *pb.DBTask if err := this.modelTask.GetList(uid, &task); err != nil { log.Errorf("GetTaskById err %v", err) return nil } if taskTag == int32(comm.TASK_DAILY) { for _, v := range task.DayList { if v.TaskId == taskId { return v } } } return nil } //重置任务 func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) { this.resetActive(uid, taskTag) this.modelTask.clearTask(uid, taskTag) this.modelTaskActive.clearTask(uid, taskTag) } // 清理任务数据 func (this *ModuleTask) CleanData(uid string) { this.modelTask.clearTask(uid) this.modelTaskActive.clearTask(uid) } //任务处理器注册 type taskHandle func(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask // 获取每日任务列表 func (this *ModuleTask) GetTaskDayFinished(uid string) []*pb.TaskData { return this.modelTask.getFinishTasks(uid, comm.TASK_DAILY) } func (this *ModuleTask) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) { reddot = make(map[comm.ReddotType]bool) for _, v := range rid { switch v { case comm.Reddot1: tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_DAILY) reddot[comm.Reddot1] = tf case comm.Reddot2: tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_WEEKLY) reddot[comm.Reddot2] = tf case comm.Reddot4: tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_ACHIEVE) reddot[comm.Reddot4] = tf case comm.Reddot27: tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_DAILY) reddot[comm.Reddot27] = tf case comm.Reddot28: tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_WEEKLY) reddot[comm.Reddot28] = tf } } return }