优化任务条件
This commit is contained in:
parent
683913f1aa
commit
3f5c8b6277
@ -87,7 +87,12 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo
|
|||||||
errors.Errorf("condiID: %v", condiId)
|
errors.Errorf("condiID: %v", condiId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ok, err = condi.verify(uid, condi.cfg); !ok {
|
conf, err:= this.moduleRtask.configure.getRtaskTypeById(condiId)
|
||||||
|
if err!= nil {
|
||||||
|
errors.Errorf("conf not found condiID: %v", condiId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ok, err = condi.verify(uid, conf); !ok {
|
||||||
err = errors.WithMessagef(err, "uid: %v do rtask [condiId:%v] condition not reach", uid, condiId)
|
err = errors.WithMessagef(err, "uid: %v do rtask [condiId:%v] condition not reach", uid, condiId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ var _ comm.IRtask = (*ModuleRtask)(nil)
|
|||||||
|
|
||||||
// 限定条件
|
// 限定条件
|
||||||
type rtaskCondi struct {
|
type rtaskCondi struct {
|
||||||
cfg *cfg.GameRdtaskCondiData
|
condId int32 //任务条件配置ID
|
||||||
verify verifyHandle //校验任务条件
|
verify verifyHandle //校验任务条件
|
||||||
find condiFindHandle //检索任务条件
|
find condiFindHandle //检索任务条件
|
||||||
update updateDataHandle //更新任务数据
|
update updateDataHandle //更新任务数据
|
||||||
@ -93,77 +93,66 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
|
|||||||
switch comm.TaskType(typeCfg.Type) {
|
switch comm.TaskType(typeCfg.Type) {
|
||||||
case comm.Rtype1:
|
case comm.Rtype1:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verfiyRtype1,
|
verify: this.modelRtask.verfiyRtype1,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype2:
|
case comm.Rtype2:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verifyRtype2,
|
verify: this.modelRtask.verifyRtype2,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype3:
|
case comm.Rtype3:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verifyRtype3,
|
verify: this.modelRtask.verifyRtype3,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype4:
|
case comm.Rtype4:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verifyRtype4,
|
verify: this.modelRtask.verifyRtype4,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype5:
|
case comm.Rtype5:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verifyRtype5,
|
verify: this.modelRtask.verifyRtype5,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype6:
|
case comm.Rtype6:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verifyRtype6,
|
verify: this.modelRtask.verifyRtype6,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype8:
|
case comm.Rtype8:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verfiyRtype8,
|
verify: this.modelRtask.verfiyRtype8,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype9:
|
case comm.Rtype9:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verfiyRtype9,
|
verify: this.modelRtask.verfiyRtype9,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype10:
|
case comm.Rtype10:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verfiyRtype10,
|
verify: this.modelRtask.verfiyRtype10,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype11, comm.Rtype84, comm.Rtype85:
|
case comm.Rtype11, comm.Rtype84, comm.Rtype85:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.lessEqualFirstParam,
|
find: this.modelRtaskRecord.lessEqualFirstParam,
|
||||||
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
|
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype18:
|
case comm.Rtype18:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.greatEqualFirstParam,
|
find: this.modelRtaskRecord.greatEqualFirstParam,
|
||||||
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
|
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
|
||||||
update: this.modelRtaskRecord.addUpdate,
|
update: this.modelRtaskRecord.addUpdate,
|
||||||
@ -176,35 +165,30 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
|
|||||||
comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104,
|
comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104,
|
||||||
comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131:
|
comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.lessEqualFirstParam,
|
find: this.modelRtaskRecord.lessEqualFirstParam,
|
||||||
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
|
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
|
||||||
update: this.modelRtaskRecord.addUpdate,
|
update: this.modelRtaskRecord.addUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype20:
|
case comm.Rtype20:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtask.verifyRtype20,
|
verify: this.modelRtask.verifyRtype20,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype22, comm.Rtype109:
|
case comm.Rtype22, comm.Rtype109:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalFirstParam,
|
find: this.modelRtaskRecord.equalFirstParam,
|
||||||
verify: this.modelRtaskRecord.verifyFirstEqualParam,
|
verify: this.modelRtaskRecord.verifyFirstEqualParam,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
})
|
})
|
||||||
case comm.Rtype63:
|
case comm.Rtype63:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
verify: this.modelRtask.verifyRtype63,
|
verify: this.modelRtask.verifyRtype63,
|
||||||
})
|
})
|
||||||
case comm.Rtype16, comm.Rtype17,
|
case comm.Rtype16, comm.Rtype17,
|
||||||
comm.Rtype35, comm.Rtype44,
|
comm.Rtype35, comm.Rtype44,
|
||||||
comm.Rtype59, comm.Rtype61, comm.Rtype70:
|
comm.Rtype59, comm.Rtype61, comm.Rtype70:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.equalParams,
|
find: this.modelRtaskRecord.equalParams,
|
||||||
verify: this.modelRtaskRecord.verifyFromDb,
|
verify: this.modelRtaskRecord.verifyFromDb,
|
||||||
update: this.modelRtaskRecord.overrideUpdate,
|
update: this.modelRtaskRecord.overrideUpdate,
|
||||||
@ -217,7 +201,6 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
|
|||||||
comm.Rtype52, comm.Rtype55, comm.Rtype56,
|
comm.Rtype52, comm.Rtype55, comm.Rtype56,
|
||||||
comm.Rtype65, comm.Rtype66, comm.Rtype67, comm.Rtype68, comm.Rtype140:
|
comm.Rtype65, comm.Rtype66, comm.Rtype67, comm.Rtype68, comm.Rtype140:
|
||||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||||
cfg: typeCfg,
|
|
||||||
find: this.modelRtaskRecord.lessThanParams,
|
find: this.modelRtaskRecord.lessThanParams,
|
||||||
verify: this.modelRtaskRecord.verifyFromDb,
|
verify: this.modelRtaskRecord.verifyFromDb,
|
||||||
update: this.modelRtaskRecord.addUpdate,
|
update: this.modelRtaskRecord.addUpdate,
|
||||||
@ -254,24 +237,25 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
|
|||||||
condis []*rtaskCondi
|
condis []*rtaskCondi
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, codi := range this.configure.getRtaskCondis(int32(rtaskType)) {
|
for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) {
|
||||||
v, ok := this.handleMap[codi.Id]
|
v, ok := this.handleMap[codiConf.Id]
|
||||||
if !ok {
|
if !ok {
|
||||||
this.Warn("未注册事件处理器", log.Fields{"uid": uid, "condiId": codi.Id})
|
this.Warn("未注册事件处理器", log.Fields{"uid": uid, "condiId": codiConf.Id})
|
||||||
code = pb.ErrorCode_RtaskCondiNoFound
|
code = pb.ErrorCode_RtaskCondiNoFound
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.find == nil {
|
if v.find == nil {
|
||||||
this.Warn("未设置find Handle", log.Fields{"uid": uid, "condiId": codi.Id})
|
this.Warn("未设置find Handle", log.Fields{"uid": uid, "condiId": codiConf.Id})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if condiId, err = v.find(v.cfg, params...); condiId == 0 {
|
if condiId, err = v.find(codiConf, params...); condiId == 0 {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Warnln(errors.WithMessage(err, uid).Error())
|
this.Warnln(errors.WithMessage(err, uid).Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
v.condId = codiConf.Id
|
||||||
condis = append(condis, v)
|
condis = append(condis, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,18 +263,25 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
|
|||||||
|
|
||||||
// update
|
// update
|
||||||
for _, v := range condis {
|
for _, v := range condis {
|
||||||
|
conf, err:= this.configure.getRtaskTypeById(v.condId)
|
||||||
|
if err!= nil {
|
||||||
|
this.Errorln(err)
|
||||||
|
code = pb.ErrorCode_RtaskCondiNoFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if v.update != nil {
|
if v.update != nil {
|
||||||
if err := v.update(uid, v.cfg, params...); err != nil {
|
if err := v.update(uid, conf, params...); err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//任务完成则推送
|
//任务完成则推送
|
||||||
if code := this.CheckCondi(uid, v.cfg.Id); code == pb.ErrorCode_Success {
|
if code := this.CheckCondi(uid, conf.Id); code == pb.ErrorCode_Success {
|
||||||
module, err := this.service.GetModule(comm.ModuleWorldtask)
|
module, err := this.service.GetModule(comm.ModuleWorldtask)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if worldtask, ok := module.(comm.IWorldtask); ok {
|
if worldtask, ok := module.(comm.IWorldtask); ok {
|
||||||
if err := worldtask.TaskcondNotify(session, v.cfg.Id); err != nil {
|
if err := worldtask.TaskcondNotify(session, conf.Id); err != nil {
|
||||||
var customErr = new(comm.CustomError)
|
var customErr = new(comm.CustomError)
|
||||||
if errors.As(err, &customErr) {
|
if errors.As(err, &customErr) {
|
||||||
notifyErr := &pb.NotifyErrorNotifyPush{
|
notifyErr := &pb.NotifyErrorNotifyPush{
|
||||||
@ -306,7 +297,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
|
|||||||
notifyErr.Code = pb.ErrorCode_UserSessionNobeing
|
notifyErr.Code = pb.ErrorCode_UserSessionNobeing
|
||||||
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
|
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
|
||||||
} else {
|
} else {
|
||||||
log.Error("任务条件达成通知", log.Fields{"uid": uid, "condId": v.cfg.Id, "err": err.Error()})
|
log.Error("任务条件达成通知", log.Fields{"uid": uid, "condId": conf.Id, "err": err.Error()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user