This commit is contained in:
wh_zcy 2022-12-19 21:00:26 +08:00
parent 7b97e81b28
commit 178a325df9
5 changed files with 69 additions and 41 deletions

View File

@ -64,7 +64,7 @@ func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCond
} }
} }
log.Debug("覆盖数值更新", log.Fields{"uid": uid, "condiId": cfg.Id, "params": vals, "updated": record.Vals[cfg.Id]}) log.Debug("覆盖数值更新", log.Fields{"uid": uid, "condiId": cfg.Id, "params": vals, "updated": record.Vals[cfg.Id]})
this.listenTask(uid, cfg.Id) // this.listenTask(uid, cfg.Id)
return return
} }
@ -112,7 +112,7 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData
} }
log.Debug("累计次数更新", log.Fields{"uid": uid, "condiId": cfg.Id, "params": vals, "updated": record.Vals[cfg.Id]}) log.Debug("累计次数更新", log.Fields{"uid": uid, "condiId": cfg.Id, "params": vals, "updated": record.Vals[cfg.Id]})
this.listenTask(uid, cfg.Id) // this.listenTask(uid, cfg.Id)
return return
} }

View File

@ -36,29 +36,20 @@ func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActive
return return
} }
var rewards []*cfg.Gameatn var rewards []*cfg.Gameatn
var flag bool
update := map[string]interface{}{}
// 玩家的 // 玩家的
activeList := this.moduleTask.modelTaskActive.getActiveListByTag(uid, comm.TaskTag(req.TaskTag)) activeList := this.moduleTask.modelTaskActive.getActiveList(uid)
var activityData *pb.ActivityData // var activityData *pb.ActivityData
for _, v := range activeList { for _, v := range activeList {
if v.TaskId == req.Id { if v.TaskId == req.Id {
activityData = v if v.Received != 1 {
break conf := this.moduleTask.configure.getTaskActiveById(v.TaskId)
}
}
if activityData == nil {
code = pb.ErrorCode_TaskNotFound
return
}
if activityData.Received != 1 { //未领取
conf := this.moduleTask.configure.getTaskActiveById(activityData.TaskId)
if conf == nil { if conf == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
return return
} }
update := make(map[string]interface{})
if req.TaskTag == int32(comm.TASK_DAILY) { if req.TaskTag == int32(comm.TASK_DAILY) {
if ue.Activeday < conf.Active { if ue.Activeday < conf.Active {
code = pb.ErrorCode_TaskActiveNoenough code = pb.ErrorCode_TaskActiveNoenough
@ -70,16 +61,24 @@ func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActive
return return
} }
} }
update["received"] = 1
if len(update) > 0 { v.Received = 1
if err := this.moduleTask.modelTaskActive.updateReceive(session.GetUserId(), update); err != nil { flag = true
rewards = append(rewards, conf.Reword...)
}
break
}
}
if flag {
update["activityList"] = activeList
if err := this.moduleTask.modelTaskActive.Change(session.GetUserId(), update); err != nil {
this.moduleTask.Errorf("updateReceive err %v", err) this.moduleTask.Errorf("updateReceive err %v", err)
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
} }
rewards = append(rewards, conf.Reword...)
}
if len(rewards) > 0 { if len(rewards) > 0 {
//派发奖励 //派发奖励

View File

@ -104,10 +104,23 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
} }
//更新用户领取状态 //更新用户领取状态
update := map[string]interface{}{ for _, v := range taskDataList {
"received": 1, if v.TaskId == req.Id {
v.Received = 1
break
} }
if err := this.moduleTask.modelTask.modifyUserTask(session.GetUserId(), taskData.TaskId, update); err != nil { }
update := map[string]interface{}{}
switch req.TaskTag {
case int32(comm.TASK_DAILY):
update["dayList"] = taskDataList
case int32(comm.TASK_WEEKLY):
update["weekList"] = taskDataList
case int32(comm.TASK_ACHIEVE):
update["achieveList"] = taskDataList
}
if err := this.moduleTask.modelTask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }

View File

@ -62,6 +62,16 @@ func (this *ModelTaskActive) initActiveReward(uid string, taskTag comm.TaskTag)
} }
} }
func (this *ModelTaskActive) getActiveList(uid string) (list []*pb.ActivityData) {
task := &pb.DBActivity{}
if err := this.Get(uid, task); err != nil {
this.moduleTask.Errorf("getTaskList err %v", err)
return
}
return task.ActivityList
}
//获取玩家活跃度列表 //获取玩家活跃度列表
func (this *ModelTaskActive) getActiveListByTag(uid string, taskTag comm.TaskTag) (list []*pb.ActivityData) { func (this *ModelTaskActive) getActiveListByTag(uid string, taskTag comm.TaskTag) (list []*pb.ActivityData) {
task := &pb.DBActivity{} task := &pb.DBActivity{}

View File

@ -82,6 +82,7 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
return nil return nil
} }
update := map[string]interface{}{}
var dataList []*pb.TaskData var dataList []*pb.TaskData
if taskTag == comm.TASK_DAILY { if taskTag == comm.TASK_DAILY {
dataList = task.DayList dataList = task.DayList
@ -90,7 +91,6 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
} }
// 筛选出指定tag的任务 // 筛选出指定tag的任务
update := map[string]interface{}{}
var flag bool var flag bool
for _, v := range dataList { for _, v := range dataList {
oldVal := v.Progress oldVal := v.Progress
@ -112,8 +112,13 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
} }
} }
if flag { if flag {
update["dayList"] = task.DayList if taskTag == comm.TASK_DAILY {
if err := this.moduleTask.modelTask.Change("uid", update); err != nil { update["dayList"] = dataList
} else if taskTag == comm.TASK_WEEKLY {
update["weekList"] = dataList
}
if err := this.moduleTask.modelTask.Change(uid, update); err != nil {
log.Error("更新每日任务", log.Fields{"uid": uid}) log.Error("更新每日任务", log.Fields{"uid": uid})
} }
} }
@ -325,6 +330,7 @@ func (this *ModelTask) checkTask(uid string, taskId int32) (*pb.TaskData, bool)
} }
//更改用户任务 //更改用户任务
// Deprecated
func (this *ModelTask) modifyUserTask(uid string, taskId int32, data map[string]interface{}) error { func (this *ModelTask) modifyUserTask(uid string, taskId int32, data map[string]interface{}) error {
var task *pb.DBTask var task *pb.DBTask
if err := this.GetList(uid, &task); err != nil { if err := this.GetList(uid, &task); err != nil {