187 lines
4.8 KiB
Go
187 lines
4.8 KiB
Go
// package 随机任务
|
|
package rtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 随机任务
|
|
// type rtask struct {
|
|
// rtaskId int32
|
|
// handlers []*rtaskCondi
|
|
// }
|
|
|
|
// 限定条件
|
|
type rtaskCondi struct {
|
|
cfg *cfg.GameRdtaskCondiData
|
|
fn rtaskHandle
|
|
}
|
|
|
|
// 设定返回值
|
|
type rtaskHandle func(uid string, cfg *cfg.GameRdtaskCondiData) (ok bool)
|
|
|
|
type ModuleRtask struct {
|
|
modules.ModuleBase
|
|
modelRtask *ModelRtask
|
|
api *apiComp
|
|
configure *configureComp
|
|
|
|
rtaskHandleMap map[int32]*rtaskCondi // 任务处理器
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &ModuleRtask{
|
|
rtaskHandleMap: 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.initRtaskHandle()
|
|
return
|
|
}
|
|
|
|
func (this *ModuleRtask) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelRtask = this.RegisterComp(new(ModelRtask)).(*ModelRtask)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
func (this *ModuleRtask) register(condiId int32, rtask *rtaskCondi) {
|
|
if _, ok := this.rtaskHandleMap[condiId]; !ok {
|
|
this.rtaskHandleMap[condiId] = rtask
|
|
}
|
|
}
|
|
|
|
func (this *ModuleRtask) initRtaskHandle() {
|
|
conf, err := this.configure.getRtaskTypeCfg()
|
|
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.RtaskTypeHeroTarget:
|
|
this.register(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
fn: this.modelRtask.HeroTarget,
|
|
})
|
|
case comm.RtaskTypeHeroLvTarget:
|
|
this.register(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
fn: this.modelRtask.HeroLvTarget,
|
|
})
|
|
case comm.RtaskTypeHeroStarTarget:
|
|
this.register(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
fn: this.modelRtask.HeroStarTarget,
|
|
})
|
|
|
|
case comm.RtaskTypeEquipNum:
|
|
this.register(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
fn: this.modelRtask.EquipNum,
|
|
})
|
|
|
|
case comm.RtaskTypePoltId:
|
|
this.register(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
fn: this.modelRtask.PoltId,
|
|
})
|
|
|
|
case comm.RtaskTypeTaskDay:
|
|
this.register(v.Id, &rtaskCondi{
|
|
cfg: typeCfg,
|
|
fn: this.modelRtask.TaskDay,
|
|
})
|
|
default:
|
|
log.Warnf("%v rtask type not configure", typeCfg.Type)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// if data, err := this.configure.getRtaskList(); err == nil {
|
|
// for _, v := range data {
|
|
// // var handlers []*rtaskCondi
|
|
// // rtask := &rtask{
|
|
// // rtaskId: v.Id,
|
|
// // handlers: handlers,
|
|
// // }
|
|
|
|
// //遍历任务的限定条件
|
|
// for _, rtaskTypeId := range v.Condition {
|
|
// // 获取每个限定条件配置
|
|
// if typeCfg, err2 := this.configure.getRtaskTypeById(rtaskTypeId); err2 == nil {
|
|
// if typeCfg != nil {
|
|
// switch comm.TaskType(typeCfg.GetTypeId()) {
|
|
// case comm.RtaskTypeHeroTarget:
|
|
// this.register(v.Id, &rtaskCondi{
|
|
// cfg: typeCfg,
|
|
// fn: this.modelRtask.HeroTarget,
|
|
// })
|
|
// case comm.RtaskTypeHeroLvTarget:
|
|
// handlers = append(handlers, &rtaskCondi{
|
|
// cfg: typeCfg,
|
|
// fn: this.modelRtask.HeroLvTarget,
|
|
// })
|
|
// case comm.RtaskTypeHeroStarTarget:
|
|
// handlers = append(handlers, &rtaskCondi{
|
|
// cfg: typeCfg,
|
|
// fn: this.modelRtask.HeroStarTarget,
|
|
// })
|
|
// case comm.RtaskTypeEquipNum:
|
|
// handlers = append(handlers, &rtaskCondi{
|
|
// cfg: typeCfg,
|
|
// fn: this.modelRtask.EquipNum,
|
|
// })
|
|
// case comm.RtaskTypePoltId:
|
|
// handlers = append(handlers, &rtaskCondi{
|
|
// cfg: typeCfg,
|
|
// fn: this.modelRtask.PoltId,
|
|
// })
|
|
// case comm.RtaskTypeTaskDay:
|
|
// handlers = append(handlers, &rtaskCondi{
|
|
// cfg: typeCfg,
|
|
// fn: this.modelRtask.TaskDay,
|
|
// })
|
|
|
|
// default:
|
|
// log.Warnf("%v rtask type not configure", typeCfg.GetTypeId())
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// this.register(v.Id, rtask)
|
|
|
|
// }
|
|
// }
|
|
}
|
|
|
|
// 通知随机任务
|
|
// func (this *ModuleRtask) SendToRtask(session comm.IUserSession, param *pb.RtaskParam) (code pb.ErrorCode) {
|
|
// if taskId, err := this.modelRtask.doRtaskHandle(session.GetUserId(), param); err != nil {
|
|
// code = pb.ErrorCode_TaskHandle
|
|
// } else {
|
|
// if err := session.SendMsg(string(comm.ModuleRtask), "", &pb.RtaskFinishPush{
|
|
// RtaskId: taskId,
|
|
// }); err != nil {
|
|
// code = pb.ErrorCode_SystemError
|
|
// }
|
|
// }
|
|
|
|
// return
|
|
// }
|