From 5bfa66a65dc66061d0345863907b74009a6c0ed2 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 14 Aug 2023 11:12:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=89=E8=90=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/tools/comp_configure.go | 253 +++++++++++++++----------------- 1 file changed, 120 insertions(+), 133 deletions(-) diff --git a/modules/tools/comp_configure.go b/modules/tools/comp_configure.go index a2710ed8a..1cebb6369 100644 --- a/modules/tools/comp_configure.go +++ b/modules/tools/comp_configure.go @@ -51,9 +51,9 @@ type MCompConfigure struct { _groupType1 map[int64][]int32 //value cid // 小组类型为2 _groupType2 map[int64][]int32 //value cid - Btype map[int32]int32 - Stype map[int64]int32 // subtype - SNum map[int64]int32 // 小组产出数量 + //Btype map[int32]int32 + Stype map[int64]int32 // subtype + SNum map[int64]int32 // 小组产出数量 _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._groupType1 = 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.SNum = make(map[int64]int32, 0) configure.RegisterConfigure(game_lottery, cfg.NewGameLottery, this.LoadGroupData) @@ -102,13 +102,21 @@ func (this *MCompConfigure) LoadGroupData() { this._lotteryType2 = make(map[int32][]int32, 0) this._groupType1 = 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.SNum = make(map[int64]int32, 0) + var tmp1 int64 + var tmp2 int64 + var itype int32 for _, value := range configure.GetDataList() { 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) - + if value.Type == 0 { + value.Type = itype + } else { + itype = value.Type + } // 数据安全校验 if 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) return } - if _, ok := this.Btype[value.Lotteryid]; !ok { - this.Btype[value.Lotteryid] = value.Type - } - if _, ok := this.Stype[key]; !ok { this.Stype[key] = value.Subtype } if _, ok := this.SNum[key]; !ok { this.SNum[key] = value.Groupnum } - if this.Btype[value.Lotteryid] == 1 { - this._lotteryType1[value.Lotteryid] = append(this._lotteryType1[value.Lotteryid], value.Id) - } else if this.Btype[value.Lotteryid] == 2 { - this._lotteryType2[value.Lotteryid] = append(this._lotteryType2[value.Lotteryid], value.Id) + + if value.Type == 1 || value.Type == 0 { + if tmp1 != key { + 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 @@ -163,138 +176,112 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32, } } // 优先校验大组ID 的类型 - if this.Btype[lotteryId] == 1 { // 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组 - var ( - szW []int32 // 权重数组 - szID []int32 // 小组ID 数组 - groupID int32 - gourp map[int32]int32 // key 小组ID value 权重 - ) + var ( + szW []int32 // 权重数组 + szID []int32 // 小组ID 数组 + groupID int32 + ) - gourp = make(map[int32]int32, 0) - // 随机小组id - for _, v := range this._lotteryType1[lotteryId] { - 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 _, ok := gourp[_data.Groupid]; !ok { - gourp[_data.Groupid] = _data.Groupwt // 小组ID 权重赋值 - szW = append(szW, _data.Groupwt) - szID = append(szID, _data.Groupid) - } - } + // 随机小组id + for _, v := range this._lotteryType1[lotteryId] { + 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) } } + } - groupID = szID[comm.GetRandW(szW)] // 获得小组ID - //fmt.Printf("大组类型为1的,获得小组ID :%d,dropID:%d", groupID, lotteryId) - key := int64(lotteryId)<<31 + int64(groupID) - // 小组ID 类型判断 - if this.Stype[key] == 1 { // 该小组的道具为权重掉落,必定从N个道具中随机出1个道具 - for i := 0; i < int(this.SNum[key]); i++ { - szW = make([]int32, 0) - szID = make([]int32, 0) - gourp = make(map[int32]int32, 0) - 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] { + groupID = szID[comm.GetRandW(szW)] // 获得小组ID + //fmt.Printf("大组类型为1的,获得小组ID :%d,dropID:%d", groupID, lotteryId) + key := int64(lotteryId)<<31 + int64(groupID) + // 小组ID 类型判断 + if this.Stype[key] == 1 { // 该小组的道具为权重掉落,必定从N个道具中随机出1个道具 + for i := 0; i < int(this.SNum[key]); i++ { + sztW := make([]int32, 0) + sztID := make([]int32, 0) + for _, v := range this._groupType1[key] { if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - if _data.Itemwt != 0 { - wt = _data.Itemwt - } - 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, // 小组产出数量 - }) - } + sztW = append(sztW, _data.Itemwt) + sztID = append(sztID, _data.Id) } } - 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 都随机取一次 - var szGroupID []int32 // 获得的权重数组 - gourp := make([]*cfg.GameLotteryData, 0) // key 小组ID value 权重 - for _, v := range this._lotteryType2[lotteryId] { - 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)) { // 过滤等级等条件 - gourp = append(gourp, _data) + + } 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) + items = append(items, &cfg.Gameatn{ + A: _data.Itemid.A, + T: _data.Itemid.T, + N: _data.Itemid.N * count, // 小组产出数量 + }) } } } - // 过滤 group - var wt int32 - // 类型为2 可能会同时获得多个组id - for _, v := range gourp { - k := v.Groupid - if v.Groupwt != 0 { - wt = v.Groupwt + + } + // 每个小组id 都随机取一次 + szW = make([]int32, 0) + szID = make([]int32, 0) + for _, v := range this._lotteryType2[lotteryId] { + 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) - if this.Stype[key] == 1 { // 随机一组数据 - for i := 0; i < int(this.SNum[key]); i++ { - szW := make([]int32, 0) - szID := make([]int32, 0) - gourp := make(map[int32]int32, 0) - 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, - }) - } - } else if this.Stype[key] == 2 { - var wt int32 - for _, v := range this._groupType2[key] { + } + } + + // 类型为2 可能会同时获得多个组id + for pos, v := range szW { + key := int64(lotteryId)<<31 + int64(szID[pos]) + //fmt.Printf("大组类型为2的,获得小组ID :%d,dropID:%d", k, v.Id) + if v >= comm.GetRandNum(0, 1000) { // 命中 + if this.Stype[key] == 1 { // 随机一组数据 + for i := 0; i < int(this.SNum[key]); i++ { + sztW := make([]int32, 0) + sztID := make([]int32, 0) + for _, v := range this._groupType1[key] { if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - if _data.Itemwt != 0 { - wt = _data.Itemwt - } - if wt >= 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, // 小组产出数量 - }) - } + sztW = append(sztW, _data.Itemwt) + sztID = append(sztID, _data.Id) + } + } + index := comm.GetRandW(sztW) + _data := this.GetLotterConfById(sztID[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 { + 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, // 小组产出数量 + }) } } }