掉落优化

This commit is contained in:
meixiongfeng 2023-08-14 11:12:40 +08:00
parent 5abb015088
commit 5bfa66a65d

View File

@ -51,9 +51,9 @@ type MCompConfigure struct {
_groupType1 map[int64][]int32 //value cid _groupType1 map[int64][]int32 //value cid
// 小组类型为2 // 小组类型为2
_groupType2 map[int64][]int32 //value cid _groupType2 map[int64][]int32 //value cid
Btype map[int32]int32 //Btype map[int32]int32
Stype map[int64]int32 // subtype Stype map[int64]int32 // subtype
SNum map[int64]int32 // 小组产出数量 SNum map[int64]int32 // 小组产出数量
_price map[int32][]*cfg.GamePricegroupData _price map[int32][]*cfg.GamePricegroupData
} }
@ -84,7 +84,7 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com
this._lotteryType2 = make(map[int32][]int32, 0) this._lotteryType2 = make(map[int32][]int32, 0)
this._groupType1 = make(map[int64][]int32, 0) this._groupType1 = make(map[int64][]int32, 0)
this._groupType2 = make(map[int64][]int32, 0) this._groupType2 = make(map[int64][]int32, 0)
this.Btype = make(map[int32]int32, 0) //this.Btype = make(map[int32]int32, 0)
this.Stype = make(map[int64]int32, 0) this.Stype = make(map[int64]int32, 0)
this.SNum = make(map[int64]int32, 0) this.SNum = make(map[int64]int32, 0)
configure.RegisterConfigure(game_lottery, cfg.NewGameLottery, this.LoadGroupData) configure.RegisterConfigure(game_lottery, cfg.NewGameLottery, this.LoadGroupData)
@ -102,13 +102,21 @@ func (this *MCompConfigure) LoadGroupData() {
this._lotteryType2 = make(map[int32][]int32, 0) this._lotteryType2 = make(map[int32][]int32, 0)
this._groupType1 = make(map[int64][]int32, 0) this._groupType1 = make(map[int64][]int32, 0)
this._groupType2 = make(map[int64][]int32, 0) this._groupType2 = make(map[int64][]int32, 0)
this.Btype = make(map[int32]int32, 0) //this.Btype = make(map[int32]int32, 0)
this.Stype = make(map[int64]int32, 0) this.Stype = make(map[int64]int32, 0)
this.SNum = make(map[int64]int32, 0) this.SNum = make(map[int64]int32, 0)
var tmp1 int64
var tmp2 int64
var itype int32
for _, value := range configure.GetDataList() { for _, value := range configure.GetDataList() {
key := int64(value.Lotteryid)<<31 + int64(value.Groupid) key := int64(value.Lotteryid)<<31 + int64(value.Groupid)
// key2 := int64(value.Lotteryid)<<31 + int64(value.Type)
this._group[key] = append(this._group[key], value.Id) this._group[key] = append(this._group[key], value.Id)
if value.Type == 0 {
value.Type = itype
} else {
itype = value.Type
}
// 数据安全校验 // 数据安全校验
if value.Min > value.Max { if value.Min > value.Max {
log.Errorf("value.Min:%d > value.Max :%d ", value.Min, value.Max) log.Errorf("value.Min:%d > value.Max :%d ", value.Min, value.Max)
@ -123,20 +131,25 @@ func (this *MCompConfigure) LoadGroupData() {
log.Errorf("value.Playerlvmin:%d > value.Playerlvmax :%d ", value.Playerlvmin, value.Playerlvmax) log.Errorf("value.Playerlvmin:%d > value.Playerlvmax :%d ", value.Playerlvmin, value.Playerlvmax)
return return
} }
if _, ok := this.Btype[value.Lotteryid]; !ok {
this.Btype[value.Lotteryid] = value.Type
}
if _, ok := this.Stype[key]; !ok { if _, ok := this.Stype[key]; !ok {
this.Stype[key] = value.Subtype this.Stype[key] = value.Subtype
} }
if _, ok := this.SNum[key]; !ok { if _, ok := this.SNum[key]; !ok {
this.SNum[key] = value.Groupnum this.SNum[key] = value.Groupnum
} }
if this.Btype[value.Lotteryid] == 1 {
this._lotteryType1[value.Lotteryid] = append(this._lotteryType1[value.Lotteryid], value.Id) if value.Type == 1 || value.Type == 0 {
} else if this.Btype[value.Lotteryid] == 2 { if tmp1 != key {
this._lotteryType2[value.Lotteryid] = append(this._lotteryType2[value.Lotteryid], value.Id) this._lotteryType1[value.Lotteryid] = append(this._lotteryType1[value.Lotteryid], value.Id)
tmp1 = key
}
}
if value.Type == 2 || value.Type == 0 {
if tmp2 != key {
this._lotteryType2[value.Lotteryid] = append(this._lotteryType2[value.Lotteryid], value.Id)
tmp2 = key
}
} }
if this.Stype[key] == 1 { // 小组ID为1 if this.Stype[key] == 1 { // 小组ID为1
@ -163,138 +176,112 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
} }
} }
// 优先校验大组ID 的类型 // 优先校验大组ID 的类型
if this.Btype[lotteryId] == 1 { // 该大组中的小组为权重掉落必定从N个小组中随机出1个小组 var (
var ( szW []int32 // 权重数组
szW []int32 // 权重数组 szID []int32 // 小组ID 数组
szID []int32 // 小组ID 数组 groupID int32
groupID int32 )
gourp map[int32]int32 // key 小组ID value 权重
)
gourp = make(map[int32]int32, 0) // 随机小组id
// 随机小组id for _, v := range this._lotteryType1[lotteryId] {
for _, v := range this._lotteryType1[lotteryId] { if _data := this.GetLotterConfById(v); _data != nil {
if _data := this.GetLotterConfById(v); _data != nil { if (_data.Playerlvmax == 0 || (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax)) && (_data.VIPmax == 0 || (_data.VIPmin <= vipLv && vipLv <= _data.VIPmax)) { // 过滤等级等条件
if (_data.Playerlvmax == 0 || (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax)) && (_data.VIPmax == 0 || (_data.VIPmin <= vipLv && vipLv <= _data.VIPmax)) { // 过滤等级等条件 szW = append(szW, _data.Groupwt)
if _, ok := gourp[_data.Groupid]; !ok { szID = append(szID, _data.Groupid)
gourp[_data.Groupid] = _data.Groupwt // 小组ID 权重赋值
szW = append(szW, _data.Groupwt)
szID = append(szID, _data.Groupid)
}
}
} }
} }
}
groupID = szID[comm.GetRandW(szW)] // 获得小组ID groupID = szID[comm.GetRandW(szW)] // 获得小组ID
//fmt.Printf("大组类型为1的,获得小组ID :%ddropID%d", groupID, lotteryId) //fmt.Printf("大组类型为1的,获得小组ID :%ddropID%d", groupID, lotteryId)
key := int64(lotteryId)<<31 + int64(groupID) key := int64(lotteryId)<<31 + int64(groupID)
// 小组ID 类型判断 // 小组ID 类型判断
if this.Stype[key] == 1 { // 该小组的道具为权重掉落必定从N个道具中随机出1个道具 if this.Stype[key] == 1 { // 该小组的道具为权重掉落必定从N个道具中随机出1个道具
for i := 0; i < int(this.SNum[key]); i++ { for i := 0; i < int(this.SNum[key]); i++ {
szW = make([]int32, 0) sztW := make([]int32, 0)
szID = make([]int32, 0) sztID := make([]int32, 0)
gourp = make(map[int32]int32, 0) for _, v := range this._groupType1[key] {
for _, v := range this._groupType1[key] {
if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值
if _, ok := gourp[_data.Groupid]; !ok {
szW = append(szW, _data.Itemwt)
szID = append(szID, _data.Id)
}
}
}
index := comm.GetRandW(szW)
_data := this.GetLotterConfById(szID[index])
//fmt.Printf("获得最终的道具 :%d", _data.Id)
count := comm.GetRandNum(_data.Min, _data.Max)
// 随机获得的数量
items = append(items, &cfg.Gameatn{
A: _data.Itemid.A,
T: _data.Itemid.T,
N: _data.Itemid.N * count,
})
}
return
} else if this.Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
var wt int32
for _, v := range this._groupType2[key] {
if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值
if _data.Itemwt != 0 { sztW = append(sztW, _data.Itemwt)
wt = _data.Itemwt sztID = append(sztID, _data.Id)
}
if wt >= comm.GetRandNum(0, 1000) { // 命中
count := comm.GetRandNum(_data.Min, _data.Max)
items = append(items, &cfg.Gameatn{
A: _data.Itemid.A,
T: _data.Itemid.T,
N: _data.Itemid.N * count, // 小组产出数量
})
}
} }
} }
return index := comm.GetRandW(sztW)
_data := this.GetLotterConfById(sztID[index])
count := comm.GetRandNum(_data.Min, _data.Max)
// 随机获得的数量
items = append(items, &cfg.Gameatn{
A: _data.Itemid.A,
T: _data.Itemid.T,
N: _data.Itemid.N * count,
})
} }
} else if this.Btype[lotteryId] == 2 { // 该大组中的小组为概率掉落,每个小组都会随机一次是否会掉落(单位为千分比)
// 每个小组id 都随机取一次 } else if this.Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
var szGroupID []int32 // 获得的权重数组 for _, v := range this._groupType2[key] {
gourp := make([]*cfg.GameLotteryData, 0) // key 小组ID value 权重 if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值
for _, v := range this._lotteryType2[lotteryId] {
if _data := this.GetLotterConfById(v); _data != nil { if _data.Itemwt >= comm.GetRandNum(0, 1000) { // 命中
if (_data.Playerlvmax == 0 || (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax)) && (_data.VIPmax == 0 || (_data.VIPmin <= vipLv && vipLv <= _data.VIPmax)) { // 过滤等级等条件 count := comm.GetRandNum(_data.Min, _data.Max)
gourp = append(gourp, _data) items = append(items, &cfg.Gameatn{
A: _data.Itemid.A,
T: _data.Itemid.T,
N: _data.Itemid.N * count, // 小组产出数量
})
} }
} }
} }
// 过滤 group
var wt int32 }
// 类型为2 可能会同时获得多个组id // 每个小组id 都随机取一次
for _, v := range gourp { szW = make([]int32, 0)
k := v.Groupid szID = make([]int32, 0)
if v.Groupwt != 0 { for _, v := range this._lotteryType2[lotteryId] {
wt = v.Groupwt if _data := this.GetLotterConfById(v); _data != nil {
if (_data.Playerlvmax == 0 || (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax)) && (_data.VIPmax == 0 || (_data.VIPmin <= vipLv && vipLv <= _data.VIPmax)) { // 过滤等级等条件
szW = append(szW, _data.Groupwt)
szID = append(szID, _data.Groupid)
} }
//fmt.Printf("大组类型为2的,获得小组ID :%d,dropID:%d", k, v.Id) }
if wt >= comm.GetRandNum(0, 1000) { // 命中 }
szGroupID = append(szGroupID, k)
key := int64(lotteryId)<<31 + int64(k) // 类型为2 可能会同时获得多个组id
if this.Stype[key] == 1 { // 随机一组数据 for pos, v := range szW {
for i := 0; i < int(this.SNum[key]); i++ { key := int64(lotteryId)<<31 + int64(szID[pos])
szW := make([]int32, 0) //fmt.Printf("大组类型为2的,获得小组ID :%d,dropID:%d", k, v.Id)
szID := make([]int32, 0) if v >= comm.GetRandNum(0, 1000) { // 命中
gourp := make(map[int32]int32, 0) if this.Stype[key] == 1 { // 随机一组数据
for _, v := range this._groupType1[key] { for i := 0; i < int(this.SNum[key]); i++ {
if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 sztW := make([]int32, 0)
if _, ok := gourp[_data.Groupid]; !ok { sztID := make([]int32, 0)
szW = append(szW, _data.Itemwt) for _, v := range this._groupType1[key] {
szID = append(szID, _data.Id)
}
}
}
index := comm.GetRandW(szW)
_data := this.GetLotterConfById(szID[index])
//fmt.Printf("获得最终的道具 :%d", _data.Id)
count := comm.GetRandNum(_data.Min, _data.Max)
// 随机获得的数量
items = append(items, &cfg.Gameatn{
A: _data.Itemid.A,
T: _data.Itemid.T,
N: _data.Itemid.N * count,
})
}
} else if this.Stype[key] == 2 {
var wt int32
for _, v := range this._groupType2[key] {
if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值
if _data.Itemwt != 0 { sztW = append(sztW, _data.Itemwt)
wt = _data.Itemwt sztID = append(sztID, _data.Id)
} }
if wt >= comm.GetRandNum(1, 1000) { // 命中 }
count := comm.GetRandNum(_data.Min, _data.Max) index := comm.GetRandW(sztW)
items = append(items, &cfg.Gameatn{ _data := this.GetLotterConfById(sztID[index])
A: _data.Itemid.A, //fmt.Printf("获得最终的道具 :%d", _data.Id)
T: _data.Itemid.T, count := comm.GetRandNum(_data.Min, _data.Max)
N: _data.Itemid.N * count, // 小组产出数量 // 随机获得的数量
}) items = append(items, &cfg.Gameatn{
} A: _data.Itemid.A,
T: _data.Itemid.T,
N: _data.Itemid.N * count,
})
}
} else if this.Stype[key] == 2 {
for _, v := range this._groupType2[key] {
if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值
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,
N: _data.Itemid.N * count, // 小组产出数量
})
} }
} }
} }