diff --git a/modules/stonehenge/configure.go b/modules/stonehenge/configure.go index 7882507c1..0f8255397 100644 --- a/modules/stonehenge/configure.go +++ b/modules/stonehenge/configure.go @@ -41,15 +41,14 @@ type configureComp struct { // buff buff map[int32]map[int32]struct{} // key buff 类型 value buffid // 房间随机 - _groupR map[int64][]int32 // key 小组ID value cid // 类型为1 的数据 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组 - _lotteryType1R map[int32][]int32 // key 大组ID value cid + _lotteryTypeR map[int32][]*cfg.GameRoomlotteryData // key 大组ID value cid // 类型为2 的数据 有多个小组ID - _lotteryType2R map[int32][]int32 // key 大组ID value 小组ID + _lotteryType2R map[int32][]*cfg.GameRoomlotteryData // key 大组ID value 小组ID // 小组类型为1 - _groupType1R map[int64][]int32 //value cid + _groupType1R map[int64][]*cfg.GameRoomlotteryData //value cid // 小组类型为2 - _groupType2R map[int64][]int32 //value cid + _groupType2R map[int64][]*cfg.GameRoomlotteryData //value cid //Btype map[int32]int32 StypeR map[int64]int32 // subtype SNumR map[int64]int32 // 小组产出数量 @@ -101,6 +100,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp configure.RegisterConfigure(game_buffconf, cfg.NewGameStoneBuff, this.LoadGameStoneBuff) configure.RegisterConfigure(game_storyconf, cfg.NewGameStoneStory, this.LoadGameStoneStory) + this.GetRoomGroupDataByLottery(110100) return } @@ -171,89 +171,68 @@ func (this *configureComp) LoadRoomGroupData() { if configure, ok := v.(*cfg.GameRoomlottery); ok { this.hlock.Lock() defer this.hlock.Unlock() - this._groupR = make(map[int64][]int32, 0) - this._lotteryType1R = make(map[int32][]int32, 0) - this._lotteryType2R = make(map[int32][]int32, 0) - this._groupType1R = make(map[int64][]int32, 0) - this._groupType2R = make(map[int64][]int32, 0) + this._lotteryTypeR = make(map[int32][]*cfg.GameRoomlotteryData, 0) + this._lotteryType2R = make(map[int32][]*cfg.GameRoomlotteryData, 0) + this._groupType1R = make(map[int64][]*cfg.GameRoomlotteryData, 0) + this._groupType2R = make(map[int64][]*cfg.GameRoomlotteryData, 0) //this.Btype = make(map[int32]int32, 0) this.StypeR = make(map[int64]int32, 0) this.SNumR = make(map[int64]int32, 0) - var tmp1 int64 - var tmp2 int64 var itype int32 - var wt int32 - var subid int32 + var groupwt int32 + var groupid int32 for _, value := range configure.GetDataList() { if value.SubGroupId == 0 { - value.SubGroupId = subid + value.SubGroupId = groupid } else { - subid = value.SubGroupId + groupid = value.SubGroupId } key := int64(value.GroupId)<<31 + int64(value.SubGroupId) - // key2 := int64(value.Lotteryid)<<31 + int64(value.Type) - this._groupR[key] = append(this._groupR[key], value.Id) + if value.GroupType == 0 { value.GroupType = itype } else { itype = value.GroupType } if value.SubGroupWt == 0 { - value.SubGroupWt = wt + value.SubGroupWt = groupwt } else { - wt = value.SubGroupWt + groupwt = value.SubGroupWt } if _, ok := this.StypeR[key]; !ok { - this.StypeR[key] = value.SubGroupType + this.StypeR[key] = value.GroupType } if _, ok := this.SNumR[key]; !ok { - this.SNumR[key] = value.SubGroupNum + this.SNumR[key] = value.SubGroupNum //value.Groupnum } if value.GroupType == 1 { - if tmp1 != key { - this._lotteryType1R[value.GroupId] = append(this._lotteryType2R[value.GroupId], value.Id) - tmp1 = key - } + this._lotteryTypeR[value.GroupId] = append(this._lotteryTypeR[value.GroupId], value) } if value.GroupType == 2 { - if tmp2 != key { - this._lotteryType2R[value.GroupId] = append(this._lotteryType2R[value.GroupId], value.Id) - tmp2 = key - } + this._lotteryType2R[value.GroupId] = append(this._lotteryType2R[value.GroupId], value) } if this.StypeR[key] == 1 { // 小组ID为1 - this._groupType1R[key] = append(this._groupType1R[key], value.Id) + this._groupType1R[key] = append(this._groupType1R[key], value) } else if this.StypeR[key] == 2 { - this._groupType2R[key] = append(this._groupType2R[key], value.Id) + this._groupType2R[key] = append(this._groupType2R[key], value) } } return } } else { - log.Errorf("get NewGameBufflottery conf err:%v", err) - } - return -} -func (this *configureComp) GetRoomLotterConfById(id int32) (data *cfg.GameRoomlotteryData) { - - if v, err := this.GetConfigure(game_roomlottery); err == nil { - if configure, ok := v.(*cfg.GameRoomlottery); ok { - data = configure.Get(id) - return - } + log.Errorf("get LoadGroupData conf err:%v", err) } return } // 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具) func (this *configureComp) GetRoomGroupDataByLottery(lotteryId int32) (rooms []int32) { - - if _, ok := this._lotteryType1R[lotteryId]; !ok { + if _, ok := this._lotteryTypeR[lotteryId]; !ok { if _, ok := this._lotteryType2R[lotteryId]; !ok { - this.module.Errorf("not found config lotterId:%d", lotteryId) + //this.module.Errorf("not found config lotterId:%d", lotteryId) return } } @@ -263,16 +242,14 @@ func (this *configureComp) GetRoomGroupDataByLottery(lotteryId int32) (rooms []i szID []int32 // 小组ID 数组 groupID int32 ) - + //this.module.Debugf("config lotterId:%d") // 随机小组id - for _, v := range this._lotteryType1R[lotteryId] { - if _data := this.GetRoomLotterConfById(v); _data != nil { - if _data.SubGroupId == 0 { - continue - } + for _, _data := range this._lotteryTypeR[lotteryId] { + if _data.SubGroupId != 0 { szW = append(szW, _data.SubGroupWt) szID = append(szID, _data.SubGroupId) } + } if len(szW) > 0 { groupID = szID[comm.GetRandW(szW)] // 获得小组ID @@ -282,39 +259,32 @@ func (this *configureComp) GetRoomGroupDataByLottery(lotteryId int32) (rooms []i if this.StypeR[key] == 1 { // 该小组的道具为权重掉落,必定从N个道具中随机出1个道具 for i := 0; i < int(this.SNumR[key]); i++ { sztW := make([]int32, 0) - sztID := make([]int32, 0) - for _, v := range this._groupType1R[key] { - if _data := this.GetRoomLotterConfById(v); _data != nil { // 权重赋值 - sztW = append(sztW, _data.RoomWt) - sztID = append(sztID, _data.Id) - } + sztID := make([]*cfg.GameRoomlotteryData, 0) + for _, _data := range this._groupType1R[key] { + sztW = append(sztW, _data.SubGroupWt) + sztID = append(sztID, _data) } - index := comm.GetRandW(sztW) - _data := this.GetRoomLotterConfById(sztID[index]) + if len(sztW) == 0 { + continue + } + _data := sztID[comm.GetRandW(sztW)] + // 随机获得的数量 rooms = append(rooms, _data.RoomID) - } - } else if this.StypeR[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比) - for _, v := range this._groupType2R[key] { - if _data := this.GetRoomLotterConfById(v); _data != nil { // 权重赋值 - - if _data.RoomWt >= comm.GetRandNum(0, 1000) { // 命中 - rooms = append(rooms, _data.RoomID) - } + for _, _data := range this._groupType2R[key] { + if _data.RoomWt >= comm.GetRandNum(0, 1000) { // 命中 + rooms = append(rooms, _data.RoomID) } } - } } + // 每个小组id 都随机取一次 szW = make([]int32, 0) szID = make([]int32, 0) - for _, v := range this._lotteryType2R[lotteryId] { - if _data := this.GetRoomLotterConfById(v); _data != nil { - if _data.SubGroupId == 0 { - continue - } + for _, _data := range this._lotteryType2R[lotteryId] { + if _data.SubGroupId != 0 { szW = append(szW, _data.SubGroupWt) szID = append(szID, _data.SubGroupId) } @@ -328,31 +298,27 @@ func (this *configureComp) GetRoomGroupDataByLottery(lotteryId int32) (rooms []i if this.StypeR[key] == 1 { // 随机一组数据 for i := 0; i < int(this.SNumR[key]); i++ { sztW := make([]int32, 0) - sztID := make([]int32, 0) - for _, v := range this._groupType1R[key] { - if _data := this.GetRoomLotterConfById(v); _data != nil { // 权重赋值 - sztW = append(sztW, _data.RoomWt) - sztID = append(sztID, _data.Id) - } + sztID := make([]*cfg.GameRoomlotteryData, 0) + for _, _data := range this._groupType1R[key] { + sztW = append(sztW, _data.RoomWt) + sztID = append(sztID, _data) } - index := comm.GetRandW(sztW) - _data := this.GetRoomLotterConfById(sztID[index]) - //fmt.Printf("获得最终的道具 :%d", _data.Id) - // 随机获得的数量 + if len(sztW) == 0 { + continue + } + _data := sztID[comm.GetRandW(sztW)] rooms = append(rooms, _data.RoomID) } } else if this.StypeR[key] == 2 { - for _, v := range this._groupType2R[key] { - if _data := this.GetRoomLotterConfById(v); _data != nil { // 权重赋值 - - if _data.RoomWt >= comm.GetRandNum(1, 1000) { // 命中 - rooms = append(rooms, _data.RoomID) - } + for _, _data := range this._groupType2R[key] { + if _data.RoomWt >= comm.GetRandNum(1, 1000) { // 命中 + rooms = append(rooms, _data.RoomID) } } } } } + this.module.Debugf("drop rooms result:%v", rooms) return }