package hero 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) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode) { if req.DrawType <= 0 { // 只能是单抽或10抽 code = pb.ErrorCode_ReqParameterError } return } //抽卡 func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode, data proto.Message) { var ( szCards []int32 // 最终抽到的卡牌 totalWeight int64 // 总权重 curWeigth int64 // 临时随机获得的权重 drawTimes int32 // 抽卡次数 hitStar4 int32 // 抽了多少次还没获得4星英雄 hitStar5 int32 // 抽了多少次还没获得5星英雄 hitStar int32 // 抽中几星 curStar4Count int32 // 当前4星没抽到的次数 curStar5Count int32 // 当前5星没抽到的次数 floor4Count int32 // 4星保底次数 floor5Count int32 // 5星保底次数 ) szCards = make([]int32, 0) rsp := &pb.HeroDrawCardResp{} curStar4Count = this.GetFloorStarData(req.DrawType, session.GetUserId(), 4) curStar5Count = this.GetFloorStarData(req.DrawType, session.GetUserId(), 5) this.module.Debugf("当前4星抽卡没中次数:%d, 当前5星抽卡没中次数:%d", curStar4Count, curStar5Count) // 抽卡相关 // 获取配置文件的权重信息 _conf, err := this.module.configure.GetHeroDrawConfig() if err != nil { code = pb.ErrorCode_ConfigNoFound return } _costConf, err := this.module.configure.GetDrawCostConfigByID(req.DrawType) if err != nil { code = pb.ErrorCode_ConfigNoFound return } floor4Count = _costConf.Floor4 // 4星保底次数 floor5Count = _costConf.Floor5 // 五星保底次数 if floor4Count == 0 || floor5Count == 0 { code = pb.ErrorCode_ConfigNoFound return } sz := make([]*cfg.Game_atn, 0) sz = append(sz, _costConf.Cost) code = this.module.CheckRes(session, sz) // 消耗校验 if code != pb.ErrorCode_Success { return } drawTimes = _costConf.Count // 抽卡次数 for _, v := range _conf.GetDataList() { totalWeight += int64(v.Weight) // 统计所有权重 } this.module.configure.GetDrawUpDrawConfig() drawTimes = 1 for i := 0; i < int(drawTimes); i++ { n, _ := rand.Int(rand.Reader, big.NewInt(totalWeight)) // [0,totalWeight) for _, v := range _conf.GetDataList() { curWeigth += int64(v.Weight) if curWeigth < n.Int64() { // 命中 szCards = append(szCards, v.Id) // 获取当前星级 _getCardCfg := this.module.configure.GetHero(v.Id) //获取的英雄信息 if _getCardCfg != nil { continue } if _getCardCfg.Star == 4 { // 当抽取到的英雄是4星的时候 清除 该类型的保底次数 this.SetFloorStarData(req.DrawType, session.GetUserId(), 4) hitStar4 = 0 hitStar = 4 break } else if _getCardCfg.Star == 5 { // 当抽取到的英雄是5星的时候 清除 该类型的保底次数 this.SetFloorStarData(req.DrawType, session.GetUserId(), 5) hitStar5 = 0 // 清0 hitStar = 5 break } hitStar4++ hitStar5++ if hitStar4 >= floor4Count { // 达到保底次数了 修改当前卡牌星级 break } if hitStar5 >= floor5Count { // 触发5星保底 // 5星卡池找 break } break } } if hitStar != 0 { hitStar = 0 this.ModifyFloorStarData(req.DrawType, session.GetUserId(), hitStar) // 重置该星级保底 } } if hitStar4 != 0 { this.AddFloorStarData(req.DrawType, session.GetUserId(), 4, hitStar4) // 增加4星保底次数 } if hitStar5 != 0 { this.AddFloorStarData(req.DrawType, session.GetUserId(), 5, hitStar5) // 增加5星保底次数 } //计算保底 if err := this.module.modelHero.createMultiHero(session.GetUserId(), szCards...); err != nil { code = pb.ErrorCode_HeroCreate return } rsp.Heroes = szCards session.SendMsg(string(this.module.GetType()), DrawCard, rsp) return } // 获取当前卡牌类型保底次数 func (this *apiComp) GetFloorStarData(drawType int32, uid string, star int32) (count int32) { return } // 清除保底信息(drawType 抽卡类型) func (this *apiComp) SetFloorStarData(drawType int32, uid string, star int32) { return } // 当前没有抽中 增加保底次数 func (this *apiComp) AddFloorStarData(drawType int32, uid string, star int32, count int32) { return } // 当前有抽中 修改保底次数 func (this *apiComp) ModifyFloorStarData(drawType int32, uid string, star int32) { return }