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]})
this.listenTask(uid, cfg.Id)
// this.listenTask(uid, cfg.Id)
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]})
this.listenTask(uid, cfg.Id)
// this.listenTask(uid, cfg.Id)
return
}

View File

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

View File

@ -104,10 +104,23 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
}
//更新用户领取状态
update := map[string]interface{}{
"received": 1,
for _, v := range taskDataList {
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
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) {
task := &pb.DBActivity{}

View File

@ -82,6 +82,7 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
return nil
}
update := map[string]interface{}{}
var dataList []*pb.TaskData
if taskTag == comm.TASK_DAILY {
dataList = task.DayList
@ -90,7 +91,6 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
}
// 筛选出指定tag的任务
update := map[string]interface{}{}
var flag bool
for _, v := range dataList {
oldVal := v.Progress
@ -112,8 +112,13 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) *pb.DB
}
}
if flag {
update["dayList"] = task.DayList
if err := this.moduleTask.modelTask.Change("uid", update); err != nil {
if taskTag == comm.TASK_DAILY {
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})
}
}
@ -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 {
var task *pb.DBTask
if err := this.GetList(uid, &task); err != nil {