diff --git a/modules/mline/api_challenge.go b/modules/mline/api_challenge.go index 8478e2b3c..3b019683b 100644 --- a/modules/mline/api_challenge.go +++ b/modules/mline/api_challenge.go @@ -5,51 +5,77 @@ import ( "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode) { - + if req.StageId == 0 { + code = pb.ErrorCode_ReqParameterError + } return } ///挑战主线关卡 func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode, data proto.Message) { var ( - curChapter *pb.DBMainline // 当前章节信息 - ps int32 + curChapter *pb.DBMline // 当前章节信息 + ps int32 // 消耗的体力 psAnt *cfg.Gameatn + stageConf *cfg.GameMainStageData ) - code = this.ChallengeCheck(session, req) - if code != pb.ErrorCode_Success { + if code = this.ChallengeCheck(session, req); code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - // 校验关卡存不存在 - - node := this.module.configure.GetMainStageConf(req.StageId) - if node == nil { // 配置文件校验 + if stageConf = this.module.configure.GetMainStageConf(req.StageId); stageConf == nil { // 配置文件校验 code = pb.ErrorCode_MainlineNotFindChapter return } - if curChapter.Ps != 0 { - if code = this.module.ConsumeRes(session, node.PsMg, true); code != pb.ErrorCode_Success { // 扣1点 - return + list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) + for _, v := range list { + if stageConf.Chapterid == v.ChapterId { + curChapter = v + break } + } + if curChapter == nil { // 校验是不是新的数据 + if stageConf.Previoustage == 0 { // 创建一条新的章节数据 + newData := &pb.DBMline{ + Id: primitive.NewObjectID().Hex(), + Uid: session.GetUserId(), + CType: stageConf.Episodetype, + ChapterId: stageConf.Chapterid, + StageId: stageConf.Id, + Star: map[int32]int32{}, + Awared: map[int32]bool{}, + Ps: map[int32]int32{}, + } + this.module.modelMline.addNewChapter(session.GetUserId(), newData) + } + } + + if v, ok := curChapter.Ps[req.StageId]; ok { + if v != 0 { // 扣1点 + if code = this.module.ConsumeRes(session, stageConf.PsMg, true); code != pb.ErrorCode_Success { // 扣1点 + return + } + } + } else { - for _, v := range node.PsConsume { + for _, v := range stageConf.PsConsume { if v.A == "attr" && v.T == "ps" { ps += v.N } } - for _, v := range node.PsMg { + for _, v := range stageConf.PsMg { if v.A == "attr" && v.T == "ps" { ps += v.N } } - psAnt = &cfg.Gameatn{ + psAnt = &cfg.Gameatn{ // 构建一个atn 对象 A: "attr", T: "ps", N: ps, @@ -58,12 +84,11 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallenge return } - curChapter.Ps = ps - update := map[string]interface{}{ - "ps": ps, - } + curChapter.Ps[req.StageId] = ps - err := this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) + err := this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, map[string]interface{}{ + "ps": curChapter.Ps, + }) if err != nil { code = pb.ErrorCode_DBError return @@ -74,7 +99,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallenge Ptype: pb.PlayType_mainline, Title: "", Format: req.Battle, - Mformat: node.FormatList, + Mformat: stageConf.FormatList, }) if code != pb.ErrorCode_Success { return diff --git a/modules/mline/api_challengeover.go b/modules/mline/api_challengeover.go index 5683d7278..54005bb41 100644 --- a/modules/mline/api_challengeover.go +++ b/modules/mline/api_challengeover.go @@ -21,32 +21,37 @@ func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.Mline ///挑战主线关卡 func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChallengeOverReq) (code pb.ErrorCode, data proto.Message) { var ( - mainline *pb.DBMline // 当前章节信息 - res []*cfg.Gameatn // 小章节奖励 - isWin bool - hero []string //新的英雄 - newhero []string //新的英雄 + curChapter *pb.DBMline // 当前章节信息 + stageConf *cfg.GameMainStageData + res []*cfg.Gameatn // 小章节奖励 + isWin bool + first bool // 判断是否是首通 + update map[string]interface{} + rsp *pb.MlineChallengeOverResp ) + rsp = &pb.MlineChallengeOverResp{} + update = make(map[string]interface{}) res = make([]*cfg.Gameatn, 0) - hero = make([]string, 0) - newhero = make([]string, 0) code = this.ChallengeOverCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - // 校验关卡存不存在 - // mainline = this.module.modelMline.getOneChapterInfo(session.GetUserId(), req.ChapterObj) - // if mainline == nil { - // code = pb.ErrorCode_MainlineNotFound - // return - // } - - node := this.module.configure.GetMainStageConf(req.StageId) - if node == nil { // 配置文件校验 + if stageConf = this.module.configure.GetMainStageConf(req.StageId); stageConf == nil { // 配置文件校验 code = pb.ErrorCode_MainlineNotFindChapter return } + list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) + for _, v := range list { + if stageConf.Chapterid == v.ChapterId { + curChapter = v + break + } + } + if curChapter == nil { + code = pb.ErrorCode_MainlineNotFindChapter + return + } // 校验通过 code, isWin = this.module.battle.CheckBattleReport(session, req.Report) @@ -54,65 +59,68 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChall return } - if !isWin { // 战斗失败直接返回 - // 返还 - //mainline.Ps = 0 - this.module.modelMline.modifyMlineData(session.GetUserId(), mainline.Id, map[string]interface{}{ - "ps": 0, - }) - - if code = this.module.DispenseRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { // 返还预扣体力 - return + if !isWin { // 战斗失败返还扣除的体力 + if v, ok := curChapter.Ps[req.StageId]; ok && v > 0 { + if code = this.module.DispenseRes(session, stageConf.PsConsume, true); code != pb.ErrorCode_Success { // 返还预扣体力 + return + } } + curChapter.Ps[req.StageId] = 0 // 清空预扣体力值 + update["ps"] = curChapter.Ps + this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) code = pb.ErrorCode_BattleNoWin return } + // 判断是不是首通 + if _, ok := curChapter.Star[req.StageId]; !ok { + first = true + curChapter.Star[req.StageId] = 1 + update["star"] = curChapter.Star + } + curChapter.Ps[req.StageId] = 0 // 清空预扣体力值 + update["ps"] = curChapter.Ps - res = append(res, node.Commonaward...) - for _, v := range node.Commonaward { - if v.A == comm.HeroType { - hero = append(hero, v.T) + curChapter.StageId = req.StageId + update["stageId"] = curChapter.StageId + + if first { // 发奖 + if code = this.module.DispenseRes(session, stageConf.Firstaward, true); code != pb.ErrorCode_Success { + this.module.Debugf("DispenseRes err:+%v", res) + } + for _, v := range stageConf.Firstaward { + rsp.Reward = append(rsp.Reward, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) + } + + } else { + if code = this.module.DispenseRes(session, stageConf.Commonaward, true); code != pb.ErrorCode_Success { + this.module.Debugf("DispenseRes err:+%v", res) + } + for _, v := range stageConf.Commonaward { + rsp.Reward = append(rsp.Reward, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) } } - if len(hero) > 0 { - ishave := this.module.ModuleUser.CheckTujianHero(session, hero) - for i, v := range ishave { - if !v { - newhero = append(newhero, hero[i]) - } - } - } - mainline.StageId = req.StageId - //mainline.Ps = 0 // 重置预扣体力 - update := map[string]interface{}{ - "stageId": mainline.StageId, - } - if node.Episodetype == comm.MainLineBoss { // 打完boss 设置领奖状态 - update["awaredID"] = pb.AwaredType_TypeAvailable - } - err := this.module.modelMline.modifyMlineData(session.GetUserId(), mainline.Id, update) - if err != nil { - code = pb.ErrorCode_DBError - return - } - - // 发奖 - if code = this.module.DispenseRes(session, res, true); code != pb.ErrorCode_Success { - this.module.Debugf("DispenseRes err:+%v", res) - } - // 加经验 - if node.Episodetype != 5 && node.Episodetype != 7 { + // 加英雄经验 + if stageConf.HeroExp > 0 { if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { for _, v := range req.Report.Info.Redflist[0].Team { - if node.Exp > 0 && !v.Ishelp { // 助战英雄不加经验 - this.module.ModuleHero.AddHeroExp(session, v.Oid, node.Exp) + if !v.Ishelp { // 助战英雄不加经验 + this.module.ModuleHero.AddHeroExp(session, v.Oid, stageConf.HeroExp) } } } } - - session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, &pb.MlineChallengeOverResp{}) + this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) + rsp.Data = curChapter + session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送 // 主线任务统计 Rtype60 this.module.ModuleRtask.SendToRtask(session, comm.Rtype60, 1) this.module.ModuleRtask.SendToRtask(session, comm.Rtype61, int32(req.StageId)) diff --git a/modules/mline/model_mainline.go b/modules/mline/model_mainline.go index 2b48bacc9..0e23ecc94 100644 --- a/modules/mline/model_mainline.go +++ b/modules/mline/model_mainline.go @@ -22,7 +22,7 @@ func (this *ModelMline) Init(service core.IService, module core.IModule, comp co // 获取章节信息 func (this *ModelMline) getMainlineList(uid string) (mLine []*pb.DBMline, err error) { mLine = make([]*pb.DBMline, 0) - err = this.GetList(uid, &mLine) + this.GetList(uid, &mLine) return } @@ -32,13 +32,14 @@ func (this *ModelMline) modifyMlineData(uid string, objId string, data map[strin } // 增加新的章节数据 -func (this *ModelMline) addNewChapter(uId string, data map[string]interface{}) (err error) { - - if err = this.AddLists(uId, data); err != nil { - this.module.Errorf("err:%v", err) - return +func (this *ModelMline) addNewChapter(uId string, data *pb.DBMline) (err error) { + update := make(map[string]*pb.DBMline) + update[data.Id] = data + if err = this.AddLists(uId, update); err != nil { + this.module.Errorln(err) } - return nil + + return err } // 获取指定章节数据 diff --git a/pb/battle_msg.pb.go b/pb/battle_msg.pb.go index 09010e6d1..a2a4845a4 100644 --- a/pb/battle_msg.pb.go +++ b/pb/battle_msg.pb.go @@ -630,6 +630,8 @@ type BattleReport struct { Incmd []*BattleCmd `protobuf:"bytes,3,rep,name=incmd,proto3" json:"incmd"` //输入指令 Outcmd []*BattleCmd `protobuf:"bytes,4,rep,name=outcmd,proto3" json:"outcmd"` //输出指令 Completetask []int32 `protobuf:"varint,5,rep,packed,name=completetask,proto3" json:"completetask"` //完成任务 + Death int32 `protobuf:"varint,6,opt,name=death,proto3" json:"death"` // 死亡人数 + Round int32 `protobuf:"varint,7,opt,name=round,proto3" json:"round"` // 回合数 } func (x *BattleReport) Reset() { @@ -699,6 +701,20 @@ func (x *BattleReport) GetCompletetask() []int32 { return nil } +func (x *BattleReport) GetDeath() int32 { + if x != nil { + return x.Death + } + return 0 +} + +func (x *BattleReport) GetRound() int32 { + if x != nil { + return x.Round + } + return 0 +} + //公用消息结构代码 type BattleRpcMessage struct { state protoimpl.MessageState @@ -892,7 +908,7 @@ var file_battle_battle_msg_proto_rawDesc = []byte{ 0x65, 0x43, 0x6d, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6d, 0x64, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6d, 0x64, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x22, 0xb5, 0x01, 0x0a, 0x0c, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, + 0x61, 0x6c, 0x75, 0x65, 0x22, 0xe1, 0x01, 0x0a, 0x0c, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1f, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x43, 0x6f, 0x73, 0x74, 0x74, 0x69, @@ -903,18 +919,20 @@ var file_battle_battle_msg_proto_rawDesc = []byte{ 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x43, 0x6d, 0x64, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x63, 0x6d, 0x64, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x74, 0x61, 0x73, 0x6b, 0x18, 0x05, 0x20, 0x03, 0x28, 0x05, 0x52, 0x0c, - 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x74, 0x61, 0x73, 0x6b, 0x22, 0x66, 0x0a, 0x10, - 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x12, 0x10, 0x0a, 0x03, 0x72, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x72, - 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x28, 0x0a, 0x04, 0x64, 0x61, - 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x22, 0x2e, 0x0a, 0x12, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x43, 0x68, - 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x69, 0x73, - 0x63, 0x68, 0x65, 0x63, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x63, - 0x68, 0x65, 0x63, 0x6b, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x74, 0x61, 0x73, 0x6b, 0x12, 0x14, 0x0a, 0x05, + 0x64, 0x65, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x64, 0x65, 0x61, + 0x74, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x22, 0x66, 0x0a, 0x10, 0x42, 0x61, 0x74, 0x74, + 0x6c, 0x65, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, + 0x72, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x72, 0x69, 0x64, 0x12, 0x16, + 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x28, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x22, 0x2e, 0x0a, 0x12, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x69, 0x73, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (