diff --git a/comm/core.go b/comm/core.go index 95b10b121..bb41451c6 100644 --- a/comm/core.go +++ b/comm/core.go @@ -115,7 +115,8 @@ func GetRandNum(min, max int32) int32 { if max == min { return min } - n, _ := rand.Int(rand.Reader, big.NewInt(int64(max-min))) + + n, _ := rand.Int(rand.Reader, big.NewInt(int64(max-min+1))) //+1 是因为 rand方法范围是[0, max) return int32(n.Int64()) + min } diff --git a/modules/comp_configure.go b/modules/comp_configure.go index 171ac96ea..91c124dfb 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -6,7 +6,6 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/log" - "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" @@ -186,7 +185,7 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32, index := comm.GetRandW(szW) _data := this.GetLotterConfById(szID[index]) fmt.Printf("获得最终的道具 :%d", _data.Id) - count := comm.GetRandNum(_data.Min, _data.Max+1) + count := comm.GetRandNum(_data.Min, _data.Max) // 随机获得的数量 items = append(items, &cfg.Gameatn{ A: _data.Itemid.A, @@ -198,8 +197,8 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32, } else if this.Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比) for _, v := range this._groupType2[key] { if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - if _data.Itemwt >= comm.GetRandNum(0, 1000) { // 命中 - count := comm.GetRandNum(_data.Min, _data.Max+1) + if _data.Itemwt >= comm.GetRandNum(1, 1000) { // 命中 + count := comm.GetRandNum(_data.Min, _data.Max) items = append(items, &cfg.Gameatn{ A: _data.Itemid.A, T: _data.Itemid.T, @@ -244,7 +243,7 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32, index := comm.GetRandW(szW) _data := this.GetLotterConfById(szID[index]) fmt.Printf("获得最终的道具 :%d", _data.Id) - count := comm.GetRandNum(_data.Min, _data.Max+1) + count := comm.GetRandNum(_data.Min, _data.Max) // 随机获得的数量 items = append(items, &cfg.Gameatn{ A: _data.Itemid.A, @@ -255,8 +254,8 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32, } else if this.Stype[key] == 2 { for _, v := range this._groupType2[key] { if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - if _data.Itemwt >= comm.GetRandNum(0, 1000) { // 命中 - count := comm.GetRandNum(_data.Min, _data.Max+1) + if _data.Itemwt >= comm.GetRandNum(1, 1000) { // 命中 + count := comm.GetRandNum(_data.Min, _data.Max) items = append(items, &cfg.Gameatn{ A: _data.Itemid.A, T: _data.Itemid.T, @@ -408,40 +407,6 @@ func (this *MCompConfigure) GetDropData(dropId int32) (data []*cfg.GameDropData) return } -// todo 调用drop 表 获取掉落信息 -func (this *MCompConfigure) GetMultipleDropReward(count, dropId int32, items []*pb.UserAssets) (resData []*pb.UserAssets) { - res := make([]*cfg.Gameatn, 0) - - for i := 0; i < int(count); i++ { - data := this.GetDropData(dropId) - szW := make([]int32, 0) - for _, value := range data { - szW = append(szW, value.P) - } - if len(szW) > 0 { - index := comm.GetRandW(szW) - res = append(res, data[index].Prize...) - } - } - for _, v := range res { - bFind := false - for _, v1 := range items { - if v.A == v1.A && v.T == v1.T { - v1.N += v.N - bFind = true - } - } - if !bFind { - items = append(items, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - } - resData = append(resData, items...) - return -} func (this *MCompConfigure) GetDropReward(dropId int32) (result []*cfg.Gameatn) { result = make([]*cfg.Gameatn, 0)