This commit is contained in:
liwei1dao 2023-04-12 18:41:57 +08:00
commit d718496138
2 changed files with 8 additions and 42 deletions

View File

@ -115,7 +115,8 @@ func GetRandNum(min, max int32) int32 {
if max == min { if max == min {
return 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 return int32(n.Int64()) + min
} }

View File

@ -6,7 +6,6 @@ import (
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/core/cbase"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"sync" "sync"
@ -186,7 +185,7 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
index := comm.GetRandW(szW) index := comm.GetRandW(szW)
_data := this.GetLotterConfById(szID[index]) _data := this.GetLotterConfById(szID[index])
fmt.Printf("获得最终的道具 :%d", _data.Id) 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{ items = append(items, &cfg.Gameatn{
A: _data.Itemid.A, A: _data.Itemid.A,
@ -198,8 +197,8 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
} else if this.Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比) } else if this.Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
for _, v := range this._groupType2[key] { for _, v := range this._groupType2[key] {
if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值
if _data.Itemwt >= comm.GetRandNum(0, 1000) { // 命中 if _data.Itemwt >= comm.GetRandNum(1, 1000) { // 命中
count := comm.GetRandNum(_data.Min, _data.Max+1) count := comm.GetRandNum(_data.Min, _data.Max)
items = append(items, &cfg.Gameatn{ items = append(items, &cfg.Gameatn{
A: _data.Itemid.A, A: _data.Itemid.A,
T: _data.Itemid.T, T: _data.Itemid.T,
@ -244,7 +243,7 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
index := comm.GetRandW(szW) index := comm.GetRandW(szW)
_data := this.GetLotterConfById(szID[index]) _data := this.GetLotterConfById(szID[index])
fmt.Printf("获得最终的道具 :%d", _data.Id) 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{ items = append(items, &cfg.Gameatn{
A: _data.Itemid.A, A: _data.Itemid.A,
@ -255,8 +254,8 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
} else if this.Stype[key] == 2 { } else if this.Stype[key] == 2 {
for _, v := range this._groupType2[key] { for _, v := range this._groupType2[key] {
if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值
if _data.Itemwt >= comm.GetRandNum(0, 1000) { // 命中 if _data.Itemwt >= comm.GetRandNum(1, 1000) { // 命中
count := comm.GetRandNum(_data.Min, _data.Max+1) count := comm.GetRandNum(_data.Min, _data.Max)
items = append(items, &cfg.Gameatn{ items = append(items, &cfg.Gameatn{
A: _data.Itemid.A, A: _data.Itemid.A,
T: _data.Itemid.T, T: _data.Itemid.T,
@ -408,40 +407,6 @@ func (this *MCompConfigure) GetDropData(dropId int32) (data []*cfg.GameDropData)
return 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) { func (this *MCompConfigure) GetDropReward(dropId int32) (result []*cfg.Gameatn) {
result = make([]*cfg.Gameatn, 0) result = make([]*cfg.Gameatn, 0)