支线剧情任务优化

This commit is contained in:
wh_zcy 2022-09-06 19:10:59 +08:00
parent 99f48b3e43
commit 7b9ad86089
5 changed files with 97 additions and 77 deletions

View File

@ -4,8 +4,7 @@
"preTId": -1,
"nextTId": 100102,
"cond": [
101,
102
101
],
"reward": [
{

View File

@ -172,6 +172,7 @@ var (
},
"linestory": {
ff(comm.ModuleLinestory, linestory.LinestorySubTypeDostart),
ff(comm.ModuleLinestory, linestory.LinestorySubTypeDotask),
},
}
)

View File

@ -21,6 +21,15 @@ func (this *apiComp) Dotask(session comm.IUserSession, req *pb.LinestoryDotaskRe
return
}
rsp := &pb.LinestoryDotaskResp{}
defer func() {
if err := session.SendMsg(string(this.moduleLinestory.GetType()), LinestorySubTypeDotask, rsp); err != nil {
code = pb.ErrorCode_SystemError
return
}
}()
// task conf
conf := this.moduleLinestory.configure.getLinestoryTaskCfgById(req.TaskId)
if conf == nil {
@ -42,10 +51,15 @@ func (this *apiComp) Dotask(session comm.IUserSession, req *pb.LinestoryDotaskRe
return
}
var curTask *pb.TaskNode //当前任务
if dbLinestory.Tasks == nil {
dbLinestory.Tasks = make(map[int32]*pb.TaskNode)
curTask = &pb.TaskNode{}
dbLinestory.Tasks[req.TaskId] = curTask
} else {
if v, ok := dbLinestory.Tasks[req.TaskId]; ok {
curTask = v
// 是否被禁止进入
if v.Status == 3 {
code = pb.ErrorCode_LinestoryTaskDisabledEnter
@ -54,70 +68,70 @@ func (this *apiComp) Dotask(session comm.IUserSession, req *pb.LinestoryDotaskRe
}
}
var curTask *pb.TaskNode //当前任务
rsp := &pb.LinestoryDotaskResp{}
defer func() {
if err := session.SendMsg(string(this.moduleLinestory.GetType()), LinestorySubTypeDotask, rsp); err != nil {
code = pb.ErrorCode_SystemError
return
}
}()
//校验前置
if conf.PreTId != -1 {
if tn, ok := dbLinestory.Tasks[conf.PreTId]; !ok {
code = pb.ErrorCode_LinestoryTaskNoFinished
code = pb.ErrorCode_LinestoryPreTaskNoFinished
return
} else {
curTask = tn
// 判此任务是否是结局
if conf.Ending == 0 && conf.Resetto != -1 {
// 重置任务
for k, _ := range dbLinestory.Tasks {
if k >= conf.Resetto {
delete(dbLinestory.Tasks, k)
}
}
dbLinestory.Tasks[req.TaskId] = &pb.TaskNode{Status: 3}
}
// 判断是否最后一个 发奖励
if code = this.moduleLinestory.DispenseRes(session, conf.Reward, true); code != pb.ErrorCode_Success {
log.Errorf("%v", code)
if tn.Status != 2 {
code = pb.ErrorCode_LinestoryPreTaskNoFinished
return
}
}
}
// 判此任务是否是结局
if conf.Ending == 0 && conf.Resetto != -1 {
// 重置任务
for k, _ := range dbLinestory.Tasks {
if k >= conf.Resetto {
delete(dbLinestory.Tasks, k)
}
}
// 设置当前任务为禁止
dbLinestory.Tasks[req.TaskId] = &pb.TaskNode{Status: 3}
}
// 校验子任务是否完成
if _, ok := utils.Findx(curTask.SubtaskIds, req.SubtaskId); !ok {
code = pb.ErrorCode_LinestorySubTaskNoFinished
if _, ok := utils.Findx(curTask.SubtaskIds, req.SubtaskId); ok {
code = pb.ErrorCode_LinestorySubTaskFinished
return
}
// 校验子任务前置
// 校验子任务前置是否完成
if stageConf.PreTId != -1 {
module, err := this.service.GetModule(comm.ModuleRtask)
if err != nil {
code = pb.ErrorCode_SystemError
if _, ok := utils.Findx(curTask.SubtaskIds, stageConf.PreTId); !ok {
code = pb.ErrorCode_LinestoryPreTaskNoFinished
return
}
//校验子任务完成条件
if m, ok := module.(comm.IRtask); ok {
for _, condiId := range stageConf.Cond {
if code = m.CheckCondi(session, condiId); code != pb.ErrorCode_Success {
return
}
}
}
// 全部符合条件
curTask.SubtaskIds = append(curTask.SubtaskIds, req.SubtaskId)
if len(conf.StageTId) == len(curTask.SubtaskIds) {
curTask.Status = 2 //完成
} else {
curTask.Status = 1 //进行中
module, err := this.service.GetModule(comm.ModuleRtask)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
//校验子任务完成条件
if m, ok := module.(comm.IRtask); ok {
for _, condiId := range stageConf.Cond {
if code = m.CheckCondi(session, condiId); code != pb.ErrorCode_Success {
return
}
dbLinestory.Tasks[conf.PreTId] = curTask
}
// 全部符合条件
curTask.SubtaskIds = append(curTask.SubtaskIds, req.SubtaskId)
if len(conf.StageTId) == len(curTask.SubtaskIds) {
curTask.Status = 2 //完成
// 发任务奖励
if code = this.moduleLinestory.DispenseRes(session, conf.Reward, true); code != pb.ErrorCode_Success {
log.Errorf("%v", code)
}
} else {
curTask.Status = 1 //进行中
}
dbLinestory.Tasks[conf.Id] = curTask
}
// 更新子任务
@ -130,10 +144,8 @@ func (this *apiComp) Dotask(session comm.IUserSession, req *pb.LinestoryDotaskRe
return
}
if stageConf.NextTId == -1 {
//派发奖励
code = this.moduleLinestory.DispenseRes(session, stageConf.Reward, true)
}
//派发子任务奖励
code = this.moduleLinestory.DispenseRes(session, stageConf.Reward, true)
return
}

View File

@ -14,6 +14,20 @@ func (this *apiComp) DostartCheck(session comm.IUserSession, req *pb.LinestorySt
}
func (this *apiComp) Dostart(session comm.IUserSession, req *pb.LinestoryStartReq) (code pb.ErrorCode, data proto.Message) {
if code = this.DostartCheck(session, req); code != pb.ErrorCode_Success {
return
}
rsp := &pb.LinestoryStartResp{
JqId: req.JqId,
}
defer func() {
if err := session.SendMsg(string(this.moduleLinestory.GetType()), LinestorySubTypeDostart,
rsp); err != nil {
code = pb.ErrorCode_SystemError
}
}()
conf := this.moduleLinestory.configure.getLinestoryChapterCfgById(req.JqId)
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
@ -35,17 +49,6 @@ func (this *apiComp) Dostart(session comm.IUserSession, req *pb.LinestoryStartRe
}
}
rsp := &pb.LinestoryStartResp{
JqId: req.JqId,
}
defer func() {
if err := session.SendMsg(string(this.moduleLinestory.GetType()), LinestorySubTypeDostart,
rsp); err != nil {
code = pb.ErrorCode_SystemError
}
}()
dbLinestory := &pb.DBLinestory{}
if err := this.moduleLinestory.modelLinestory.Get(session.GetUserId(), dbLinestory); err != nil {
if err == mongo.ErrNoDocuments {

View File

@ -171,9 +171,10 @@ const (
ErrorCode_MoonfantasyBattleNoEnd ErrorCode = 2404 // boos 战斗未结束
ErrorCode_MoonfantasyBattleNoWin ErrorCode = 2405 // boos 战斗魏未胜利
ErrorCode_BattleNoFoundRecord ErrorCode = 2501 // 未找到记录
ErrorCode_LinestoryTaskNoFinished ErrorCode = 2601 //任务完成
ErrorCode_LinestorySubTaskNoFinished ErrorCode = 2602 //子任务完成
ErrorCode_LinestoryTaskFinished ErrorCode = 2601 //任务完成
ErrorCode_LinestorySubTaskFinished ErrorCode = 2602 //子任务完成
ErrorCode_LinestoryTaskDisabledEnter ErrorCode = 2603 //禁止进入
ErrorCode_LinestoryPreTaskNoFinished ErrorCode = 2604 //前置任务未完成
)
// Enum value maps for ErrorCode.
@ -312,9 +313,10 @@ var (
2404: "MoonfantasyBattleNoEnd",
2405: "MoonfantasyBattleNoWin",
2501: "BattleNoFoundRecord",
2601: "LinestoryTaskNoFinished",
2602: "LinestorySubTaskNoFinished",
2601: "LinestoryTaskFinished",
2602: "LinestorySubTaskFinished",
2603: "LinestoryTaskDisabledEnter",
2604: "LinestoryPreTaskNoFinished",
}
ErrorCode_value = map[string]int32{
"Success": 0,
@ -450,9 +452,10 @@ var (
"MoonfantasyBattleNoEnd": 2404,
"MoonfantasyBattleNoWin": 2405,
"BattleNoFoundRecord": 2501,
"LinestoryTaskNoFinished": 2601,
"LinestorySubTaskNoFinished": 2602,
"LinestoryTaskFinished": 2601,
"LinestorySubTaskFinished": 2602,
"LinestoryTaskDisabledEnter": 2603,
"LinestoryPreTaskNoFinished": 2604,
}
)
@ -487,7 +490,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2a, 0xb3, 0x17, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x6f, 0x2a, 0xd0, 0x17, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12,
0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
@ -668,14 +671,16 @@ var file_errorcode_proto_rawDesc = []byte{
0x12, 0x1b, 0x0a, 0x16, 0x4d, 0x6f, 0x6f, 0x6e, 0x66, 0x61, 0x6e, 0x74, 0x61, 0x73, 0x79, 0x42,
0x61, 0x74, 0x74, 0x6c, 0x65, 0x4e, 0x6f, 0x57, 0x69, 0x6e, 0x10, 0xe5, 0x12, 0x12, 0x18, 0x0a,
0x13, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x4e, 0x6f, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65,
0x63, 0x6f, 0x72, 0x64, 0x10, 0xc5, 0x13, 0x12, 0x1c, 0x0a, 0x17, 0x4c, 0x69, 0x6e, 0x65, 0x73,
0x74, 0x6f, 0x72, 0x79, 0x54, 0x61, 0x73, 0x6b, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68,
0x65, 0x64, 0x10, 0xa9, 0x14, 0x12, 0x1f, 0x0a, 0x1a, 0x4c, 0x69, 0x6e, 0x65, 0x73, 0x74, 0x6f,
0x72, 0x79, 0x53, 0x75, 0x62, 0x54, 0x61, 0x73, 0x6b, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x69, 0x73,
0x68, 0x65, 0x64, 0x10, 0xaa, 0x14, 0x12, 0x1f, 0x0a, 0x1a, 0x4c, 0x69, 0x6e, 0x65, 0x73, 0x74,
0x6f, 0x72, 0x79, 0x54, 0x61, 0x73, 0x6b, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x45,
0x6e, 0x74, 0x65, 0x72, 0x10, 0xab, 0x14, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x63, 0x6f, 0x72, 0x64, 0x10, 0xc5, 0x13, 0x12, 0x1a, 0x0a, 0x15, 0x4c, 0x69, 0x6e, 0x65, 0x73,
0x74, 0x6f, 0x72, 0x79, 0x54, 0x61, 0x73, 0x6b, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64,
0x10, 0xa9, 0x14, 0x12, 0x1d, 0x0a, 0x18, 0x4c, 0x69, 0x6e, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x79,
0x53, 0x75, 0x62, 0x54, 0x61, 0x73, 0x6b, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x10,
0xaa, 0x14, 0x12, 0x1f, 0x0a, 0x1a, 0x4c, 0x69, 0x6e, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x54,
0x61, 0x73, 0x6b, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x45, 0x6e, 0x74, 0x65, 0x72,
0x10, 0xab, 0x14, 0x12, 0x1f, 0x0a, 0x1a, 0x4c, 0x69, 0x6e, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x79,
0x50, 0x72, 0x65, 0x54, 0x61, 0x73, 0x6b, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65,
0x64, 0x10, 0xac, 0x14, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
var (