diff --git a/modules/gourmet/module.go b/modules/gourmet/module.go index e75058532..3eb7b7ae6 100644 --- a/modules/gourmet/module.go +++ b/modules/gourmet/module.go @@ -6,12 +6,11 @@ package gourmet import ( - "crypto/rand" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" cfg "go_dreamfactory/sys/configure/structs" - "math/big" + "math/rand" ) type Gourmet struct { @@ -61,8 +60,8 @@ func (this *Gourmet) GetSuccessRate(m map[string]int32, conf *cfg.GameBreakingba rate += v.N * v1 } } - n, _ := rand.Int(rand.Reader, big.NewInt(100)) - if n.Int64() < int64(rate) { + + if rand.Int31n(100) < rate { return conf.Delicacies } else { cid = this.configure.GetNormalGourmetFood() diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index 59c461bba..1f2c402eb 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -76,7 +76,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq // 3,4,5 星权重 starWeight := []int32{cfgDraw.BasePoolStar3, cfgDraw.BasePoolStar4, cfgDraw.BasePoolStar5} - starIndex := this.module.modelHero.GetRandW(starWeight) // 3 4 5 星索引 + starIndex := comm.GetRandW(starWeight) // 3 4 5 星索引 // 特殊规则 DrawCard_5StarsInRange 第2-30次抽奖必出一个5星英雄(普通卡池) inRangeConf := this.module.ModuleTools.GetGlobalConf().DrawCard5StarsInRange @@ -249,7 +249,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq for { starWeight := []int32{cfgDraw.CampPoolStar3, cfgDraw.CampPoolStar4, cfgDraw.CampPoolStar5} - starIndex := this.module.modelHero.GetRandW(starWeight) + starIndex := comm.GetRandW(starWeight) if starIndex == 1 { star4Max++ } else if starIndex == 2 { @@ -279,7 +279,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq for _, v := range _data[int32(star)] { sz = append(sz, v.Weight) } - randomIndex := this.module.modelHero.GetRandW(sz) + randomIndex := comm.GetRandW(sz) if v, ok := _data[int32(star)]; ok { if int32(len(v)) > randomIndex { diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 0cca58876..d5369996a 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -655,27 +655,6 @@ func (this *ModelHero) CheckPool(drawCount int32, config *cfg.GameGlobalData) (p return config.BasePool7.P } -// 通数组里的权重随机命中 返回值为数组的下标 -func (this *ModelHero) GetRandW(sz []int32) int32 { - - if len(sz) > 0 { - var _totalW int64 // 总权重 - var _tmpW int64 // 临时权重 - for _, v := range sz { - _totalW += int64(v) - } - // 随机权重 - n, _ := rand.Int(rand.Reader, big.NewInt(_totalW)) - for i, v := range sz { - _tmpW += int64(v) - if n.Int64() < _tmpW { - return int32(i) - } - } - } - return 0 -} - // 通过卡池的权重 获取英雄 func (this *ModelHero) GetRandHeroIdBypool(sz []int32) int32 { diff --git a/modules/hero/module.go b/modules/hero/module.go index 7cb13c85a..93fcaba75 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -541,11 +541,7 @@ func (this *Hero) ContinuousRestriction(uid string, heroCid string, drawCount in return heroCid } - sz := make([]int32, 0) - for _, v := range _data[5] { - sz = append(sz, v.Weight) - } - //randomIndex := this.modelHero.GetRandW(sz) + for i := 0; i < len(_data[5]); i++ { if v, ok := _data[5]; ok { if int32(len(v)) > int32(i) { @@ -922,7 +918,7 @@ func (this *Hero) DrawCardContinuousRestrictionCamp(cardId string, race map[int3 if heroConf, _ := this.configure.GetHeroConfig(cardId); heroConf != nil { if v1, ok := race[heroConf.Race]; ok && v1 > iMaxCount { // 满足条件 再随机获取一个英雄 for i := 0; i < int(iMaxCount); i++ { // 最多循环次数 - randomIndex := this.modelHero.GetRandW(sz) + randomIndex := comm.GetRandW(sz) if int32(len(sz)) > randomIndex { if v1, ok := race[heroConf.Race]; !ok && v1 <= iMaxCount { card = data[randomIndex].Id