265 lines
8.5 KiB
Go
265 lines
8.5 KiB
Go
// package 随机任务
|
|
package rtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 限定条件
|
|
type rtaskCondi struct {
|
|
cfg *cfg.GameRdtaskCondiData
|
|
verify verifyHandle //校验任务条件
|
|
find condiFindHandle //检索任务条件
|
|
update updateDataHandle //更新任务数据
|
|
}
|
|
|
|
type verifyHandle func(uid string, cfg *cfg.GameRdtaskCondiData) (error, bool)
|
|
type condiFindHandle func(cfg *cfg.GameRdtaskCondiData, vals ...int32) int32
|
|
type updateDataHandle func(uid string, cfg *cfg.GameRdtaskCondiData, vals ...int32) error
|
|
|
|
type ModuleRtask struct {
|
|
modules.ModuleBase
|
|
modelRtask *ModelRtask
|
|
modelRtaskRecord *ModelRtaskRecord
|
|
api *apiComp
|
|
configure *configureComp
|
|
|
|
handleMap map[int32]*rtaskCondi //任务校验处理器
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &ModuleRtask{
|
|
handleMap: make(map[int32]*rtaskCondi),
|
|
}
|
|
}
|
|
|
|
func (this *ModuleRtask) GetType() core.M_Modules {
|
|
return comm.ModuleRtask
|
|
}
|
|
|
|
func (this *ModuleRtask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.initRtaskVerifyHandle()
|
|
return
|
|
}
|
|
|
|
func (this *ModuleRtask) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelRtask = this.RegisterComp(new(ModelRtask)).(*ModelRtask)
|
|
this.modelRtaskRecord = this.RegisterComp(new(ModelRtaskRecord)).(*ModelRtaskRecord)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
func (this *ModuleRtask) registerVerifyHandle(condiId int32, condi *rtaskCondi) {
|
|
if _, ok := this.handleMap[condiId]; !ok {
|
|
this.handleMap[condiId] = condi
|
|
}
|
|
}
|
|
|
|
// 条件校验初始
|
|
func (this *ModuleRtask) initRtaskVerifyHandle() {
|
|
conf, err := this.configure.getRtaskCondiCfg()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, v := range conf.GetDataList() {
|
|
if typeCfg, err := this.configure.getRtaskTypeById(v.Id); err == nil {
|
|
if typeCfg != nil {
|
|
switch comm.TaskType(typeCfg.Type) {
|
|
case comm.Rtype1:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
verify: this.modelRtaskRecord.verify,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype2:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
verify: this.modelRtaskRecord.verify,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype3:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
verify: this.modelRtaskRecord.verify,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype4:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
verify: this.modelRtaskRecord.verify,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype5:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
verify: this.modelRtaskRecord.verify,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype6:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype7:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype8:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.addUpdate,
|
|
})
|
|
case comm.Rtype9:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype10:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype11:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype12:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype13:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype14:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype15:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype16:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype17:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype18:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype19:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype20:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype21:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype22:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype23:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype24:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
case comm.Rtype25:
|
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
find: this.modelRtaskRecord.equalParams,
|
|
verify: this.modelRtaskRecord.verify,
|
|
update: this.modelRtaskRecord.overrideUpdate,
|
|
})
|
|
default:
|
|
log.Warnf("%v rtask type not configure", typeCfg.Type)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) {
|
|
if err := this.modelRtask.findAndUpdate(session.GetUserId(), rtaskType, params...); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
}
|
|
return
|
|
}
|