// 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" ) 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.EventUserLogin, this.EventUserLogin) event.RegisterGO(comm.EventUserOffline, this.CleanTask) return } func (this *ModuleTask) EventUserLogin(session comm.IUserSession) { var ( opencond map[string]int32 errdata *pb.ErrorData task *pb.DBTask active *pb.DBActivity err error ) if opencond, errdata = this.ModuleSys.QueryOpenCondData(session.GetUserId()); errdata != nil { this.Errorf("getTaskList err %v", errdata) return } if task, err = this.modelTask.getUserTask(session.GetUserId()); err != nil { this.Errorf("getTaskList err %v", err) return } this.modelTask.initTask(opencond, task, comm.TASK_DAILY) this.modelTask.initTask(opencond, task, comm.TASK_WEEKLY) this.modelTask.initTask(opencond, task, comm.TASK_ACHIEVE) if err = this.modelTask.Change(session.GetUserId(), map[string]interface{}{ "dayList": task.DayList, "weekList": task.WeekList, "achieveList": task.AchieveList, }); err != nil { log.Error("err", log.Field{Key: "uid", Value: session.GetUserId()}) return } if active, err = this.modelTaskActive.getActiveList(session.GetUserId()); err != nil { return } this.modelTaskActive.initActiveReward(active, comm.TASK_DAILY) this.modelTaskActive.initActiveReward(active, comm.TASK_WEEKLY) if err = this.modelTaskActive.Change(session.GetUserId(), map[string]interface{}{ "activityList": active.ActivityList, }); err != nil { log.Error("err", log.Field{Key: "uid", Value: session.GetUserId()}) return } } // 清除缓存 func (this *ModuleTask) CleanTask(uid, sessionid string) { this.modelTask.BatchDelLists(uid) this.modelTaskActive.BatchDelLists(uid) } // 重置玩家活跃度 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) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) { reddot = make(map[comm.ReddotType]*pb.ReddotItem) var ( task *pb.DBTask = &pb.DBTask{} active *pb.DBActivity userExpand *pb.DBUserExpand err error ) if task, err = this.modelTask.getUserTask(session.GetUserId()); err != nil { this.Errorf("getTaskList err %v", err) return } if active, err = this.modelTaskActive.getActiveList(session.GetUserId()); err != nil { return } // 获取玩家活跃度 userExpand, err = this.ModuleUser.GetUserExpand(session.GetUserId()) if err != nil { return } for _, v := range rid { switch v { case comm.Reddot10101: tf, _ := this.modelTask.noReceiveTask(task, comm.TASK_DAILY) reddot[comm.Reddot10101] = &pb.ReddotItem{ Rid: int32(comm.Reddot10101), Activated: tf, Nextchanagetime: 0, } case comm.Reddot10102: tf, _ := this.modelTask.noReceiveTask(task, comm.TASK_WEEKLY) reddot[comm.Reddot10102] = &pb.ReddotItem{ Rid: int32(comm.Reddot10102), Activated: tf, Nextchanagetime: 0, } case comm.Reddot10103: tf, _ := this.modelTask.noReceiveTask(task, comm.TASK_ACHIEVE) reddot[comm.Reddot10103] = &pb.ReddotItem{ Rid: int32(comm.Reddot10103), Activated: tf, Nextchanagetime: 0, } case comm.Reddot10201: tf, _ := this.modelTaskActive.noReceiveTaskActive(userExpand, active.ActivityList, comm.TASK_DAILY) reddot[comm.Reddot10201] = &pb.ReddotItem{ Rid: int32(comm.Reddot10201), Activated: tf, Nextchanagetime: 0, } case comm.Reddot10301: tf, _ := this.modelTaskActive.noReceiveTaskActive(userExpand, active.ActivityList, comm.TASK_WEEKLY) reddot[comm.Reddot10301] = &pb.ReddotItem{ Rid: int32(comm.Reddot10301), Activated: tf, Nextchanagetime: 0, } } } return }