package martialhall import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "time" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) PracticeCheck(session comm.IUserSession, req *pb.MartialhallPracticeReq) (code pb.ErrorCode) { if req.Pillar == 0 || req.Hero == "" || req.Time == 0 { code = pb.ErrorCode_ReqParameterError } return } ///练功请求 func (this *apiComp) Practice(session comm.IUserSession, req *pb.MartialhallPracticeReq) (code pb.ErrorCode, data proto.Message) { var ( err error mart *pb.DBMartialhall pillar *pb.DBPillar mdata *cfg.GameKungfuMasterworkerData filed string ktime int32 num int32 ) if code = this.PracticeCheck(session, req); code != pb.ErrorCode_Success { return } ktime = this.module.configure.GetGlobalConf().KungfuTime num = req.Time / ktime if mart, err = this.module.modelMartialhall.queryUserMartialhall(session.GetUserId()); err != nil { code = pb.ErrorCode_DBError } if mdata, err = this.module.configure.getMasterworker(mart.Lv); err != nil { code = pb.ErrorCode_ConfigNoFound return } switch req.Pillar { case 1: pillar = mart.Pillar1 filed = "pillar1" break case 2: pillar = mart.Pillar2 filed = "pillar2" break case 3: pillar = mart.Pillar3 filed = "pillar3" break case 4: pillar = mart.Pillar4 filed = "pillar4" break case 5: pillar = mart.Pillar5 filed = "pillar5" break } if pillar == nil || !pillar.Isunlock { code = pb.ErrorCode_MartialhallNotUnlocked return } if pillar.State != pb.PillarState_NoUse { code = pb.ErrorCode_MartialhallInUse return } var sale = make([]*cfg.Gameatn, 0) for _, v := range mdata.Deplete { sale = append(sale, &cfg.Gameatn{ A: v.A, T: v.T, N: v.N * num, }) } if code = this.module.ConsumeRes(session, sale, true); code != pb.ErrorCode_Success { return } if code = this.module.ModuleHero.KungFuHero(session, req.Hero, true); code != pb.ErrorCode_Success { return } pillar.State = pb.PillarState_Useing pillar.Hero = req.Hero pillar.Start = time.Now().Unix() pillar.End = time.Now().Add(time.Minute * time.Duration(req.Time)).Unix() pillar.Lastbill = time.Now().Unix() pillar.Reward = 0 this.module.modelMartialhall.Change(session.GetUserId(), map[string]interface{}{ filed: pillar, }) session.SendMsg(string(this.module.GetType()), "practice", &pb.MartialhallPracticeResp{Issucc: true, Info: mart}) return }