package practice import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" "time" ) // 参数校验 func (this *apiComp) PracticeCheck(session comm.IUserSession, req *pb.PracticePracticeReq) (errdata *pb.ErrorData) { return } // /练功请求 练功 func (this *apiComp) Practice(session comm.IUserSession, req *pb.PracticePracticeReq) (errdata *pb.ErrorData) { var ( err error room *pb.DBPracticeRoom hero *pb.DBHero heroconf *cfg.GameHeroData pillar *pb.DBPracticePillar pillarconfigure *cfg.GamePandamasMzData tconfigure *cfg.GamePandamasJxData pconfigure *cfg.GamePandamasJxData extra int32 = 0 filed string tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0) ) if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if hero, err = this.module.ModuleHero.QueryCrossHeroinfo(req.Hero); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: fmt.Sprintf("no found hero:%s", req.Hero), } return } if heroconf, err = this.module.ModuleTools.GetHeroConfig(hero.HeroID); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } switch req.Index { case 1: pillar = room.Pillar1 filed = "pillar1" break case 2: pillar = room.Pillar2 filed = "pillar2" break case 3: pillar = room.Pillar3 filed = "pillar3" break case 4: pillar = room.Pillarf filed = "pillarf" break } if pillar.Isunlock != 2 { //柱子未解锁 errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: "pillar is no unlock", } return } if pillarconfigure, err = this.module.configure.getGamePandamasMz(pillar.Lv); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if !utils.IsToday(pillar.Lastusetime) { //上一次训练不是今天 pillar.Usenum = 0 } if pillar.Usenum >= pillarconfigure.Limitation { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PracticeUseLimit, Title: pb.ErrorCode_PracticeUseLimit.ToString(), Message: "pillar usenum to Limitation", } return } if req.Teacher != "" { if room.Knapsack[req.Teacher].State == 1 { //已经被使用 errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("the teacher:%s is working", req.Teacher), } return } room.Knapsack[req.Teacher].State = 1 if tconfigure, err = this.module.configure.getGamePandamasJx(req.Teacher); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if !utils.IsToday(room.Knapsack[req.Teacher].Lastusetime) { room.Knapsack[req.Teacher].Usenum = 0 } if room.Knapsack[req.Teacher].Usenum >= tconfigure.Limitation { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("the teacher:%s use to Limit", req.Teacher), } return } room.Knapsack[req.Teacher].Usenum++ room.Knapsack[req.Teacher].Lastusetime = configure.Now().Unix() if tconfigure.Race != 0 && tconfigure.Race != heroconf.Race { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("the teacher race:%d and the herorace:%d is race no can use", tconfigure.Race, heroconf.Race), } return } if tconfigure.Job != 0 && tconfigure.Job != heroconf.Job { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("the teacher job:%d and the hero job:%d is race no can use", tconfigure.Job, heroconf.Job), } return } if tconfigure.BanHero == hero.HeroID { //禁止使用 errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("teacher:%s and hero:%s no can together", req.Teacher, hero.HeroID), } return } extra += int32(float64(pillarconfigure.PlacementDuration) * float64(tconfigure.Duration) / float64(1000)) pillar.Teacher = req.Teacher } if req.Prop != "" { if room.Knapsack[req.Prop].State == 1 { //已经被使用 errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } room.Knapsack[req.Prop].State = 1 if pconfigure, err = this.module.configure.getGamePandamasJx(req.Prop); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if !utils.IsToday(room.Knapsack[req.Prop].Lastusetime) { room.Knapsack[req.Prop].Usenum = 0 } if room.Knapsack[req.Prop].Usenum >= tconfigure.Limitation { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("the prop:%s use to Limit", req.Prop), } return } room.Knapsack[req.Prop].Usenum++ room.Knapsack[req.Prop].Lastusetime = configure.Now().Unix() if pconfigure.Race != 0 && pconfigure.Race != heroconf.Race { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("the teacher race:%d and the herorace:%d is race no can use", tconfigure.Race, heroconf.Race), } return } if pconfigure.Job != 0 && pconfigure.Job != heroconf.Job { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("the teacher job:%d and the hero job:%d is race no can use", tconfigure.Job, heroconf.Job), } return } extra += int32(float64(pillarconfigure.PlacementDuration) * float64(pconfigure.Duration) / float64(1000)) pillar.Prop = req.Prop } pillar.Hero = req.Hero if errdata = this.module.ModuleHero.KungFuHero(session, req.Hero, true, ""); errdata != nil { return } pillar.Start = configure.Now().Unix() if extra >= 0 { pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix() pillar.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix() } else { pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix() pillar.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix() } pillar.Usenum++ pillar.Lastusetime = configure.Now().Unix() this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{ "knapsack": room.Knapsack, filed: pillar, }) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype149, 1)) session.SendMsg(string(this.module.GetType()), "practice", &pb.PracticePracticeResp{Pillar: pillar}) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.ModuleBuried.TriggerBuried(session, tasks...) }) return }