go_dreamfactory/modules/task/module.go
2023-06-15 23:52:08 +08:00

186 lines
5.2 KiB
Go

// 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.EventUserOffline, this.CleanTask)
return
}
// 初始化日常、周常、成就
func (this *ModuleTask) InitTaskAll(uid string) {
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(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) 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
// 获取每日任务列表
// Deprecated
func (this *ModuleTask) GetTaskDayFinished(uid string) []*pb.TaskData {
return nil //this.modelTask.getFinishTasks(uid, comm.TASK_DAILY)
}
func (this *ModuleTask) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) {
reddot = make(map[comm.ReddotType]*pb.ReddotItem)
for _, v := range rid {
switch v {
case comm.Reddot10101:
tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_DAILY)
reddot[comm.Reddot10101] = &pb.ReddotItem{
Rid: int32(comm.Reddot10101),
Activated: tf,
Nextchanagetime: 0,
}
case comm.Reddot10102:
tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_WEEKLY)
reddot[comm.Reddot10102] = &pb.ReddotItem{
Rid: int32(comm.Reddot10102),
Activated: tf,
Nextchanagetime: 0,
}
case comm.Reddot10103:
tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_ACHIEVE)
reddot[comm.Reddot10103] = &pb.ReddotItem{
Rid: int32(comm.Reddot10103),
Activated: tf,
Nextchanagetime: 0,
}
case comm.Reddot10201:
tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_DAILY)
reddot[comm.Reddot10201] = &pb.ReddotItem{
Rid: int32(comm.Reddot10201),
Activated: tf,
Nextchanagetime: 0,
}
case comm.Reddot10301:
tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_WEEKLY)
reddot[comm.Reddot10301] = &pb.ReddotItem{
Rid: int32(comm.Reddot10301),
Activated: tf,
Nextchanagetime: 0,
}
}
}
return
}