From 413362e21accfcfcc6903b719d6a040317531a75 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Tue, 14 Mar 2023 18:19:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=9D=A1=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_rdtaskcondi.json | 4 +- modules/rtask/module.go | 301 ++++++++++++++++++++++++--------- modules/rtask/updateHandle.go | 15 +- modules/sociaty/module.go | 8 +- 4 files changed, 237 insertions(+), 91 deletions(-) diff --git a/bin/json/game_rdtaskcondi.json b/bin/json/game_rdtaskcondi.json index 77e539471..40018f1b3 100644 --- a/bin/json/game_rdtaskcondi.json +++ b/bin/json/game_rdtaskcondi.json @@ -623,8 +623,8 @@ { "id": 170, "type": 1, - "data1": 44006, - "data2": 0, + "data1": 1, + "data2": 44006, "data3": 0, "data4": 0, "data5": 0 diff --git a/modules/rtask/module.go b/modules/rtask/module.go index 15ec4f0ee..e935783eb 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -15,6 +15,7 @@ import ( cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "go_dreamfactory/utils" + "sync" "github.com/pkg/errors" ) @@ -40,8 +41,8 @@ type ModuleRtask struct { modelRtaskRecord *ModelRtaskRecord api *apiComp configure *configureComp - - handleMap map[int32]*rtaskCondi //任务校验处理器 + lock sync.Mutex + handleMap map[int32]*rtaskCondi //任务校验处理器 } func NewModule() core.IModule { @@ -57,7 +58,7 @@ func (this *ModuleRtask) GetType() core.M_Modules { func (this *ModuleRtask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) - this.initRtaskVerifyHandle() + // this.initRtaskVerifyHandle() return } func (this *ModuleRtask) Start() (err error) { @@ -75,12 +76,198 @@ func (this *ModuleRtask) OnInstallComp() { } func (this *ModuleRtask) registerVerifyHandle(condiId int32, condi *rtaskCondi) { - if _, ok := this.handleMap[condiId]; !ok { - this.handleMap[condiId] = condi + // if _, ok := this.handleMap[condiId]; !ok { + // this.handleMap[condiId] = condi + // } + this.lock.Lock() + defer this.lock.Unlock() + this.handleMap[condiId] = condi +} + +func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) { + for _, v := range this.configure.getRtaskCondis(int32(tt)) { + switch tt { + case comm.Rtype1: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verfiyRtype1, + update: this.modelRtaskRecord.addUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype2: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verifyRtype2, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype3: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verifyRtype3, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype4: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verifyRtype4, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype5: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verifyRtype5, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype6: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verifyRtype6, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype8: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verfiyRtype8, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype9: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verfiyRtype9, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype10: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verfiyRtype10, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype11, comm.Rtype84, comm.Rtype85: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.lessEqualFirstParam, + verify: this.modelRtaskRecord.verifyFirstGreatEqualParam, + update: this.modelRtaskRecord.overrideUpdate, + } + + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype18: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.greatEqualFirstParam, + verify: this.modelRtaskRecord.verifyFirstGreatEqualParam, + update: this.modelRtaskRecord.addUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype7, comm.Rtype12, comm.Rtype13, comm.Rtype14, comm.Rtype15, + comm.Rtype19, comm.Rtype21, comm.Rtype24, + comm.Rtype26, comm.Rtype27, comm.Rtype28, comm.Rtype38, + comm.Rtype39, comm.Rtype50, comm.Rtype51, comm.Rtype53, + comm.Rtype54, comm.Rtype57, comm.Rtype58, comm.Rtype60, + comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104, + comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131, + comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146, + comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.lessEqualFirstParam, + verify: this.modelRtaskRecord.verifyFirstGreatEqualParam, + update: this.modelRtaskRecord.addUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype20: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verifyRtype20, + update: this.modelRtaskRecord.overrideUpdate, + } + + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype22, comm.Rtype109: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtaskRecord.verifyFirstEqualParam, + update: this.modelRtaskRecord.overrideUpdate, + } + + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype63: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalFirstParam, + verify: this.modelRtask.verifyRtype63, + update: this.modelRtaskRecord.addUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype16, comm.Rtype17, + comm.Rtype35, comm.Rtype44, + comm.Rtype59, comm.Rtype61, comm.Rtype70: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.equalParams, + verify: this.modelRtaskRecord.verifyFromDb, + update: this.modelRtaskRecord.overrideUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + case comm.Rtype23, comm.Rtype25, comm.Rtype29, comm.Rtype30, comm.Rtype31, + comm.Rtype32, comm.Rtype33, comm.Rtype34, comm.Rtype36, + comm.Rtype37, comm.Rtype40, comm.Rtype41, + comm.Rtype42, comm.Rtype43, comm.Rtype45, + comm.Rtype46, comm.Rtype47, comm.Rtype48, comm.Rtype49, + comm.Rtype52, comm.Rtype55, comm.Rtype56, + comm.Rtype65, comm.Rtype66, comm.Rtype67, comm.Rtype68, comm.Rtype140: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.lessThanParams, + verify: this.modelRtaskRecord.verifyFromDb, + update: this.modelRtaskRecord.addUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) + default: + log.Warnf("rtaskType[%v] not register", tt) + } } + return } // 条件校验初始 +// Deprecated func (this *ModuleRtask) initRtaskVerifyHandle() { conf, err := this.configure.getRtaskCondiCfg() if err != nil { @@ -236,36 +423,13 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com } return } - for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) { - v, ok := this.handleMap[codiConf.Id] - if !ok { - this.Warn("未注册事件处理器", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "condiId", Value: codiConf.Id}, - ) - code = pb.ErrorCode_RtaskCondiNoFound - return - } - - if v.find == nil { - this.Warn("未设置find Handle", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "condiId", Value: codiConf.Id}, - ) - return - } - - if condiId, _ := v.find(codiConf, params...); condiId != 0 { - v.condId = codiConf.Id - condis = append(condis, v) - } - } + condis = this.getHandle(rtaskType) // update for _, v := range condis { conf, err := this.configure.getRtaskTypeById(v.condId) if err != nil { - log.Errorf("get condId conf err:%v", err) + log.Debug("任务配置未找到", log.Field{Key: "condId", Value: v.condId}) code = pb.ErrorCode_RtaskCondiNoFound return } @@ -274,6 +438,7 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com if err := v.update(uid, conf, params...); err != nil { log.Errorf("update task:%v", err) code = pb.ErrorCode_DBError + return } } @@ -281,13 +446,6 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com if code = this.CheckCondi(uid, conf.Id); code == pb.ErrorCode_Success { module, err := this.service.GetModule(comm.ModuleWorldtask) if err == nil { - // go func() { - // defer func() { - // if r := recover(); r != nil { - // log.Errorf("[worldtask ] err:%v ", r) - // } - // }() - if worldtask, ok := module.(comm.IWorldtask); ok { if err := worldtask.TaskcondNotify(session, conf.Id); err != nil { log.Error("任务条件达成通知", @@ -297,16 +455,9 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com ) } } - // }() } userModule, err := this.service.GetModule(comm.ModuleUser) if err == nil { - // go func() { - // defer func() { //程序异常 收集异常信息传递给前端显示 - // if r := recover(); r != nil { - // log.Errorf("[sociatytask ] err:%v ", r) - // } - // }() // 公会 if user, ok := userModule.(comm.IUser); ok { ex, err := user.GetUserExpand(uid) @@ -325,15 +476,9 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com ) } this.processOneTask(session, comm.Rtype156, 1) - // if module, err := this.service.GetModule(comm.ModuleRtask); err == nil { - // if iRtask, ok := module.(comm.IRtask); ok { - // iRtask.SendToRtask(session, comm.Rtype156, 1) - // } - // } } } } - // }() } } @@ -368,30 +513,32 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T condis []*rtaskCondi ) - for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) { - v, ok := this.handleMap[codiConf.Id] - if !ok { - this.Warn("未注册事件处理器", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "condiId", Value: codiConf.Id}, - ) - code = pb.ErrorCode_RtaskCondiNoFound - return - } + condis = this.getHandle(rtaskType) - if v.find == nil { - this.Warn("未设置find Handle", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "condiId", Value: codiConf.Id}, - ) - return - } + // for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) { + // v, ok := this.handleMap[codiConf.Id] + // if !ok { + // this.Warn("未注册事件处理器", + // log.Field{Key: "uid", Value: uid}, + // log.Field{Key: "condiId", Value: codiConf.Id}, + // ) + // code = pb.ErrorCode_RtaskCondiNoFound + // return + // } - if condiId, _ := v.find(codiConf, params...); condiId != 0 { - v.condId = codiConf.Id - condis = append(condis, v) - } - } + // if v.find == nil { + // this.Warn("未设置find Handle", + // log.Field{Key: "uid", Value: uid}, + // log.Field{Key: "condiId", Value: codiConf.Id}, + // ) + // return + // } + + // if condiId, _ := v.find(codiConf, params...); condiId != 0 { + // v.condId = codiConf.Id + // condis = append(condis, v) + // } + // } // update for _, v := range condis { @@ -496,10 +643,11 @@ func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) } for _, tp := range taskParams { if code := this.processOneTask(session, tp.TT, tp.Params...); code != pb.ErrorCode_Success { - this.Debug("任务处理", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "taskType", Value: tp.TT}, - log.Field{Key: "params", Value: tp.Params}) + // this.Debug("任务处理", + // log.Field{Key: "uid", Value: uid}, + // log.Field{Key: "taskType", Value: tp.TT}, + // log.Field{Key: "params", Value: tp.Params}, + // log.Field{Key: "code", Value: code}) } session.Push() comm.PuttaskParam(tp) @@ -511,6 +659,7 @@ func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) // 任务条件校验 func (this *ModuleRtask) CheckCondi(uid string, condiId int32) (code pb.ErrorCode) { if _, ok := this.modelRtask.checkCondi(uid, condiId); !ok { + // this.Debug("任务条件未达到", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condiId", Value: condiId}) code = pb.ErrorCode_RtaskCondiNoReach } return diff --git a/modules/rtask/updateHandle.go b/modules/rtask/updateHandle.go index 13bebf1d3..daeb7c66e 100644 --- a/modules/rtask/updateHandle.go +++ b/modules/rtask/updateHandle.go @@ -2,6 +2,7 @@ package rtask import ( + "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" @@ -37,6 +38,11 @@ func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCond if v, ok := record.Vals[cfg.Id]; ok { v.Data = hasUpdateData(paramLen, v, vals...) if len(v.Data) > 0 { + this.moduleRtask.Debug("打印V", + log.Field{Key: "v", Value: v.Data}, + log.Field{Key: "paramLen", Value: paramLen}, + log.Field{Key: "vals", Value: vals}, + ) update := map[string]interface{}{ "vals": v, } @@ -60,8 +66,6 @@ func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCond return } } - // log.Debug("覆盖数值更新", log.Fields{"uid": uid, "condiId": cfg.Id, "params": vals, "updated": record.Vals[cfg.Id]}) - // this.listenTask(uid, cfg.Id) return } @@ -107,12 +111,5 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData } err = this.Change(uid, update) } - // log.Debug("累计次数更新", - // log.Field{Key: "uid", Value: uid}, - // log.Field{Key: "condiId", Value: cfg.Id}, - // log.Field{Key: "params", Value: vals}, - // log.Field{Key: "updated", Value: record.Vals[cfg.Id]}, - // ) - return } diff --git a/modules/sociaty/module.go b/modules/sociaty/module.go index 418e459a8..62599279b 100644 --- a/modules/sociaty/module.go +++ b/modules/sociaty/module.go @@ -240,10 +240,10 @@ type TaskParams struct { // 任务条件达成通知 func (this *Sociaty) TaskcondNotify(uid, sociatyId string, condId int32) error { - log.Debug("公会任务", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "sociatyId", Value: sociatyId}, - log.Field{Key: "condId", Value: condId}) + // log.Debug("公会任务", + // log.Field{Key: "uid", Value: uid}, + // log.Field{Key: "sociatyId", Value: sociatyId}, + // log.Field{Key: "condId", Value: condId}) dt := &pb.DBSociatyTask{} err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(),