优化任务通知接口

This commit is contained in:
wh_zcy 2023-05-26 10:59:32 +08:00
parent 74f5d0328f
commit 25f4dd7bfb
4 changed files with 51 additions and 64 deletions

View File

@ -354,7 +354,7 @@ type (
// 设置工会活跃度 // 设置工会活跃度
BingoSetActivity(session IUserSession, activity int32) error BingoSetActivity(session IUserSession, activity int32) error
// 任务条件达成通知 // 任务条件达成通知
TaskcondNotify(uid string, condId int32) error TaskcondNotify(uid string, condIds []int32) error
// 红点 // 红点
IReddot IReddot
} }
@ -390,11 +390,7 @@ type (
// 世界任务 // 世界任务
IWorldtask interface { IWorldtask interface {
// 任务条件达成通知 // 任务条件达成通知
// Deprecated TaskCondFinishNotify(session IUserSession, condIds []int32) error
// TaskcondNotify(session IUserSession, condId int32) error
TaskCondFinishNotify(session IUserSession, condId int32) error
// bingo所有任务
// BingoAllTask(session IUserSession) error
// bingo任务 // bingo任务
BingoJumpTask(session IUserSession, groupId, rtaskId int32) error BingoJumpTask(session IUserSession, groupId, rtaskId int32) error
// 查询我的世界任务 // 查询我的世界任务

View File

@ -340,47 +340,36 @@ func (this *ModuleRtask) processTasks(session comm.IUserSession, taskParams ...*
//去重 //去重
condIds = removeDuplicate(condIds) condIds = removeDuplicate(condIds)
//带通知的condIds
var condIdsForNotify []int32
for _, condId := range condIds { for _, condId := range condIds {
r, _ := record.Vals[condId] r, _ := record.Vals[condId]
conf, _ := this.configure.getRtaskTypeById(condId) conf, _ := this.configure.getRtaskTypeById(condId)
if r.Data[0] >= conf.Data1 { if r.Data[0] >= conf.Data1 {
condIdsForNotify = append(condIdsForNotify, condId)
}
}
if len(condIdsForNotify) == 0 {
return
}
//通知世界任务模块
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.TaskCondFinishNotify(session, condId); err != nil { if err := worldtask.TaskCondFinishNotify(session, condIdsForNotify); err != nil {
// log.Error("世界任务条件达成通知",
// log.Field{Key: "uid", Value: uid},
// log.Field{Key: "condId", Value: condId},
// log.Field{Key: "err", Value: err.Error()},
// )
} }
} }
} }
// userModule, err := this.service.GetModule(comm.ModuleUser) // 通知公会任务模块
// if err == nil {
// // 公会
// if user, ok := userModule.(comm.IUser); ok {
// ex, err := user.GetUserExpand(uid)
// if err == nil && ex.SociatyId != "" {
sociatyModule, err := this.service.GetModule(comm.ModuleSociaty) sociatyModule, err := this.service.GetModule(comm.ModuleSociaty)
if err != nil { if err != nil {
return return
} }
if sociaty, ok := sociatyModule.(comm.ISociaty); ok { if sociaty, ok := sociatyModule.(comm.ISociaty); ok {
if err2 := sociaty.TaskcondNotify(uid, condId); err2 != nil { if err2 := sociaty.TaskcondNotify(uid, condIds); err2 != nil {
// log.Error("公会任务条件达成通知",
// log.Field{Key: "uid", Value: uid},
// log.Field{Key: "sociatyId", Value: ex.SociatyId},
// log.Field{Key: "condId", Value: condId},
// log.Field{Key: "err", Value: err2.Error()},
// )
}
}
// }
// }
// }
} }
} }
} }

View File

@ -239,7 +239,7 @@ type TaskParams struct {
} }
// 任务条件达成通知 // 任务条件达成通知
func (this *Sociaty) TaskcondNotify(uid string, condId int32) error { func (this *Sociaty) TaskcondNotify(uid string, condIds []int32) error {
// log.Debug("公会任务", // log.Debug("公会任务",
// log.Field{Key: "uid", Value: uid}, // log.Field{Key: "uid", Value: uid},
// log.Field{Key: "sociatyId", Value: sociatyId}, // log.Field{Key: "sociatyId", Value: sociatyId},
@ -247,7 +247,7 @@ func (this *Sociaty) TaskcondNotify(uid string, condId int32) error {
sociaty := this.modelSociaty.getUserSociaty(uid) sociaty := this.modelSociaty.getUserSociaty(uid)
if sociaty == nil { if sociaty == nil {
return fmt.Errorf("公会未找到 uid:%v condId:%v", uid, condId) return fmt.Errorf("公会未找到 uid:%v condIds:%v", uid, condIds)
} }
sociatyId := sociaty.Id sociatyId := sociaty.Id
@ -259,10 +259,11 @@ func (this *Sociaty) TaskcondNotify(uid string, condId int32) error {
var flag bool var flag bool
for _, v := range dt.TaskList { for _, v := range dt.TaskList {
for _, condId := range condIds {
if v.TaskId == condId { if v.TaskId == condId {
v.Status = 1 v.Status = 1
flag = true flag = true
break }
} }
} }
if !flag { if !flag {

View File

@ -55,15 +55,13 @@ func (this *Worldtask) Start() (err error) {
} }
// 任务条件达成通知 // 任务条件达成通知
func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId int32) error { func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condIds []int32) error {
this.Debug("世界任务完成条件通知", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "condIds", Value: condIds})
this.Debug("世界任务完成条件通知", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "condId", Value: condId})
uid := session.GetUserId() uid := session.GetUserId()
// 玩家世界任务 // 玩家世界任务
userTask, err := this.modelWorldtask.getWorldtask(uid) userTask, err := this.modelWorldtask.getWorldtask(uid)
if err != nil { if err != nil {
this.Error("获取玩家世界任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condId", Value: condId}) this.Error("获取玩家世界任务", log.Field{Key: "uid", Value: uid})
return err return err
} }
@ -72,6 +70,7 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in
finishedTaskIds := make(map[int32]int32) //达成的任务条件 finishedTaskIds := make(map[int32]int32) //达成的任务条件
for _, c := range this.worldtaskConf.GetDataList() { for _, c := range this.worldtaskConf.GetDataList() {
for _, v := range c.Completetask { for _, v := range c.Completetask {
for _, condId := range condIds {
if v == condId { if v == condId {
//校验任务是否是当前任务 //校验任务是否是当前任务
if task, ok := userTask.CurrentTask[c.Group]; ok { if task, ok := userTask.CurrentTask[c.Group]; ok {
@ -85,6 +84,7 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in
} }
} }
} }
}
if len(finishedTaskIds) == 0 { if len(finishedTaskIds) == 0 {
// this.Debug("未找到通知的世界任务", // this.Debug("未找到通知的世界任务",
@ -102,13 +102,14 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in
wt = &pb.Worldtask{} wt = &pb.Worldtask{}
} }
for _, condId := range condIds {
if _, ok := utils.Findx(wt.CondiIds, condId); !ok { if _, ok := utils.Findx(wt.CondiIds, condId); !ok {
wt.CondiIds = append(wt.CondiIds, condId) wt.CondiIds = append(wt.CondiIds, condId)
} }
}
userTask.CurrentTask[groupId] = wt userTask.CurrentTask[groupId] = wt
//this.Debug("当前任务更新", log.Field{Key: "currentTask", Value: userTask.CurrentTask})
update := map[string]interface{}{ update := map[string]interface{}{
"currentTask": userTask.CurrentTask, "currentTask": userTask.CurrentTask,
} }