优化调整

This commit is contained in:
meixiongfeng 2023-06-05 16:14:34 +08:00
parent 2138bb81fb
commit b61085b0e1
4 changed files with 8 additions and 34 deletions

View File

@ -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()

View File

@ -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 {

View File

@ -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 {

View File

@ -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