package moonfantasy import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "time" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (code pb.ErrorCode) { return } ///挑战怪物请求 func (this *apiComp) Battle(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (code pb.ErrorCode, data proto.Message) { var ( globalconf *cfg.GameGlobalData boss *cfg.GameDreamlandBoosData mdata *pb.DBMoonfantasy record *pb.DBBattleRecord cd pb.ErrorCode err error ) defer func() { if cd == pb.ErrorCode_Success { session.SendMsg(string(this.module.GetType()), "battle", &pb.MoonfantasyBattleResp{ Code: cd, Monster: mdata.Monster, Info: &pb.BattleInfo{ Id: record.Id, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist, }, }) } else { session.SendMsg(string(this.module.GetType()), "battle", &pb.MoonfantasyBattleResp{Code: cd}) } }() if cd = this.BattleCheck(session, req); cd != pb.ErrorCode_Success { return } if mdata, err = this.module.modelDream.queryDreamData(req.Uid, req.Mid); err != nil { cd = pb.ErrorCode_DBError return } if mdata == nil { cd = pb.ErrorCode_MoonfantasyHasExpired return } if boss, err = this.module.configure.GetMonsterById(mdata.Monster); err != nil { cd = pb.ErrorCode_ConfigNoFound return } if mdata.Joinnum >= mdata.Numup { cd = pb.ErrorCode_MoonfantasyJoinUp return } globalconf = this.module.configure.GetGlobalConf() if time.Now().Sub(time.Unix(mdata.Ctime, 0)).Seconds() >= float64(globalconf.DreamlandLimit) { cd = pb.ErrorCode_MoonfantasyHasExpired return } if v, ok := mdata.Record[session.GetUserId()]; ok { if v >= mdata.Unitmup { cd = pb.ErrorCode_MoonfantasyDareUp return } else { mdata.Record[session.GetUserId()]++ } } else { mdata.Record[session.GetUserId()] = 1 } cd, record = this.module.battle.CreatePvbBattle(session, &pb.BattlePVEReq{ Ptype: pb.PlayType_moonfantasy, Leadpos: req.Leadpos, Teamids: req.Teamids, Mformat: []int32{boss.Monsterformatid}, }) return }