// 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) } } } } }