package martialhall import ( "crypto/rand" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "math/big" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.MartialhallUpgradeReq) (code pb.ErrorCode) { return } ///练功请求 func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.MartialhallUpgradeReq) (code pb.ErrorCode, data proto.Message) { var ( err error mart *pb.DBMartialhall mdata *cfg.GameKungfuMasterworkerData issucc bool ) if code = this.UpgradeCheck(session, req); code != pb.ErrorCode_Success { return } if mart, err = this.module.modelMartialhall.queryUserMartialhall(session.GetUserId()); err != nil { code = pb.ErrorCode_DBError return } if mdata, err = this.module.configure.getMasterworker(mart.Lv); err != nil { code = pb.ErrorCode_ConfigNoFound return } if code = this.module.ConsumeRes(session, mdata.LevelDeplete, true); code != pb.ErrorCode_Success { return } n, _ := rand.Int(rand.Reader, big.NewInt(1000)) if int32(n.Int64()) < mdata.Probability { issucc = true } else { issucc = false } if issucc { mart.Lv++ settlement(mart.Pillar1, mdata) settlement(mart.Pillar2, mdata) settlement(mart.Pillar3, mdata) settlement(mart.Pillar4, mdata) settlement(mart.Pillar5, mdata) this.module.modelMartialhall.Add(session.GetUserId(), mart) } session.SendMsg(string(this.module.GetType()), "upgrade", &pb.MartialhallUpgradeResp{Issucc: issucc, Info: mart}) return }