From b3f3147475c89fbf7c39ce58ebd2dda7a5868b5d Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Tue, 11 Apr 2023 15:23:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A0=A1=E9=AA=8C=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/rtask/module.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/rtask/module.go b/modules/rtask/module.go index 406c94666..3eed78efa 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -181,9 +181,9 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) { case comm.Rtype7, comm.Rtype12, comm.Rtype13, comm.Rtype14, comm.Rtype15, comm.Rtype19, comm.Rtype21, comm.Rtype24, comm.Rtype26, comm.Rtype27, comm.Rtype28, comm.Rtype38, - comm.Rtype39, comm.Rtype50, comm.Rtype51, comm.Rtype53, + comm.Rtype39, comm.Rtype51, comm.Rtype53, comm.Rtype54, comm.Rtype57, comm.Rtype58, comm.Rtype60, - comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype73, comm.Rtype88, comm.Rtype104, + comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104, comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131, comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146, comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156: @@ -195,6 +195,15 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) { } condis = append(condis, condi) this.registerVerifyHandle(v.Id, condi) + case comm.Rtype50, comm.Rtype73: + condi := &rtaskCondi{ + condId: v.Id, + find: this.modelRtaskRecord.lessEqualFirstParam, + verify: this.modelRtaskRecord.verifyFromDb, + update: this.modelRtaskRecord.addUpdate, + } + condis = append(condis, condi) + this.registerVerifyHandle(v.Id, condi) case comm.Rtype20: condi := &rtaskCondi{ condId: v.Id, From 5e26c30c53b4d874ffb9260bbcefc382f3cead94 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Tue, 11 Apr 2023 15:28:03 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_rdtaskcondi.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/json/game_rdtaskcondi.json b/bin/json/game_rdtaskcondi.json index 5ff8cd481..1ca51326d 100644 --- a/bin/json/game_rdtaskcondi.json +++ b/bin/json/game_rdtaskcondi.json @@ -1690,7 +1690,7 @@ "valid": 0, "NPC": 10071, "data1": 1, - "data2": 1001, + "data2": 1, "data3": 1, "data4": 0, "data5": 0 @@ -1754,7 +1754,7 @@ "valid": 0, "NPC": 70022, "data1": 1, - "data2": 1001, + "data2": 1, "data3": 1, "data4": 0, "data5": 0 @@ -1770,7 +1770,7 @@ "valid": 0, "NPC": 70032, "data1": 1, - "data2": 1001, + "data2": 1, "data3": 1, "data4": 0, "data5": 0 From fcf0b3a048132bf960ad0d51befe3148f4a3d207 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 11 Apr 2023 17:37:18 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8E=89=E8=90=BD=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_lottery.json | 16 +-- comm/core.go | 11 ++ modules/comp_configure.go | 221 +++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+), 8 deletions(-) diff --git a/bin/json/game_lottery.json b/bin/json/game_lottery.json index d5bad4b39..4462598f0 100644 --- a/bin/json/game_lottery.json +++ b/bin/json/game_lottery.json @@ -124,10 +124,10 @@ "lotteryid": 40001001, "description": "随机蓝色英雄", "type": 0, - "groupwt": 0, - "groupid": 1001, - "subtype": 0, - "groupnum": 0, + "groupwt": 500, + "groupid": 1002, + "subtype": 2, + "groupnum": 1, "itemid": { "a": "item", "t": "132005", @@ -149,7 +149,7 @@ "description": "随机蓝色英雄", "type": 0, "groupwt": 0, - "groupid": 1001, + "groupid": 1002, "subtype": 0, "groupnum": 0, "itemid": { @@ -173,7 +173,7 @@ "description": "随机蓝色英雄", "type": 0, "groupwt": 0, - "groupid": 1001, + "groupid": 1002, "subtype": 0, "groupnum": 0, "itemid": { @@ -197,7 +197,7 @@ "description": "随机蓝色英雄", "type": 0, "groupwt": 0, - "groupid": 1001, + "groupid": 1002, "subtype": 0, "groupnum": 0, "itemid": { @@ -221,7 +221,7 @@ "description": "随机蓝色英雄", "type": 0, "groupwt": 0, - "groupid": 1001, + "groupid": 1002, "subtype": 0, "groupnum": 0, "itemid": { diff --git a/comm/core.go b/comm/core.go index 28766795c..95b10b121 100644 --- a/comm/core.go +++ b/comm/core.go @@ -108,6 +108,17 @@ func GetRandW(sz []int32) int32 { return 0 } +func GetRandNum(min, max int32) int32 { + if max < min { + return 0 + } + if max == min { + return min + } + n, _ := rand.Int(rand.Reader, big.NewInt(int64(max-min))) + return int32(n.Int64()) + min +} + ///通过uid获取用户所在区服 func UidToSTag(uid string) (stag string, err error) { s := strings.SplitN(uid, "_", 2) diff --git a/modules/comp_configure.go b/modules/comp_configure.go index 8f32696d4..292d133ab 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -28,6 +28,8 @@ const ( game_vip = "game_vip.json" game_equip = "game_equip.json" //装备信息表 + + game_lottery = "game_lottery.json" ) ///配置管理基础组件 @@ -36,6 +38,22 @@ type MCompConfigure struct { hlock sync.RWMutex _dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId _sign map[int32]*cfg.GameSignData + + _group map[int64][]int32 // key 小组ID value cid + + // 类型为1 的数据 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组 + _lotteryType1 map[int32][]int32 // key 大组ID value cid + // 类型为2 的数据 有多个小组ID + _lotteryType2 map[int32][]int32 // key 大组ID value 小组ID + + // 小组类型为1 + _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 // 小组产出数量 } //组件初始化接口 @@ -52,13 +70,207 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com //err = this.LoadConfigure(game_sign, cfg.NewGameSign) err = this.LoadConfigure(game_item, cfg.NewGameItem) err = this.LoadConfigure(game_vip, cfg.NewGameVip) + err = this.LoadConfigure(game_lottery, cfg.NewGameLottery) this._dropMap = make(map[int32][]*cfg.GameDropData, 0) this._sign = make(map[int32]*cfg.GameSignData, 0) configure.RegisterConfigure(game_drop, cfg.NewGameDrop, this.LoadDropData) configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData) + this._group = make(map[int64][]int32, 0) + this._lotteryType1 = make(map[int32][]int32, 0) + 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.Stype = make(map[int64]int32, 0) + this.SNum = make(map[int64]int32, 0) + configure.RegisterConfigure(game_lottery, cfg.NewGameLottery, this.LoadGroupData) + return } + +func (this *MCompConfigure) LoadGroupData() { + if v, err := this.GetConfigure(game_lottery); err == nil { + if configure, ok := v.(*cfg.GameLottery); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + this._group = make(map[int64][]int32, 0) + this._lotteryType1 = make(map[int32][]int32, 0) + 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.Stype = make(map[int64]int32, 0) + this.SNum = make(map[int64]int32, 0) + for _, value := range configure.GetDataList() { + key := int64(value.Lotteryid)<<31 + int64(value.Groupid) + this._group[key] = append(this._group[key], value.Id) + + 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.Groupid], value.Id) + } else if this.Btype[value.Lotteryid] == 2 { + this._lotteryType2[value.Groupid] = append(this._lotteryType2[value.Groupid], value.Id) + } + + if this.Stype[key] == 1 { // 小组ID为1 + this._groupType1[key] = append(this._groupType1[key], value.Id) + } else if this.Stype[key] == 2 { + this._groupType2[key] = append(this._groupType2[key], value.Id) + } + } + return + } + } else { + log.Errorf("get LoadGroupData conf err:%v", err) + } + return +} +func (this *MCompConfigure) GetGroupConf(lotterId int32, group int32) (conf *cfg.GameLotteryData) { + key := int64(lotterId)<<31 + int64(group) + return this.GetLotterConfById(this._group[key][0]) +} + +// 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具) +func (this *MCompConfigure) GetGroupData(lotterId int32, vipLv int32, lv int32) (items []*cfg.Gameatn) { + // 优先校验大组ID 的类型 + if this.Btype[lotterId] == 1 { // 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组 + var ( + szW []int32 // 权重数组 + szID []int32 // 小组ID 数组 + groupID int32 + ) + + var gourp map[int32]int32 // key 小组ID value 权重 + gourp = make(map[int32]int32, 0) + // 随机小组id + for _, v := range this._lotteryType1[lotterId] { + if _data := this.GetLotterConfById(v); _data != nil { + if (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax) && (_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(szW, _data.Groupid) + } + } + } + } + + groupID = szID[comm.GetRandW(szW)] // 获得小组ID + fmt.Printf("获得小组ID :%d", groupID) + key := int64(lotterId)<<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(szW, _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 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比) + 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, // 小组产出数量 + }) + } + } + } + return + } + } else if this.Btype[lotterId] == 2 { // 该大组中的小组为概率掉落,每个小组都会随机一次是否会掉落(单位为千分比) + // 每个小组id 都随机取一次 + var szGroupID []int32 // 获得的权重数组 + gourp := make(map[int32]*cfg.GameLotteryData, 0) // key 小组ID value 权重 + for _, v := range this._lotteryType2[lotterId] { + if _data := this.GetLotterConfById(v); _data != nil { + if (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax) && (_data.VIPmin <= vipLv && vipLv <= _data.VIPmax) { // 过滤等级等条件 + if _, ok := gourp[_data.Groupid]; !ok { + gourp[_data.Groupid] = _data // 小组ID 权重赋值 + } + } + } + } + // 类型为2 可能会同时获得多个组id + for k, v := range gourp { + if v.Itemwt >= comm.GetRandNum(0, 1000) { // 命中 + szGroupID = append(szGroupID, k) + key := int64(lotterId)<<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(szW, _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 { + 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, // 小组产出数量 + }) + } + } + } + } + } + } + } + return +} + func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) { return configure.RegisterConfigure(name, fn, nil) } @@ -396,3 +608,12 @@ func (this *MCompConfigure) GetAllEquipmentConfigure() (configure []*cfg.GameEqu } return } + +func (this *MCompConfigure) GetLotterConfById(id int32) (data *cfg.GameLotteryData) { + if v, err := this.GetConfigure(game_lottery); err == nil { + if configure, ok := v.(*cfg.GameLottery); ok { + return configure.Get(id) + } + } + return +} From e872169e3b692280f3777bc059609d6f3788ec2a Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 11 Apr 2023 19:02:53 +0800 Subject: [PATCH 4/4] =?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/comp_configure.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/modules/comp_configure.go b/modules/comp_configure.go index 292d133ab..96ab82203 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -45,15 +45,13 @@ type MCompConfigure struct { _lotteryType1 map[int32][]int32 // key 大组ID value cid // 类型为2 的数据 有多个小组ID _lotteryType2 map[int32][]int32 // key 大组ID value 小组ID - // 小组类型为1 _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 // 小组产出数量 } //组件初始化接口 @@ -85,7 +83,8 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com this.Stype = make(map[int64]int32, 0) this.SNum = make(map[int64]int32, 0) configure.RegisterConfigure(game_lottery, cfg.NewGameLottery, this.LoadGroupData) - + _d := this.GetGroupData(40001001, 1, 1) + fmt.Printf("%v", _d) return } @@ -117,9 +116,9 @@ func (this *MCompConfigure) LoadGroupData() { this.SNum[key] = value.Groupnum } if this.Btype[value.Lotteryid] == 1 { - this._lotteryType1[value.Lotteryid] = append(this._lotteryType1[value.Groupid], value.Id) + this._lotteryType1[value.Lotteryid] = append(this._lotteryType1[value.Lotteryid], value.Id) } else if this.Btype[value.Lotteryid] == 2 { - this._lotteryType2[value.Groupid] = append(this._lotteryType2[value.Groupid], value.Id) + this._lotteryType2[value.Lotteryid] = append(this._lotteryType2[value.Lotteryid], value.Id) } if this.Stype[key] == 1 { // 小组ID为1 @@ -135,10 +134,6 @@ func (this *MCompConfigure) LoadGroupData() { } return } -func (this *MCompConfigure) GetGroupConf(lotterId int32, group int32) (conf *cfg.GameLotteryData) { - key := int64(lotterId)<<31 + int64(group) - return this.GetLotterConfById(this._group[key][0]) -} // 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具) func (this *MCompConfigure) GetGroupData(lotterId int32, vipLv int32, lv int32) (items []*cfg.Gameatn) { @@ -148,18 +143,18 @@ func (this *MCompConfigure) GetGroupData(lotterId int32, vipLv int32, lv int32) szW []int32 // 权重数组 szID []int32 // 小组ID 数组 groupID int32 + gourp map[int32]int32 // key 小组ID value 权重 ) - var gourp map[int32]int32 // key 小组ID value 权重 gourp = make(map[int32]int32, 0) // 随机小组id for _, v := range this._lotteryType1[lotterId] { if _data := this.GetLotterConfById(v); _data != nil { - if (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax) && (_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) { // 过滤等级等条件 if _, ok := gourp[_data.Groupid]; !ok { gourp[_data.Groupid] = _data.Groupwt // 小组ID 权重赋值 szW = append(szW, _data.Groupwt) - szID = append(szW, _data.Groupid) + szID = append(szID, _data.Groupid) } } } @@ -178,7 +173,7 @@ func (this *MCompConfigure) GetGroupData(lotterId int32, vipLv int32, lv int32) if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 if _, ok := gourp[_data.Groupid]; !ok { szW = append(szW, _data.Itemwt) - szID = append(szW, _data.Id) + szID = append(szID, _data.Id) } } } @@ -215,7 +210,7 @@ func (this *MCompConfigure) GetGroupData(lotterId int32, vipLv int32, lv int32) gourp := make(map[int32]*cfg.GameLotteryData, 0) // key 小组ID value 权重 for _, v := range this._lotteryType2[lotterId] { if _data := this.GetLotterConfById(v); _data != nil { - if (_data.Playerlvmin <= lv && lv <= _data.Playerlvmax) && (_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) { // 过滤等级等条件 if _, ok := gourp[_data.Groupid]; !ok { gourp[_data.Groupid] = _data // 小组ID 权重赋值 } @@ -236,7 +231,7 @@ func (this *MCompConfigure) GetGroupData(lotterId int32, vipLv int32, lv int32) if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 if _, ok := gourp[_data.Groupid]; !ok { szW = append(szW, _data.Itemwt) - szID = append(szW, _data.Id) + szID = append(szID, _data.Id) } } }