This commit is contained in:
wh_zcy 2023-05-05 09:36:55 +08:00
parent af5808a748
commit cc356997a3
5 changed files with 145 additions and 119 deletions

View File

@ -16,6 +16,7 @@ type ModelRtaskRecord struct {
modules.MCompModel modules.MCompModel
moduleRtask *ModuleRtask moduleRtask *ModuleRtask
service core.IService service core.IService
record *pb.DBRtaskRecord
} }
func (this *ModelRtaskRecord) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ModelRtaskRecord) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {

View File

@ -89,7 +89,7 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo
} }
//验证限定条件 //验证限定条件
var condi *rtaskCondi var condi *rtaskCondHandle
cond, ok := this.moduleRtask.handleMap.Load(condiId) cond, ok := this.moduleRtask.handleMap.Load(condiId)
if !ok { if !ok {
rcs := this.moduleRtask.getHandle(comm.TaskType(conf.Type)) rcs := this.moduleRtask.getHandle(comm.TaskType(conf.Type))
@ -100,7 +100,7 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo
} }
} }
if condi, ok = cond.(*rtaskCondi); !ok { if condi, ok = cond.(*rtaskCondHandle); !ok {
err = fmt.Errorf("condiType err") err = fmt.Errorf("condiType err")
return return
} }

View File

@ -12,18 +12,21 @@ import (
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db" "go_dreamfactory/sys/db"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"sync" "sync"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
) )
var _ comm.IRtask = (*ModuleRtask)(nil) var _ comm.IRtask = (*ModuleRtask)(nil)
// 限定条件 // 限定条件
type rtaskCondi struct { type rtaskCondHandle struct {
condId int32 //任务条件配置ID condId int32 //任务条件配置ID
verify verifyHandle //校验任务条件 verify verifyHandle //校验任务条件
find condiFindHandle //检索任务条件 find condiFindHandle //检索任务条件
@ -71,15 +74,15 @@ func (this *ModuleRtask) OnInstallComp() {
this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
} }
func (this *ModuleRtask) registerVerifyHandle(condiId int32, condi *rtaskCondi) { func (this *ModuleRtask) registerVerifyHandle(condiId int32, condi *rtaskCondHandle) {
this.handleMap.Store(condiId, condi) this.handleMap.Store(condiId, condi)
} }
func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) { func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondHandle) {
for _, v := range this.configure.getRtaskCondis(int32(tt)) { for _, v := range this.configure.getRtaskCondis(int32(tt)) {
switch tt { switch tt {
case comm.Rtype1: case comm.Rtype1:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype1, verify: this.modelRtask.verfiyRtype1,
@ -88,7 +91,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype2: case comm.Rtype2:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype2, verify: this.modelRtask.verifyRtype2,
@ -97,7 +100,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype3: case comm.Rtype3:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype3, verify: this.modelRtask.verifyRtype3,
@ -106,7 +109,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype4: case comm.Rtype4:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype4, verify: this.modelRtask.verifyRtype4,
@ -115,7 +118,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype5: case comm.Rtype5:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype5, verify: this.modelRtask.verifyRtype5,
@ -124,7 +127,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype6: case comm.Rtype6:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype6, verify: this.modelRtask.verifyRtype6,
@ -133,7 +136,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype8: case comm.Rtype8:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype8, verify: this.modelRtask.verfiyRtype8,
@ -142,7 +145,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype9: case comm.Rtype9:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype9, verify: this.modelRtask.verfiyRtype9,
@ -151,7 +154,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype10: case comm.Rtype10:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verfiyRtype10, verify: this.modelRtask.verfiyRtype10,
@ -160,7 +163,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype11, comm.Rtype84, comm.Rtype85: case comm.Rtype11, comm.Rtype84, comm.Rtype85:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.lessEqualFirstParam, find: this.modelRtaskRecord.lessEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam, verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
@ -170,7 +173,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype18: case comm.Rtype18:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.greatEqualFirstParam, find: this.modelRtaskRecord.greatEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam, verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
@ -187,7 +190,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131, comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131,
comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146, comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146,
comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156: comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.lessEqualFirstParam, find: this.modelRtaskRecord.lessEqualFirstParam,
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam, verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
@ -196,7 +199,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype50, comm.Rtype73: case comm.Rtype50, comm.Rtype73:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.lessEqualFirstParam, find: this.modelRtaskRecord.lessEqualFirstParam,
verify: this.modelRtaskRecord.verifyFromDb, verify: this.modelRtaskRecord.verifyFromDb,
@ -205,7 +208,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype20: case comm.Rtype20:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype20, verify: this.modelRtask.verifyRtype20,
@ -215,7 +218,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype22, comm.Rtype109: case comm.Rtype22, comm.Rtype109:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtaskRecord.verifyFirstEqualParam, verify: this.modelRtaskRecord.verifyFirstEqualParam,
@ -225,7 +228,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
condis = append(condis, condi) condis = append(condis, condi)
this.registerVerifyHandle(v.Id, condi) this.registerVerifyHandle(v.Id, condi)
case comm.Rtype63: case comm.Rtype63:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalFirstParam, find: this.modelRtaskRecord.equalFirstParam,
verify: this.modelRtask.verifyRtype63, verify: this.modelRtask.verifyRtype63,
@ -236,7 +239,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
case comm.Rtype16, comm.Rtype17, case comm.Rtype16, comm.Rtype17,
comm.Rtype35, comm.Rtype44, comm.Rtype35, comm.Rtype44,
comm.Rtype59, comm.Rtype61: comm.Rtype59, comm.Rtype61:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.equalParams, find: this.modelRtaskRecord.equalParams,
verify: this.modelRtaskRecord.verifyFromDb, verify: this.modelRtaskRecord.verifyFromDb,
@ -251,7 +254,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
comm.Rtype46, comm.Rtype47, comm.Rtype48, comm.Rtype49, comm.Rtype46, comm.Rtype47, comm.Rtype48, comm.Rtype49,
comm.Rtype52, comm.Rtype55, comm.Rtype56, comm.Rtype52, comm.Rtype55, comm.Rtype56,
comm.Rtype65, comm.Rtype66, comm.Rtype67, comm.Rtype68, comm.Rtype70, comm.Rtype140: comm.Rtype65, comm.Rtype66, comm.Rtype67, comm.Rtype68, comm.Rtype70, comm.Rtype140:
condi := &rtaskCondi{ condi := &rtaskCondHandle{
condId: v.Id, condId: v.Id,
find: this.modelRtaskRecord.lessThanParams, find: this.modelRtaskRecord.lessThanParams,
verify: this.modelRtaskRecord.verifyFromDb, verify: this.modelRtaskRecord.verifyFromDb,
@ -269,7 +272,8 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
// 处理触发的任务 // 处理触发的任务
func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) {
uid := session.GetUserId() uid := session.GetUserId()
var condis []*rtaskCondi
var handles []*rtaskCondHandle
if this.IsCross() { if this.IsCross() {
//随机任务 //随机任务
@ -285,18 +289,18 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com
return return
} }
condis = this.getHandle(rtaskType) handles = this.getHandle(rtaskType)
// update // update
for _, v := range condis { for _, handle := range handles {
conf, err := this.configure.getRtaskTypeById(v.condId) conf, err := this.configure.getRtaskTypeById(handle.condId)
if err != nil { if err != nil {
log.Debug("任务配置未找到", log.Field{Key: "condId", Value: v.condId}) log.Debug("任务配置未找到", log.Field{Key: "condId", Value: handle.condId})
code = pb.ErrorCode_RtaskCondiNoFound code = pb.ErrorCode_RtaskCondiNoFound
return return
} }
if v.update != nil { if handle.update != nil {
if err := v.update(uid, conf, params...); err != nil { if err := handle.update(uid, conf, params...); err != nil {
log.Errorf("update task:%v", err) log.Errorf("update task:%v", err)
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
@ -349,27 +353,52 @@ func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType com
} }
func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) { func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) {
this.Debug("任务处理",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "params", Value: taskParams})
session, ok := this.GetUserSession(uid) session, ok := this.GetUserSession(uid)
if !ok { if !ok {
return return
} }
lock, _ := this.modelRtask.userlock(uid) lock, _ := this.modelRtask.userlock(uid)
err := lock.Lock() err := lock.Lock()
if err != nil { if err != nil {
this.Error("TriggerTask userlock err!", log.Field{Key: "err", Value: err.Error()}) this.Error("TriggerTask userlock err!", log.Field{Key: "err", Value: err.Error()})
} }
defer lock.Unlock() defer lock.Unlock()
for _, tp := range taskParams {
if code := this.processOneTask(session, tp.TT, tp.Params...); code != pb.ErrorCode_Success {
record := &pb.DBRtaskRecord{Uid: uid}
if err := this.modelRtaskRecord.Get(uid, record); err != nil {
if err == mongo.ErrNoDocuments {
record.Id = primitive.NewObjectID().Hex()
record.Ctime = configure.Now().Unix()
if err := this.modelRtaskRecord.Add(uid, record); err != nil {
return
} }
}
}
this.modelRtaskRecord.record = record
for _, tp := range taskParams {
this.Debug("任务触发",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "type", Value: tp.TT},
log.Field{Key: "params", Value: tp.Params})
if code := this.processOneTask(session, tp.TT, tp.Params...); code != pb.ErrorCode_Success {
// this.Error("任务处理", log.Field{Key: "uid", Value: uid}, log.Field{Key: "code", Value: code})
}
session.Push() session.Push()
comm.PuttaskParam(tp) comm.PuttaskParam(tp)
} }
update := map[string]interface{}{
"vals": record.Vals,
}
this.modelRtaskRecord.Change(uid, update)
this.PutUserSession(session) this.PutUserSession(session)
return return
} }

View File

@ -2,14 +2,9 @@
package rtask package rtask
import ( import (
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
) )
// 覆盖更新 // 覆盖更新
@ -19,93 +14,79 @@ func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCond
return err return err
} }
record := &pb.DBRtaskRecord{Uid: uid} // record := &pb.DBRtaskRecord{Uid: uid}
if err := this.Get(uid, record); err != nil { // if err := this.Get(uid, record); err != nil {
if err == mongo.ErrNoDocuments { // if err == mongo.ErrNoDocuments {
record.Id = primitive.NewObjectID().Hex() // record.Id = primitive.NewObjectID().Hex()
record.Ctime = configure.Now().Unix() // record.Ctime = configure.Now().Unix()
if err := this.Add(uid, record); err != nil { // if err := this.Add(uid, record); err != nil {
return errors.Wrapf(err, "创建玩家任务记录 err: %v rtype[%v]", uid, cfg.Id) // return errors.Wrapf(err, "创建玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
} // }
} else { // } else {
return errors.Wrapf(err, "获取玩家任务记录 err: %v rtype[%v]", uid, cfg.Id) // return errors.Wrapf(err, "获取玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
} // }
// }
if this.record.Vals == nil {
this.record.Vals = make(map[int32]*pb.RtaskData)
} }
if record.Vals == nil { if v, ok := this.record.Vals[cfg.Id]; ok {
record.Vals = make(map[int32]*pb.RtaskData)
}
if v, ok := record.Vals[cfg.Id]; ok {
this.moduleRtask.Debug("覆盖更新前",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "v", Value: v},
log.Field{Key: "paramLen", Value: paramLen},
log.Field{Key: "vals", Value: vals},
log.Field{Key: "cfgId", Value: cfg.Id},
)
v.Data = hasUpdateData(paramLen, v, vals...) v.Data = hasUpdateData(paramLen, v, vals...)
this.moduleRtask.Debug("覆盖更新后", // if len(v.Data) > 0 {
log.Field{Key: "uid", Value: uid}, // update := map[string]interface{}{
log.Field{Key: "v", Value: v.Data}, // "vals": record.Vals,
log.Field{Key: "paramLen", Value: paramLen}, // }
log.Field{Key: "vals", Value: vals}, // if err = this.Change(uid, update); err != nil {
log.Field{Key: "cfgId", Value: cfg.Id}, // this.moduleRtask.Error("更新失败",
) // log.Field{Key: "uid", Value: uid},
if len(v.Data) > 0 { // log.Field{Key: "update", Value: update})
update := map[string]interface{}{ // return
"vals": record.Vals, // }
} // }
if err = this.Change(uid, update); err != nil {
this.moduleRtask.Error("更新失败",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "update", Value: update})
return
}
}
} else { } else {
data := &pb.RtaskData{ data := &pb.RtaskData{
Rtype: cfg.Type, Rtype: cfg.Type,
Data: toMap(vals...), Data: toMap(vals...),
Timestamp: configure.Now().Unix(), Timestamp: configure.Now().Unix(),
} }
record.Vals[cfg.Id] = data this.record.Vals[cfg.Id] = data
update := map[string]interface{}{ // update := map[string]interface{}{
"vals": record.Vals, // "vals": record.Vals,
} // }
if err = this.Change(uid, update); err != nil { // if err = this.Change(uid, update); err != nil {
this.moduleRtask.Error("更新失败", // this.moduleRtask.Error("更新失败",
log.Field{Key: "uid", Value: uid}, // log.Field{Key: "uid", Value: uid},
log.Field{Key: "update", Value: update}) // log.Field{Key: "update", Value: update})
return // return
} // }
} }
return return
} }
// 累计更新 - 招募等 // 累计更新 - 招募等
func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData, vals ...int32) (err error) { func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData, vals ...int32) (err error) {
record := &pb.DBRtaskRecord{Uid: uid} // record := &pb.DBRtaskRecord{Uid: uid}
err = this.Get(uid, record) // err = this.Get(uid, record)
if err != nil { // if err != nil {
if err == mongo.ErrNoDocuments { // if err == mongo.ErrNoDocuments {
record.Id = primitive.NewObjectID().Hex() // record.Id = primitive.NewObjectID().Hex()
record.Ctime = configure.Now().Unix() // record.Ctime = configure.Now().Unix()
if err := this.Add(uid, record); err != nil { // if err := this.Add(uid, record); err != nil {
return errors.Wrapf(err, "创建玩家任务记录 err: %v rtype[%v]", uid, cfg.Id) // return errors.Wrapf(err, "创建玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
} // }
} else { // } else {
return errors.Wrapf(err, "获取玩家任务记录 err: %v rtype[%v]", uid, cfg.Id) // return errors.Wrapf(err, "获取玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
} // }
} // }
if record.Vals == nil { if this.record.Vals == nil {
record.Vals = make(map[int32]*pb.RtaskData) this.record.Vals = make(map[int32]*pb.RtaskData)
} }
//查找任务数据 //查找任务数据
if v, ok := record.Vals[cfg.Id]; ok { if v, ok := this.record.Vals[cfg.Id]; ok {
newArr := make([]int32, len(vals)) newArr := make([]int32, len(vals))
copy(newArr, vals) copy(newArr, vals)
srcCount := v.Data[0] srcCount := v.Data[0]
@ -113,20 +94,20 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData
v.Data = toMap(newArr...) v.Data = toMap(newArr...)
v.Timestamp = configure.Now().Unix() v.Timestamp = configure.Now().Unix()
update := map[string]interface{}{ // update := map[string]interface{}{
"vals": record.Vals, // "vals": record.Vals,
} // }
err = this.Change(uid, update) // err = this.Change(uid, update)
} else { } else {
record.Vals[cfg.Id] = &pb.RtaskData{ this.record.Vals[cfg.Id] = &pb.RtaskData{
Data: toMap(vals...), Data: toMap(vals...),
Rtype: cfg.Type, Rtype: cfg.Type,
Timestamp: configure.Now().Unix(), Timestamp: configure.Now().Unix(),
} }
update := map[string]interface{}{ // update := map[string]interface{}{
"vals": record.Vals, // "vals": record.Vals,
} // }
err = this.Change(uid, update) // err = this.Change(uid, update)
} }
return return
} }

View File

@ -11,7 +11,7 @@ import (
// 战斗结束的请求 // 战斗结束的请求
func (this *apiComp) BattlefinishCheck(session comm.IUserSession, req *pb.WorldtaskBattleFinishReq) (code pb.ErrorCode) { func (this *apiComp) BattlefinishCheck(session comm.IUserSession, req *pb.WorldtaskBattleFinishReq) (code pb.ErrorCode) {
if req.GroupId <= 0 || req.CondiId <= 0 || req.BattleConfId <= 0 || req.TaskId <= 0 || req.Report == nil { if req.GroupId <= 0 || req.BattleConfId <= 0 || req.TaskId <= 0 || req.Report == nil {
this.module.Error("世界任务战斗结束参数错误", this.module.Error("世界任务战斗结束参数错误",
log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "uid", Value: session.GetUserId()},
log.Field{Key: "params", Value: req.String()}, log.Field{Key: "params", Value: req.String()},
@ -87,9 +87,18 @@ func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBa
if userTask.CurrentTask == nil { if userTask.CurrentTask == nil {
userTask.CurrentTask = make(map[int32]*pb.Worldtask) userTask.CurrentTask = make(map[int32]*pb.Worldtask)
} }
if req.CondiId != 0 {
if _, ok := utils.Findx(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId); !ok { if _, ok := utils.Findx(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId); !ok {
userTask.CurrentTask[req.GroupId].CondiIds = append(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId) userTask.CurrentTask[req.GroupId].CondiIds = append(userTask.CurrentTask[req.GroupId].CondiIds, req.CondiId)
} }
} else {
for _, condId := range taskConf.Completetask {
if _, ok := utils.Findx(userTask.CurrentTask[req.GroupId].CondiIds, condId); !ok {
userTask.CurrentTask[req.GroupId].CondiIds = append(userTask.CurrentTask[req.GroupId].CondiIds, condId)
}
}
}
update := map[string]interface{}{ update := map[string]interface{}{
"currentTask": userTask.CurrentTask, "currentTask": userTask.CurrentTask,
@ -105,6 +114,12 @@ func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBa
TaskId: req.TaskId, TaskId: req.TaskId,
CondiIds: userTask.CurrentTask[req.GroupId].CondiIds, CondiIds: userTask.CurrentTask[req.GroupId].CondiIds,
}) })
//结束任务
if taskConf.DeliverNpc == 0 {
this.module.modelWorldtask.taskFinish(session, req.GroupId, req.TaskId, userTask, taskConf)
this.module.modelWorldtask.taskFinishPush(session, req.GroupId, userTask, taskConf)
}
} }
this.module.Debug("校验战报", this.module.Debug("校验战报",
log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "uid", Value: session.GetUserId()},