修改成就任务

This commit is contained in:
zhaocy 2022-07-25 21:52:14 +08:00
parent c8f8f19bd1
commit 4d5cedc949
8 changed files with 111 additions and 30 deletions

View File

@ -17,9 +17,9 @@ var (
subType: task.TaskSubTypeList,
req: &pb.TaskListReq{
//设置任务类型
TaskTag: int32(comm.TASK_DAILY), //每天任务
// TaskTag: int32(comm.TASK_DAILY), //每天任务
// TaskTag: int32(comm.TASK_WEEKLY), //周任务
// TaskTag: int32(comm.TASK_ACHIEVE),
TaskTag: int32(comm.TASK_ACHIEVE),
// TaskTag: int32(comm.TASK_STRATEGY),
},
rsp: &pb.TaskListResp{},
@ -29,7 +29,7 @@ var (
fmt.Printf("%v \n", v)
}
},
// enabled: true,
enabled: true,
next: func(robot *Robot, rsp proto.Message) {
tcs := []*TestCase{}
if _, ok := rsp.(*pb.TaskListResp); ok {

View File

@ -17,8 +17,8 @@ var user_builders = []*TestCase{
req: &pb.UserModifynameReq{ //设置请求参数
Name: "uuuuuu",
},
rsp: &pb.UserModifynameResp{},
enabled: true,
rsp: &pb.UserModifynameResp{},
// enabled: true,
}, {
desc: "添加资源",
mainType: string(comm.ModuleUser),

View File

@ -2,7 +2,6 @@ package task
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
@ -41,9 +40,9 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
return
}
// 待领取的任务配置
conf, err := this.moduleTask.configure.getTaskById(userTask.TaskId)
if err != nil {
log.Errorf("get task config err:%v", err)
conf := this.moduleTask.configure.getTaskById(userTask.TaskId)
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}

View File

@ -2,6 +2,7 @@ package task
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
@ -62,11 +63,11 @@ func (this *configureComp) getTaskRoundCfg() (data *cfg.Game_taskRound, err erro
}
//根据taskId获取配置
func (this *configureComp) getTaskById(taskId int32) (data *cfg.Game_taskRoundData, err error) {
func (this *configureComp) getTaskById(taskId int32) (data *cfg.Game_taskRoundData) {
cfg, err := this.getTaskRoundCfg()
if err != nil {
log.Errorf("%v", err)
return data, err
return nil
}
if cfg != nil {
data = cfg.GetDataMap()[taskId]
@ -74,6 +75,28 @@ func (this *configureComp) getTaskById(taskId int32) (data *cfg.Game_taskRoundDa
return
}
//是否第一个成就任务
func (this *configureComp) isFirstTask(taskId int32) bool {
data := this.getTaskByTag(int32(comm.TASK_ACHIEVE))
for _, v := range data {
if v.IdAfter == taskId {
return false
}
}
return true
}
// 上一个任务
func (this *configureComp) getPreTask(preTaskId int32) *cfg.Game_taskRoundData {
data := this.getTaskByTag(int32(comm.TASK_ACHIEVE))
for _, v := range data {
if v.IdAfter == preTaskId {
return v
}
}
return nil
}
//获取任务配置列表
func (this *configureComp) getTaskList() (data []*cfg.Game_taskRoundData, err error) {
cfg, err := this.getTaskRoundCfg()
@ -116,11 +139,11 @@ func (this *configureComp) getSortedTasks(taskType int32) (data []*cfg.Game_task
}
//获取任务配置 条件 tasktag
func (this *configureComp) getTaskByTag(taskTag int32) (data []*cfg.Game_taskRoundData, err error) {
func (this *configureComp) getTaskByTag(taskTag int32) (data []*cfg.Game_taskRoundData) {
list, err := this.getTaskList()
if err != nil {
log.Errorf("%v", err)
return data, err
return data
}
for _, d := range list {
if d.IdTag == taskTag {

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"sort"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@ -26,6 +27,7 @@ func (this *ModelTask) Init(service core.IService, module core.IModule, comp cor
return
}
// 玩家的所有任务列表
func (this *ModelTask) getTaskList(uid string) (list []*pb.DBTask) {
if err := this.GetList(uid, &list); err != nil {
log.Errorf("getTaskList err %v", err)
@ -42,9 +44,58 @@ func (this *ModelTask) getTaskListByTag(uid string, taskTag comm.TaskTag) (newli
return
}
sort.SliceStable(list, func(i, j int) bool {
return list[i].Sort < list[j].Sort
})
var taskList []*pb.DBTask
for _, v := range list {
if v.Tag == int32(taskTag) {
newlist = append(newlist, v)
taskList = append(taskList, v)
}
}
// 当前玩家任务
getCurTask := func(taskId int32) *pb.DBTask {
for _, v := range list {
if v.TaskId == taskId {
return v
}
}
return nil
}
if taskTag == comm.TASK_ACHIEVE {
for _, v := range taskList {
if curTask := this.moduleTask.configure.getTaskById(v.TaskId); curTask != nil {
if v.Received == 0 && curTask.IdAfter == 0 { //未领取和没有下个连续任务的
newlist = append(newlist, v)
} else if this.moduleTask.configure.isFirstTask(curTask.Key) && curTask.IdAfter != 0 { //连续任务的第一个任务
next := this.moduleTask.configure.getTaskById(curTask.IdAfter)
if next != nil && v.Received == 0 {
newlist = append(newlist, v)
}
} else if !this.moduleTask.configure.isFirstTask(curTask.Key) && curTask.IdAfter == 0 { //连续任务的最后一个任务
// 上个任务
if preCnf := this.moduleTask.configure.getPreTask(curTask.Key); preCnf != nil {
if preTask := getCurTask(preCnf.Key); preTask != nil {
if preTask.Received == 1 { //判断上个任务领取了才显示最后一个任务
newlist = append(newlist, v)
}
}
}
} else {
if preCnf := this.moduleTask.configure.getPreTask(curTask.Key); preCnf != nil {
if preTask := getCurTask(preCnf.Key); preTask != nil {
if preTask.Received == 1 { //判断上个任务领取了才显示最后一个任务
newlist = append(newlist, v)
}
}
}
}
}
}
}
return
@ -79,6 +130,7 @@ func (this *ModelTask) initTask(uid string) error {
TaskId: cnf.Key,
Active: cnf.Active,
Progress: cnf.ConditionSecond,
Sort: cnf.IdList,
}
if err := this.AddList(uid, task.Id, task); err != nil {
log.Errorf("initTask addlists err %v", err)
@ -162,11 +214,7 @@ func (this *ModelTask) inStrategy(uid string, heroCfgId int32) (taskIds []int32,
taskList := this.getTaskListByTag(uid, comm.TASK_STRATEGY)
allFinished := true
for _, v := range taskList {
conf, err := this.moduleTask.configure.getTaskById(v.TaskId)
if err != nil {
this.moduleTask.Errorf("get task[%v] config err %v", v.TaskId, err)
return nil, err
}
conf := this.moduleTask.configure.getTaskById(v.TaskId)
if conf != nil {
if conf.RestrictiveCondition == heroCfgId && v.Status != 1 {
allFinished = false

View File

@ -112,7 +112,7 @@ func (this *ModuleTask) initTaskHandle() {
case int32(comm.TaskTypeUpHeroLevel):
this.register(comm.TaskTypeUpHeroLevel, this.modelTask.UpHeroLevel)
default:
log.Errorf("%v task type not supported", v.TypeId)
log.Warnf("%v task type not supported", v.TypeId)
}
}
}

View File

@ -11,6 +11,7 @@ message DBTask {
int32 status = 7; //@go_tags(`bson:"status"`) 0 1
int32 received = 8; //@go_tags(`bson:"received"`) 0 1
int32 typeId = 9; //@go_tags(`bson:"typeId"`)
int32 sort = 10; //@go_tags(`bson:"sort"`)
}
message DBTaskActive {

View File

@ -34,6 +34,7 @@ type DBTask struct {
Status int32 `protobuf:"varint,7,opt,name=status,proto3" json:"status" bson:"status"` // 任务状态 默认0未完成 1已完成
Received int32 `protobuf:"varint,8,opt,name=received,proto3" json:"received" bson:"received"` //领取状态 默认0未领取 1已领取
TypeId int32 `protobuf:"varint,9,opt,name=typeId,proto3" json:"typeId" bson:"typeId"`
Sort int32 `protobuf:"varint,10,opt,name=sort,proto3" json:"sort" bson:"sort"`
}
func (x *DBTask) Reset() {
@ -131,6 +132,13 @@ func (x *DBTask) GetTypeId() int32 {
return 0
}
func (x *DBTask) GetSort() int32 {
if x != nil {
return x.Sort
}
return 0
}
type DBTaskActive struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -214,7 +222,7 @@ var File_task_task_db_proto protoreflect.FileDescriptor
var file_task_task_db_proto_rawDesc = []byte{
0x0a, 0x12, 0x74, 0x61, 0x73, 0x6b, 0x2f, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd4, 0x01, 0x0a, 0x06, 0x44, 0x42, 0x54, 0x61, 0x73, 0x6b, 0x12,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe8, 0x01, 0x0a, 0x06, 0x44, 0x42, 0x54, 0x61, 0x73, 0x6b, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69,
0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
@ -227,15 +235,17 @@ var file_task_task_db_proto_rawDesc = []byte{
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69,
0x76, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69,
0x76, 0x65, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x79, 0x70, 0x65, 0x49, 0x64, 0x18, 0x09, 0x20,
0x01, 0x28, 0x05, 0x52, 0x06, 0x74, 0x79, 0x70, 0x65, 0x49, 0x64, 0x22, 0x70, 0x0a, 0x0c, 0x44,
0x42, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75,
0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x10, 0x0a,
0x03, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x72, 0x49, 0x64, 0x12,
0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x74, 0x61,
0x67, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x18, 0x05, 0x20,
0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x42, 0x06, 0x5a,
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x01, 0x28, 0x05, 0x52, 0x06, 0x74, 0x79, 0x70, 0x65, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x73,
0x6f, 0x72, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x6f, 0x72, 0x74, 0x22,
0x70, 0x0a, 0x0c, 0x44, 0x42, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69,
0x64, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03,
0x72, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05,
0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65,
0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65,
0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (