package storyline import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.StorylineBattleReq) (errdata *pb.ErrorData) { if req.Level == 0 || req.Battle == nil { this.module.Error("战斗开始参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()}, ) errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: "BattleConfId is 0", } } return } // /获取系统公告 func (this *apiComp) Battle(session comm.IUserSession, req *pb.StorylineBattleReq) (errdata *pb.ErrorData) { var ( conf *cfg.GameHeroupstoryChapterData bconf *cfg.GameHeroupstoryBattleData record *pb.DBBattleRecord err error ) if errdata = this.BattleCheck(session, req); errdata != nil { return } if conf, err = this.module.configure.getGameHeroupstoryChapter(req.Level); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if bconf, err = this.module.configure.getGameHeroupstoryBattle(conf.Battle); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if errdata, record = this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{ Rulesid: bconf.BattleReadyID, Ptype: pb.PlayType_rtask, Format: req.Battle, Mformat: bconf.FormatList, }); err != nil { return } session.SendMsg(string(this.module.GetType()), "battle", &pb.StorylineBattleResp{ Level: req.Level, Info: &pb.BattleInfo{ Id: record.Id, Rulesid: bconf.BattleReadyID, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist, Tasks: record.Tasks, }, }) return }