世界任务多组支持

This commit is contained in:
wh_zcy 2023-03-27 16:47:42 +08:00
parent 397ab14b79
commit b53972e79f
14 changed files with 329 additions and 334 deletions

View File

@ -79,8 +79,43 @@ func (this *WorldtaskMineView) CreateView(t *model.TestCase) fyne.CanvasObject {
dconf.Show() dconf.Show()
}) })
// 完成任务 // 完成任务条件
this.juqingBtn = widget.NewButton("完成任务", func() { completeBtn := widget.NewButton("任务条件", func() {
groupId := widget.NewEntry()
groupId.PlaceHolder = "分组ID"
taskIdEntry := widget.NewEntry()
taskIdEntry.PlaceHolder = "任务ID"
condiId := widget.NewEntry()
condiId.PlaceHolder = "条件"
form := widget.NewForm(
widget.NewFormItem("组ID", groupId),
widget.NewFormItem("任务ID", taskIdEntry),
widget.NewFormItem("完成条件", condiId),
)
dconf := dialog.NewCustom("完成条件", "关闭", form, this.w)
form.OnSubmit = func() {
if err := service.GetPttService().SendToClient(
t.MainType,
"completecondi",
&pb.WorldtaskCompleteCondiReq{
GroupId: cast.ToInt32(groupId.Text),
TaskId: cast.ToInt32(taskIdEntry.Text),
CondiId: cast.ToInt32(condiId.Text),
}); err != nil {
logrus.Error(err)
}
dconf.Hide()
this.mineReq()
}
form.SubmitText = "确定"
dconf.Resize(fyne.NewSize(400, 200))
dconf.Show()
})
// 交付任务
this.juqingBtn = widget.NewButton("交付任务", func() {
groupId := widget.NewEntry() groupId := widget.NewEntry()
groupId.PlaceHolder = "分组ID" groupId.PlaceHolder = "分组ID"
taskIdEntry := widget.NewEntry() taskIdEntry := widget.NewEntry()
@ -141,7 +176,7 @@ func (this *WorldtaskMineView) CreateView(t *model.TestCase) fyne.CanvasObject {
dconf.Resize(fyne.NewSize(400, 200)) dconf.Resize(fyne.NewSize(400, 200))
dconf.Show() dconf.Show()
}) })
barBtn := container.NewHBox(refreshBtn, acceptBtn, this.juqingBtn, battleBtn) barBtn := container.NewHBox(refreshBtn, acceptBtn, completeBtn, this.juqingBtn, battleBtn)
c := container.NewBorder(barBtn, nil, nil, nil, this.itemList.ItemList) c := container.NewBorder(barBtn, nil, nil, nil, this.itemList.ItemList)
this.mineData() this.mineData()
@ -173,8 +208,8 @@ func (this *WorldtaskMineView) mineData() {
for _, v := range rsp.Task.TaskList { for _, v := range rsp.Task.TaskList {
item := common.Item{ item := common.Item{
Id: cast.ToString(v.TaskId), Id: cast.ToString(v),
Text: fmt.Sprintf("%d - 类型:%v", v.TaskId, v.TaskType), Text: fmt.Sprintf("%d ", v),
} }
this.itemList.AddItem(item) this.itemList.AddItem(item)
} }

View File

@ -370,7 +370,7 @@ type (
IWorldtask interface { IWorldtask interface {
// 任务条件达成通知 // 任务条件达成通知
// Deprecated // Deprecated
TaskcondNotify(session IUserSession, condId int32) error // TaskcondNotify(session IUserSession, condId int32) error
TaskCondFinishNotify(session IUserSession, condId int32) error TaskCondFinishNotify(session IUserSession, condId int32) error
// bingo所有任务 // bingo所有任务
BingoAllTask(session IUserSession) error BingoAllTask(session IUserSession) error

View File

@ -321,7 +321,8 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
} }
stime := time.Now() stime := time.Now()
// this.gateway.Debugf("----------3 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) // this.gateway.Debugf("----------3 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
ctx, _ := context.WithTimeout(context.Background(), time.Second*5) // ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
ctx := context.Background()
if len(serviceTag) == 0 { if len(serviceTag) == 0 {
// this.gateway.Debugf("----------4 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) // this.gateway.Debugf("----------4 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
if err = this.gateway.Service().RpcCall(ctx, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil { if err = this.gateway.Service().RpcCall(ctx, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil {

View File

@ -91,7 +91,7 @@ func (this *modelFetterstory) getMaintasks(uid string, fetterId int32) (list []*
for _, taskId := range mainTasks.Tasks { for _, taskId := range mainTasks.Tasks {
// 遍历已完成的世界任务 // 遍历已完成的世界任务
for _, task := range wt.TaskList { for _, task := range wt.TaskList {
if taskId == task.TaskId { if taskId == task {
list = append(list, &pb.FetterTask{ list = append(list, &pb.FetterTask{
TaskId: taskId, TaskId: taskId,
Status: 1, Status: 1,

View File

@ -88,7 +88,7 @@ func (this *ModelLinestory) getMaintasks(uid string, groupId int32) (list []*pb.
for _, conf := range mainTasks { for _, conf := range mainTasks {
// 遍历已完成的世界任务 // 遍历已完成的世界任务
for _, task := range wt.TaskList { for _, task := range wt.TaskList {
if conf.Id == task.TaskId { if conf.Id == task {
list = append(list, &pb.TaskMain{ list = append(list, &pb.TaskMain{
TaskId: conf.Id, TaskId: conf.Id,
Status: 1, Status: 1,

View File

@ -80,7 +80,7 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo
} }
conf, err := this.moduleRtask.configure.getRtaskTypeById(condiId) conf, err := this.moduleRtask.configure.getRtaskTypeById(condiId)
if err != nil { if err != nil || conf == nil {
errors.Errorf("conf not found condiID: %v", condiId) errors.Errorf("conf not found condiID: %v", condiId)
return return
} }

View File

@ -550,81 +550,6 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
} }
} }
//任务完成则推送
if code = this.CheckCondi(uid, conf.Id); code == pb.ErrorCode_Success {
module, err := this.service.GetModule(comm.ModuleWorldtask)
if err == nil {
// go func() {
// defer func() {
// if r := recover(); r != nil {
// log.Errorf("[worldtask ] err:%v ", r)
// }
// }()
// 世界任务
if worldtask, ok := module.(comm.IWorldtask); ok {
if err := worldtask.TaskcondNotify(session, conf.Id); err != nil {
var customErr = new(comm.CustomError)
if errors.As(err, &customErr) {
notifyErr := &pb.NotifyErrorNotifyPush{
ReqMainType: string(comm.ModuleWorldtask),
ReqSubType: "finish",
Message: "",
}
if customErr.Code == pb.ErrorCode_WorldtaskLvNotEnough {
notifyErr.Code = pb.ErrorCode_WorldtaskLvNotEnough
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
} else if customErr.Code == pb.ErrorCode_UserSessionNobeing {
notifyErr.Code = pb.ErrorCode_UserSessionNobeing
session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr)
} else {
log.Error("任务条件达成通知",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "condId", Value: conf.Id},
log.Field{Key: "err", Value: err.Error()},
)
}
}
}
}
// }()
}
userModule, err := this.service.GetModule(comm.ModuleUser)
if err == nil {
// go func() {
// defer func() { //程序异常 收集异常信息传递给前端显示
// if r := recover(); r != nil {
// log.Errorf("[sociatytask ] err:%v ", r)
// }
// }()
// 公会
if user, ok := userModule.(comm.IUser); ok {
ex, err := user.GetUserExpand(session.GetUserId())
if err == nil && ex.SociatyId != "" {
sociatyModule, err := this.service.GetModule(comm.ModuleSociaty)
if err != nil {
return
}
if sociaty, ok := sociatyModule.(comm.ISociaty); ok {
if err2 := sociaty.TaskcondNotify(uid, ex.SociatyId, conf.Id); err2 != nil {
log.Error("公会任务条件达成通知",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "sociatyId", Value: ex.SociatyId},
log.Field{Key: "condId", Value: conf.Id},
log.Field{Key: "err", Value: err2.Error()},
)
}
if module, err := this.service.GetModule(comm.ModuleRtask); err == nil {
if iRtask, ok := module.(comm.IRtask); ok {
iRtask.SendToRtask(session, comm.Rtype156, 1)
}
}
}
}
}
// }()
}
}
} }
return return
@ -652,8 +577,8 @@ func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam)
// 任务条件校验 // 任务条件校验
func (this *ModuleRtask) CheckCondi(uid string, condiId int32) (code pb.ErrorCode) { func (this *ModuleRtask) CheckCondi(uid string, condiId int32) (code pb.ErrorCode) {
// this.Debug("检查任务条件", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condiId", Value: condiId})
if _, ok := this.modelRtask.checkCondi(uid, condiId); !ok { if _, ok := this.modelRtask.checkCondi(uid, condiId); !ok {
// this.Debug("任务条件未达到", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condiId", Value: condiId})
code = pb.ErrorCode_RtaskCondiNoReach code = pb.ErrorCode_RtaskCondiNoReach
} }
return return

View File

@ -42,9 +42,10 @@ func (a *apiComp) Accept(session comm.IUserSession, req *pb.WorldtaskAcceptReq)
TaskType: 2, TaskType: 2,
} }
myWorldtask.CurrentTask[curTaskConf.Group].NpcStatus=1
update := map[string]interface{}{ update := map[string]interface{}{
"currentTaskIds": myWorldtask.CurrentTask, "currentTask": myWorldtask.CurrentTask,
"npcStatus": 1,
} }
if err := a.module.modelWorldtask.Change(uid, update); err != nil { if err := a.module.modelWorldtask.Change(uid, update); err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError

View File

@ -4,6 +4,7 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -35,12 +36,19 @@ func (this *apiComp) CompleteCondi(session comm.IUserSession, req *pb.WorldtaskC
if code = iwt.CheckCondi(uid, req.CondiId); code != pb.ErrorCode_Success { if code = iwt.CheckCondi(uid, req.CondiId); code != pb.ErrorCode_Success {
return return
} }
wt.CondiIds = append(wt.CondiIds, req.CondiId) if wt == nil {
wt = &pb.Worldtask{}
}
if _, b := utils.Findx(wt.CondiIds, req.CondiId); !b {
wt.CondiIds = append(wt.CondiIds, req.CondiId)
}
} }
} }
myWorldtask.CurrentTask[req.GroupId] = wt
update := map[string]interface{}{ update := map[string]interface{}{
"condiIds": wt.CondiIds, "currentTask": myWorldtask.CurrentTask,
} }
if err := this.module.modelWorldtask.Change(uid, update); err != nil { if err := this.module.modelWorldtask.Change(uid, update); err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError

View File

@ -68,45 +68,67 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
// 前置任务ID 只有世界任务才校验前置 // 前置任务ID 只有世界任务才校验前置
if curTaskConf.Des == 2 { if curTaskConf.Des == 2 {
if !this.module.modelWorldtask.IsPreFinished(userTask, curTaskConf) { if !this.module.modelWorldtask.IsPreFinished(req.GroupId, userTask, curTaskConf) {
this.module.Debug("前置任务未完成", log.Field{Key: "uid", Value: uid}, log.Field{Key: "preTaskId", Value: curTaskConf.Ontxe}, log.Field{Key: "taskId", Value: curTaskConf.Key}) this.module.Debug("前置任务未完成", log.Field{Key: "uid", Value: uid}, log.Field{Key: "preTaskId", Value: curTaskConf.Ontxe}, log.Field{Key: "taskId", Value: curTaskConf.Key})
code = pb.ErrorCode_WorldtaskLastUnFinished code = pb.ErrorCode_WorldtaskLastUnFinished
return return
} }
} }
updateCheckCond := func(taskIds []int32) *pb.DBWorldtask { updateCheckCond := func(nextTaskId int32) *pb.DBWorldtask {
for _, taskId := range taskIds { //检查下个任务的完成条件
//检查下个任务的完成条件 nextTaskConf, err := this.module.configure.getWorldtaskById(nextTaskId)
nextTaskConf, err := this.module.configure.getWorldtaskById(taskId) if err != nil || curTaskConf == nil {
if err != nil || curTaskConf == nil { code = pb.ErrorCode_ConfigNoFound
code = pb.ErrorCode_ConfigNoFound return nil
return nil }
} if nextTaskConf == nil {
return nil
}
if len(nextTaskConf.Completetask) == 1 && nextTaskConf.Completetask[0] == 0 { if userTask.CurrentTask == nil {
userTask.CurrentTask[req.GroupId].CondiIds = []int32{} userTask.CurrentTask = make(map[int32]*pb.Worldtask)
} else { }
for _, condiId := range nextTaskConf.Completetask {
if condiId == 0 { if req.GroupId != nextTaskId {
continue userTask.CurrentTask[nextTaskConf.Group] = &pb.Worldtask{
} TaskId: nextTaskId,
if m, err := this.module.service.GetModule(comm.ModuleRtask); err == nil { }
iwt, ok := m.(comm.IRtask) return userTask
if ok { }
if code = iwt.CheckCondi(uid, condiId); code != pb.ErrorCode_Success {
return nil if len(nextTaskConf.Completetask) == 1 && nextTaskConf.Completetask[0] == 0 {
} userTask.CurrentTask[nextTaskConf.Group].CondiIds = []int32{}
userTask.CurrentTask[req.GroupId].CondiIds = append(userTask.CurrentTask[req.GroupId].CondiIds, condiId) } else {
for _, condiId := range nextTaskConf.Completetask {
if condiId == 0 {
continue
}
if m, err := this.module.service.GetModule(comm.ModuleRtask); err == nil {
iwt, ok := m.(comm.IRtask)
if ok {
if code = iwt.CheckCondi(uid, condiId); code != pb.ErrorCode_Success {
return nil
} }
_, ok := userTask.CurrentTask[nextTaskConf.Group]
if ok {
userTask.CurrentTask[nextTaskConf.Group].CondiIds = append(userTask.CurrentTask[req.GroupId].CondiIds, condiId)
} else {
condiIds := []int32{condiId}
userTask.CurrentTask[nextTaskConf.Group] = &pb.Worldtask{
TaskId: nextTaskId,
CondiIds: condiIds,
}
}
} }
} }
} }
//设置当前进行的任务 }
userTask.CurrentTask[curTaskConf.Group] = &pb.Worldtask{ //设置当前进行的任务
TaskId: taskId, userTask.CurrentTask[curTaskConf.Group] = &pb.Worldtask{
TaskType: nextTaskConf.Des, TaskId: nextTaskId,
} TaskType: nextTaskConf.Des,
} }
update := map[string]interface{}{ update := map[string]interface{}{
@ -128,15 +150,23 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
} }
if curTaskConf.IdAfter != 0 { if curTaskConf.IdAfter != 0 {
nextTaskIds := this.module.modelWorldtask.findNextTasks(curTaskConf.Key) nextTaskIds := this.module.modelWorldtask.findNextTasks(curTaskConf.Key)
this.module.Debug("nextTaskIds", log.Field{Key: "nextTaskIds", Value: nextTaskIds})
userTask = updateCheckCond(nextTaskIds)
nextTask := make(map[int32]*pb.Worldtask) nextTask := make(map[int32]*pb.Worldtask)
for k, v := range userTask.CurrentTask { for _, next := range nextTaskIds {
nextTask[k] = &pb.Worldtask{ userTask = updateCheckCond(next)
CondiIds: v.CondiIds, if userTask != nil {
for k, v := range userTask.CurrentTask {
nextTask[k] = &pb.Worldtask{
TaskId: v.TaskId,
// CondiIds: v.CondiIds,
// NpcStatus: v.NpcStatus,
// DeliverNpc: v.DeliverNpc,
}
}
} }
} }
// 任务完成推送 // 任务完成推送
if err := session.SendMsg(string(this.module.GetType()), WorldtaskNexttaskPush, &pb.WorldtaskNexttaskPush{ if err := session.SendMsg(string(this.module.GetType()), WorldtaskNexttaskPush, &pb.WorldtaskNexttaskPush{
NextTask: nextTask, NextTask: nextTask,
@ -191,8 +221,8 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
} }
//判断任务是否已完成 //判断任务是否已完成
for _, t := range userTask.TaskList { for _, v := range userTask.TaskList {
if t.TaskId == req.TaskId { if v == req.TaskId {
this.module.Debug("任务已完成,返回下一个", this.module.Debug("任务已完成,返回下一个",
log.Field{Key: "uid", Value: uid}, log.Field{Key: "uid", Value: uid},
log.Field{Key: "taskId", Value: req.TaskId}, log.Field{Key: "taskId", Value: req.TaskId},

View File

@ -21,21 +21,7 @@ func (this *apiComp) Mine(session comm.IUserSession, req *pb.WorldtaskMineReq) (
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
var list []*pb.Worldtask
for _, v := range myWorldtask.TaskList {
if v.TaskType == 2 { //世界任务
list = append(list, v)
}
}
// var wtMp = make(map[int32]*pb.Worldtask)
// for k, v := range myWorldtask.LastTaskIds {
// if v.TaskType == 2 {
// wtMp[k] = v
// }
// }
// myWorldtask.LastTaskIds = wtMp
myWorldtask.TaskList = list
rsp := &pb.WorldtaskMineResp{ rsp := &pb.WorldtaskMineResp{
Task: myWorldtask, Task: myWorldtask,
} }

View File

@ -40,7 +40,7 @@ func (this *ModelWorldtask) getWorldtask(uid string) (*pb.DBWorldtask, error) {
// 判断前置任务是否完成 // 判断前置任务是否完成
// true 已完成 false未完成 // true 已完成 false未完成
func (this *ModelWorldtask) IsPreFinished(userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) bool { func (this *ModelWorldtask) IsPreFinished(groupId int32, userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) bool {
var ( var (
lastTaskId int32 lastTaskId int32
preTaskFinished bool preTaskFinished bool
@ -51,8 +51,8 @@ func (this *ModelWorldtask) IsPreFinished(userTask *pb.DBWorldtask, curTaskConf
lastTaskId = curTaskConf.Ontxe lastTaskId = curTaskConf.Ontxe
} }
for _, t := range userTask.TaskList { for _, v := range userTask.TaskList {
if lastTaskId == t.TaskId { if lastTaskId == v {
preTaskFinished = true preTaskFinished = true
} }
} }
@ -87,13 +87,21 @@ func (this *ModelWorldtask) finishTask(groupId, taskId int32, task *pb.DBWorldta
TaskId: taskId, TaskId: taskId,
TaskType: taskConf.Des, TaskType: taskConf.Des,
} }
task.TaskList = append(task.TaskList, wt)
task.TaskList = append(task.TaskList, taskId)
if task.CurrentTask == nil {
task.CurrentTask = make(map[int32]*pb.Worldtask)
}
wt.NpcStatus = 0
wt.DeliverNpc = 0
wt.CondiIds = []int32{}
task.CurrentTask[groupId] = wt
update["taskList"] = task.TaskList update["taskList"] = task.TaskList
update["deliverNpc"] = 1 update["currentTask"] = task.CurrentTask
update["condiIds"] = []int32{}
update["npcStatus"] = 0
update["deliverNpc"] = 0
if err := this.Change(task.Uid, update); err != nil { if err := this.Change(task.Uid, update); err != nil {
return err return err
} }

View File

@ -1,7 +1,6 @@
package worldtask package worldtask
import ( import (
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/base" "go_dreamfactory/lego/base"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
@ -85,11 +84,17 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in
userTask.CurrentTask = make(map[int32]*pb.Worldtask) userTask.CurrentTask = make(map[int32]*pb.Worldtask)
} }
wt := userTask.CurrentTask[groupId] wt, ok := userTask.CurrentTask[groupId]
if !ok {
wt = &pb.Worldtask{}
}
wt.CondiIds = append(wt.CondiIds, condId) wt.CondiIds = append(wt.CondiIds, condId)
userTask.CurrentTask[groupId] = wt
update := map[string]interface{}{ update := map[string]interface{}{
"condiIds": wt.CondiIds, "currentTask": userTask.CurrentTask,
} }
this.modelWorldtask.Change(uid, update) this.modelWorldtask.Change(uid, update)
@ -107,104 +112,104 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in
// 任务条件达成通知 // 任务条件达成通知
// Deprecated // Deprecated
func (this *Worldtask) TaskcondNotify(session comm.IUserSession, condId int32) error { // func (this *Worldtask) TaskcondNotify(session comm.IUserSession, condId int32) error {
uid := session.GetUserId() // uid := session.GetUserId()
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 {
if v == condId { // if v == condId {
finishedTaskIds[c.Group] = c.Key // finishedTaskIds[c.Group] = c.Key
} // }
} // }
} // }
if len(finishedTaskIds) == 0 { // if len(finishedTaskIds) == 0 {
//this.Debug("没有匹配到任务世界任务", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "condId", Value: condId}) // //this.Debug("没有匹配到任务世界任务", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "condId", Value: condId})
return nil // return nil
} // }
this.Debug("世界任务完成通知-查找到世界任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condId", Value: condId}, log.Field{Key: "params", Value: finishedTaskIds}) // this.Debug("世界任务完成通知-查找到世界任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condId", Value: condId}, log.Field{Key: "params", Value: finishedTaskIds})
//下一个任务ID // //下一个任务ID
var nextTaskId int32 // var nextTaskId int32
// 获取用户信息 // // 获取用户信息
user := this.ModuleUser.GetUser(uid) // user := this.ModuleUser.GetUser(uid)
if user == nil { // if user == nil {
return comm.NewCustomError(pb.ErrorCode_UserSessionNobeing) // return comm.NewCustomError(pb.ErrorCode_UserSessionNobeing)
} // }
// 玩家世界任务 // // 玩家世界任务
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}, log.Field{Key: "condId", Value: condId})
return err // return err
} // }
if userTask.Uid != "" { // if userTask.Uid != "" {
//查找任务ID根据condId 可能会找出不同的任务 // //查找任务ID根据condId 可能会找出不同的任务
for groupId, taskId := range finishedTaskIds { // for groupId, taskId := range finishedTaskIds {
logFields := []log.Field{{Key: "uid", Value: uid}, {Key: "group", Value: groupId}, {Key: "taskId", Value: taskId}, {Key: "condId", Value: condId}} // logFields := []log.Field{{Key: "uid", Value: uid}, {Key: "group", Value: groupId}, {Key: "taskId", Value: taskId}, {Key: "condId", Value: condId}}
// 判断任务是否已完成 // // 判断任务是否已完成
if this.modelWorldtask.isFinished(taskId, userTask.TaskList) { // if this.modelWorldtask.isFinished(taskId, userTask.TaskList) {
this.Debug("世界任务已完成", logFields...) // this.Debug("世界任务已完成", logFields...)
continue // continue
} // }
taskConf, err := this.configure.getWorldtaskById(taskId) // taskConf, err := this.configure.getWorldtaskById(taskId)
if err != nil { // if err != nil {
this.Error("world_task config not found", logFields...) // this.Error("world_task config not found", logFields...)
return err // return err
} // }
logFields = append(logFields, log.Field{Key: "id_after", Value: taskConf.IdAfter}, log.Field{Key: "des", Value: taskConf.Des}) // logFields = append(logFields, log.Field{Key: "id_after", Value: taskConf.IdAfter}, log.Field{Key: "des", Value: taskConf.Des})
if taskConf != nil { // if taskConf != nil {
if taskConf.Des == 2 { //只有世界任务才校验前置 // if taskConf.Des == 2 { //只有世界任务才校验前置
if !this.modelWorldtask.IsPreFinished(userTask, taskConf) { // if !this.modelWorldtask.IsPreFinished(userTask, taskConf) {
this.Debug("世界任务前置任务未完成", logFields...) // this.Debug("世界任务前置任务未完成", logFields...)
continue // continue
} // }
} // }
nextTaskId = taskConf.IdAfter // nextTaskId = taskConf.IdAfter
// 判断玩家等级要求 // // 判断玩家等级要求
if taskConf.Des == 2 { // if taskConf.Des == 2 {
if user.Lv < taskConf.Lock { // if user.Lv < taskConf.Lock {
logFields = append(logFields, log.Field{Key: "当前lv", Value: user.Lv}, log.Field{Key: "期望等级", Value: taskConf.Lock}) // logFields = append(logFields, log.Field{Key: "当前lv", Value: user.Lv}, log.Field{Key: "期望等级", Value: taskConf.Lock})
this.Debug("等级不满足", logFields...) // this.Debug("等级不满足", logFields...)
return comm.NewCustomError(pb.ErrorCode_WorldtaskLvNotEnough) // return comm.NewCustomError(pb.ErrorCode_WorldtaskLvNotEnough)
} // }
} // }
//完成任务 // //完成任务
if err := this.modelWorldtask.finishTask(groupId, taskId, userTask); err != nil { // if err := this.modelWorldtask.finishTask(groupId, taskId, userTask); err != nil {
logFields = append(logFields, log.Field{Key: "err", Value: err.Error()}) // logFields = append(logFields, log.Field{Key: "err", Value: err.Error()})
this.Error("世界任务完成", logFields...) // this.Error("世界任务完成", logFields...)
return err // return err
} // }
this.Debug("任务条件达成完成", logFields...) // this.Debug("任务条件达成完成", logFields...)
//发奖 // //发奖
if code := this.DispenseRes(session, taskConf.Reword, true); code != pb.ErrorCode_Success { // if code := this.DispenseRes(session, taskConf.Reword, true); code != pb.ErrorCode_Success {
logFields = append(logFields, log.Field{Key: "reward", Value: taskConf.Reword}, log.Field{Key: "code", Value: code}) // logFields = append(logFields, log.Field{Key: "reward", Value: taskConf.Reword}, log.Field{Key: "code", Value: code})
this.Error("资源发放", logFields...) // this.Error("资源发放", logFields...)
} // }
if nextTaskId != 0 && taskConf.Des == 2 { // if nextTaskId != 0 && taskConf.Des == 2 {
if err := session.SendMsg(string(this.GetType()), "nexttask", &pb.WorldtaskNexttaskPush{ // if err := session.SendMsg(string(this.GetType()), "nexttask", &pb.WorldtaskNexttaskPush{
// NextTaskId: nextTaskId, // // NextTaskId: nextTaskId,
}); err != nil { // }); err != nil {
logFields = append(logFields, log.Field{Key: "err", Value: err.Error()}) // logFields = append(logFields, log.Field{Key: "err", Value: err.Error()})
log.Error("任务条件达成推送", logFields...) // log.Error("任务条件达成推送", logFields...)
} else { // } else {
this.Debug("推送任务", log.Field{Key: "NextTaskId", Value: nextTaskId}) // this.Debug("推送任务", log.Field{Key: "NextTaskId", Value: nextTaskId})
} // }
} else { // } else {
this.Debug("已经是最后一个任务了", logFields...) // this.Debug("已经是最后一个任务了", logFields...)
} // }
} // }
} // }
} // }
return nil // return nil
} // }
// 获取我的世界任务 // 获取我的世界任务
func (this *Worldtask) GetMyWorldtask(uid string) *pb.DBWorldtask { func (this *Worldtask) GetMyWorldtask(uid string) *pb.DBWorldtask {
@ -217,82 +222,80 @@ func (this *Worldtask) GetMyWorldtask(uid string) *pb.DBWorldtask {
} }
func (this *Worldtask) BingoAllTask(session comm.IUserSession) error { func (this *Worldtask) BingoAllTask(session comm.IUserSession) error {
uid := session.GetUserId() // uid := session.GetUserId()
mytask := &pb.DBWorldtask{Uid: uid} // mytask := &pb.DBWorldtask{Uid: uid}
tasklist := this.worldtaskConf.GetDataList() // tasklist := this.worldtaskConf.GetDataList()
for _, conf := range tasklist { // for _, conf := range tasklist {
//世界任务配置 // //世界任务配置
if conf.Des == 2 { // wt := &pb.Worldtask{
wt := &pb.Worldtask{ // TaskId: conf.Key,
TaskId: conf.Key, // TaskType: conf.Des,
TaskType: conf.Des, // }
} // mytask.TaskList = append(mytask.TaskList, wt)
mytask.TaskList = append(mytask.TaskList, wt) // }
}
}
if err := this.modelWorldtask.Add(uid, mytask); err != nil { // if err := this.modelWorldtask.Add(uid, mytask); err != nil {
return err // return err
} // }
rsp := &pb.WorldtaskFinishIdsPush{ // rsp := &pb.WorldtaskFinishIdsPush{
TaskList: mytask.TaskList, // TaskList: mytask.TaskList,
} // }
return session.SendMsg(string(this.GetType()), "finishids", rsp) return nil //session.SendMsg(string(this.GetType()), "finishids", rsp)
} }
// bingo世界任务跳跃 支持回退 // bingo世界任务跳跃 支持回退
func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId int32) error { func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId int32) error {
uid := session.GetUserId() // uid := session.GetUserId()
mytask, err := this.modelWorldtask.getWorldtask(uid) // mytask, err := this.modelWorldtask.getWorldtask(uid)
if err != nil { // if err != nil {
return err // return err
} // }
mytask.Uid = uid // mytask.Uid = uid
// 更新数据 // // 更新数据
update := map[string]interface{}{} // update := map[string]interface{}{}
taskConf := this.worldtaskConf.GetDataMap()[taskId] // taskConf := this.worldtaskConf.GetDataMap()[taskId]
if taskConf == nil { // if taskConf == nil {
return fmt.Errorf("taskId: %v config is nil", taskId) // return fmt.Errorf("taskId: %v config is nil", taskId)
} // }
//重置taskList // //重置taskList
mytask.TaskList = []*pb.Worldtask{} // mytask.TaskList = []*pb.Worldtask{}
//遍历 // //遍历
if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 { // if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 {
for _, v := range this.worldtaskConf.GetDataList() { // for _, v := range this.worldtaskConf.GetDataList() {
if v.Group == groupId && v.Key <= taskId { // if v.Group == groupId && v.Key <= taskId {
wt := &pb.Worldtask{ // wt := &pb.Worldtask{
TaskId: v.Key, // TaskId: v.Key,
TaskType: v.Des, // TaskType: v.Des,
} // }
mytask.TaskList = append(mytask.TaskList, wt) // mytask.TaskList = append(mytask.TaskList, wt)
} // }
} // }
} else { // } else {
wt := &pb.Worldtask{ // wt := &pb.Worldtask{
TaskId: taskId, // TaskId: taskId,
TaskType: taskConf.Des, // TaskType: taskConf.Des,
} // }
mytask.TaskList = append(mytask.TaskList, wt) // mytask.TaskList = append(mytask.TaskList, wt)
} // }
update = map[string]interface{}{ // update = map[string]interface{}{
"taskList": mytask.TaskList, // "taskList": mytask.TaskList,
} // }
if err := this.modelWorldtask.Change(uid, update); err != nil { // if err := this.modelWorldtask.Change(uid, update); err != nil {
return err // return err
} // }
rsp := &pb.WorldtaskFinishIdsPush{ // rsp := &pb.WorldtaskFinishIdsPush{
TaskList: mytask.TaskList, // TaskList: mytask.TaskList,
} // }
return session.SendMsg(string(this.GetType()), "finishids", rsp) return nil //session.SendMsg(string(this.GetType()), "finishids", rsp)
} }

View File

@ -26,7 +26,7 @@ type DBWorldtask struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid" bson:"uid"` //玩家ID Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid" bson:"uid"` //玩家ID
TaskList []*Worldtask `protobuf:"bytes,3,rep,name=taskList,proto3" json:"taskList" bson:"taskList"` // 任务列表 TaskList []int32 `protobuf:"varint,3,rep,packed,name=taskList,proto3" json:"taskList" bson:"taskList"` // 任务列表
CurrentTask map[int32]*Worldtask `protobuf:"bytes,4,rep,name=currentTask,proto3" json:"currentTask" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3" bson:"currentTask"` //正在进行的任务 CurrentTask map[int32]*Worldtask `protobuf:"bytes,4,rep,name=currentTask,proto3" json:"currentTask" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3" bson:"currentTask"` //正在进行的任务
} }
@ -69,7 +69,7 @@ func (x *DBWorldtask) GetUid() string {
return "" return ""
} }
func (x *DBWorldtask) GetTaskList() []*Worldtask { func (x *DBWorldtask) GetTaskList() []int32 {
if x != nil { if x != nil {
return x.TaskList return x.TaskList
} }
@ -166,32 +166,31 @@ var File_worldtask_worldtask_db_proto protoreflect.FileDescriptor
var file_worldtask_worldtask_db_proto_rawDesc = []byte{ var file_worldtask_worldtask_db_proto_rawDesc = []byte{
0x0a, 0x1c, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x0a, 0x1c, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x2f, 0x77, 0x6f, 0x72, 0x6c,
0x64, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd4, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc8,
0x01, 0x0a, 0x0b, 0x44, 0x42, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x12, 0x10, 0x01, 0x0a, 0x0b, 0x44, 0x42, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x12, 0x10,
0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64,
0x12, 0x26, 0x0a, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x52, 0x08, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x3f, 0x0a, 0x0b,
0x74, 0x61, 0x73, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x63, 0x75, 0x72, 0x72, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x18, 0x04, 0x20, 0x03, 0x28,
0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x0b, 0x32, 0x1d, 0x2e, 0x44, 0x42, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x2e,
0x44, 0x42, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x2e, 0x43, 0x75, 0x72, 0x72, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79,
0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0b, 0x63, 0x75, 0x52, 0x0b, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x1a, 0x4a, 0x0a,
0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x1a, 0x4a, 0x0a, 0x10, 0x43, 0x75, 0x72, 0x10, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x6e, 0x74, 0x72,
0x72, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03,
0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x6b, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01,
0x20, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x52, 0x05,
0x2e, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x99, 0x01, 0x0a, 0x09, 0x57, 0x6f,
0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x99, 0x01, 0x0a, 0x09, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49,
0x61, 0x73, 0x6b, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x12,
0x01, 0x28, 0x05, 0x52, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x05, 0x52, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6e,
0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x70, 0x63, 0x53, 0x74, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09,
0x61, 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x6e, 0x70, 0x63, 0x53, 0x6e, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6f, 0x6e,
0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49, 0x64, 0x64, 0x69, 0x49, 0x64, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x63, 0x6f, 0x6e,
0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49, 0x64, 0x64, 0x69, 0x49, 0x64, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72,
0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x4e, 0x70, 0x63, 0x18, 0x4e, 0x70, 0x63, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76,
0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x4e, 0x70, 0x65, 0x72, 0x4e, 0x70, 0x63, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70,
0x63, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x33,
} }
var ( var (
@ -213,14 +212,13 @@ var file_worldtask_worldtask_db_proto_goTypes = []interface{}{
nil, // 2: DBWorldtask.CurrentTaskEntry nil, // 2: DBWorldtask.CurrentTaskEntry
} }
var file_worldtask_worldtask_db_proto_depIdxs = []int32{ var file_worldtask_worldtask_db_proto_depIdxs = []int32{
1, // 0: DBWorldtask.taskList:type_name -> Worldtask 2, // 0: DBWorldtask.currentTask:type_name -> DBWorldtask.CurrentTaskEntry
2, // 1: DBWorldtask.currentTask:type_name -> DBWorldtask.CurrentTaskEntry 1, // 1: DBWorldtask.CurrentTaskEntry.value:type_name -> Worldtask
1, // 2: DBWorldtask.CurrentTaskEntry.value:type_name -> Worldtask 2, // [2:2] is the sub-list for method output_type
3, // [3:3] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type
3, // [3:3] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee
3, // [3:3] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name
0, // [0:3] is the sub-list for field type_name
} }
func init() { file_worldtask_worldtask_db_proto_init() } func init() { file_worldtask_worldtask_db_proto_init() }