秘境掉落事件配置解析

This commit is contained in:
meixiongfeng 2023-10-08 18:55:11 +08:00
parent cce089ca57
commit 823cd28c99
2 changed files with 135 additions and 161 deletions

View File

@ -54,18 +54,17 @@ type configureComp struct {
StypeR map[int64]int32 // subtype
SNumR map[int64]int32 // 小组产出数量
// event 随机
_groupE map[int64][]int32 // key 小组ID value cid
// 类型为1 的数据 该大组中的小组为权重掉落必定从N个小组中随机出1个小组
_lotteryType1E map[int32][]int32 // key 大组ID value cid
_lotteryTypeE map[int32][]*cfg.GameEventlotteryData // key 大组ID value cid
// 类型为2 的数据 有多个小组ID
_lotteryType2E map[int32][]int32 // key 大组ID value 小组ID
_lotteryType2E map[int32][]*cfg.GameEventlotteryData // key 大组ID value 小组ID
// 小组类型为1
_groupType1E map[int64][]int32 //value cid
_groupType1E map[int64][]*cfg.GameEventlotteryData //value cid
// 小组类型为2
_groupType2E map[int64][]int32 //value cid
StypeE map[int64]int32 // subtype
SNumE map[int64]int32 // 小组产出数量
_groupType2E map[int64][]*cfg.GameEventlotteryData //value cid
//Btype map[int32]int32
StypeE map[int64]int32 // subtype
SNumE map[int64]int32 // 小组产出数量
// buff 随机
buffLottery map[int32]map[int32]*cfg.GameBufflotteryData
@ -110,194 +109,63 @@ func (this *configureComp) LoadEventGroupData() {
if configure, ok := v.(*cfg.GameEventlottery); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
this._groupE = make(map[int64][]int32, 0)
this._lotteryType1E = make(map[int32][]int32, 0)
this._lotteryType2E = make(map[int32][]int32, 0)
this._groupType1E = make(map[int64][]int32, 0)
this._groupType2E = make(map[int64][]int32, 0)
this._lotteryTypeE = make(map[int32][]*cfg.GameEventlotteryData, 0)
this._lotteryType2E = make(map[int32][]*cfg.GameEventlotteryData, 0)
this._groupType1E = make(map[int64][]*cfg.GameEventlotteryData, 0)
this._groupType2E = make(map[int64][]*cfg.GameEventlotteryData, 0)
//this.Btype = make(map[int32]int32, 0)
this.StypeE = make(map[int64]int32, 0)
this.SNumE = 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._groupE[key] = append(this._groupE[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.StypeE[key]; !ok {
this.StypeE[key] = value.SubGroupType
this.StypeE[key] = value.GroupType
}
if _, ok := this.SNumE[key]; !ok {
this.SNumE[key] = value.SubGroupNum
this.SNumE[key] = value.SubGroupNum //value.Groupnum
}
if value.GroupType == 1 {
if tmp1 != key {
this._lotteryType1E[value.GroupId] = append(this._lotteryType1E[value.GroupId], value.Id)
tmp1 = key
}
this._lotteryTypeE[value.GroupId] = append(this._lotteryTypeE[value.GroupId], value)
}
if value.GroupType == 2 {
if tmp2 != key {
this._lotteryType2E[value.GroupId] = append(this._lotteryType2E[value.GroupId], value.Id)
tmp2 = key
}
this._lotteryType2E[value.GroupId] = append(this._lotteryType2E[value.GroupId], value)
}
if this.StypeE[key] == 1 { // 小组ID为1
this._groupType1E[key] = append(this._groupType1E[key], value.Id)
this._groupType1E[key] = append(this._groupType1E[key], value)
} else if this.StypeE[key] == 2 {
this._groupType2E[key] = append(this._groupType2E[key], value.Id)
this._groupType2E[key] = append(this._groupType2E[key], value)
}
}
return
}
} else {
log.Errorf("get NewGameBufflottery conf err:%v", err)
}
return
}
func (this *configureComp) GetEventLotterConfById(id int32) (data *cfg.GameEventlotteryData) {
if v, err := this.GetConfigure(game_eventlottery); err == nil {
if configure, ok := v.(*cfg.GameEventlottery); ok {
return configure.Get(id)
}
log.Errorf("get LoadGroupData conf err:%v", err)
}
return
}
// 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具)
func (this *configureComp) GetEventGroupDataByLottery(lotterys ...int32) (event []int32) {
for _, lotteryId := range lotterys {
if _, ok := this._lotteryType1E[lotteryId]; !ok {
if _, ok := this._lotteryType2E[lotteryId]; !ok {
this.module.Errorf("not found config lotterId:%d", lotteryId)
continue
}
}
// 优先校验大组ID 的类型
var (
szW []int32 // 权重数组
szID []int32 // 小组ID 数组
groupID int32
)
// 随机小组id
for _, v := range this._lotteryType1E[lotteryId] {
if _data := this.GetEventLotterConfById(v); _data != nil {
if _data.SubGroupId == 0 {
continue
}
szW = append(szW, _data.SubGroupWt)
szID = append(szID, _data.SubGroupId)
}
}
if len(szW) > 0 {
groupID = szID[comm.GetRandW(szW)] // 获得小组ID
//fmt.Printf("大组类型为1的,获得小组ID :%ddropID%d", groupID, lotteryId)
key := int64(lotteryId)<<31 + int64(groupID)
// 小组ID 类型判断
if this.StypeE[key] == 1 { // 该小组的道具为权重掉落必定从N个道具中随机出1个道具
for i := 0; i < int(this.SNumE[key]); i++ {
sztW := make([]int32, 0)
sztID := make([]int32, 0)
for _, v := range this._groupType1E[key] {
if _data := this.GetEventLotterConfById(v); _data != nil { // 权重赋值
sztW = append(sztW, _data.EventWt)
sztID = append(sztID, _data.Id)
}
}
index := comm.GetRandW(sztW)
_data := this.GetEventLotterConfById(sztID[index])
event = append(event, _data.EventID)
}
} else if this.StypeE[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
for _, v := range this._groupType2E[key] {
if _data := this.GetEventLotterConfById(v); _data != nil { // 权重赋值
if _data.EventID >= comm.GetRandNum(0, 1000) { // 命中
event = append(event, _data.EventID)
}
}
}
}
}
// 每个小组id 都随机取一次
szW = make([]int32, 0)
szID = make([]int32, 0)
for _, v := range this._lotteryType2E[lotteryId] {
if _data := this.GetEventLotterConfById(v); _data != nil {
if _data.SubGroupId == 0 {
continue
}
szW = append(szW, _data.SubGroupWt)
szID = append(szID, _data.SubGroupId)
}
}
// 类型为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.StypeE[key] == 1 { // 随机一组数据
for i := 0; i < int(this.SNumE[key]); i++ {
sztW := make([]int32, 0)
sztID := make([]int32, 0)
for _, v := range this._groupType1E[key] {
if _data := this.GetEventLotterConfById(v); _data != nil { // 权重赋值
sztW = append(sztW, _data.EventWt)
sztID = append(sztID, _data.Id)
}
}
index := comm.GetRandW(sztW)
_data := this.GetEventLotterConfById(sztID[index])
//fmt.Printf("获得最终的道具 :%d", _data.Id)
// 随机获得的数量
event = append(event, _data.EventID)
}
} else if this.StypeE[key] == 2 {
for _, v := range this._groupType2E[key] {
if _data := this.GetEventLotterConfById(v); _data != nil { // 权重赋值
if _data.EventWt >= comm.GetRandNum(1, 1000) { // 命中
event = append(event, _data.EventID)
}
}
}
}
}
}
}
return
}
func (this *configureComp) LoadRoomGroupData() {
if v, err := this.GetConfigure(game_roomlottery); err == nil {
if configure, ok := v.(*cfg.GameRoomlottery); ok {
@ -862,3 +730,109 @@ func (this *configureComp) getGameStonePrivilegeData(privilegeId int32) (conf *c
this.module.Errorln(err)
return
}
func (this *configureComp) GetEventLotterConfById(id int32) (data *cfg.GameEventlotteryData) {
if v, err := this.GetConfigure(game_eventlottery); err == nil {
if configure, ok := v.(*cfg.GameEventlottery); ok {
return configure.Get(id)
}
}
return
}
// 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具)
func (this *configureComp) GetEventGroupDataByLottery(lotterys ...int32) (event []int32) {
for _, lotteryId := range lotterys {
if _, ok := this._lotteryTypeE[lotteryId]; !ok {
if _, ok := this._lotteryType2E[lotteryId]; !ok {
//this.module.Errorf("not found config lotterId:%d", lotteryId)
return
}
}
// 优先校验大组ID 的类型
var (
szW []int32 // 权重数组
szID []int32 // 小组ID 数组
groupID int32
)
//this.module.Debugf("config lotterId:%d")
// 随机小组id
for _, _data := range this._lotteryTypeE[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
//fmt.Printf("大组类型为1的,获得小组ID :%ddropID%d", groupID, lotteryId)
key := int64(lotteryId)<<31 + int64(groupID)
// 小组ID 类型判断
if this.StypeE[key] == 1 { // 该小组的道具为权重掉落必定从N个道具中随机出1个道具
for i := 0; i < int(this.SNumE[key]); i++ {
sztW := make([]int32, 0)
sztID := make([]*cfg.GameEventlotteryData, 0)
for _, _data := range this._groupType1E[key] {
sztW = append(sztW, _data.SubGroupWt)
sztID = append(sztID, _data)
}
if len(sztW) == 0 {
continue
}
_data := sztID[comm.GetRandW(sztW)]
// 随机获得的数量
event = append(event, _data.EventID)
}
} else if this.StypeE[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
for _, _data := range this._groupType2E[key] {
if _data.EventWt >= comm.GetRandNum(0, 1000) { // 命中
event = append(event, _data.EventID)
}
}
}
}
// 每个小组id 都随机取一次
szW = make([]int32, 0)
szID = make([]int32, 0)
for _, _data := range this._lotteryType2E[lotteryId] {
if _data.SubGroupId != 0 {
szW = append(szW, _data.SubGroupWt)
szID = append(szID, _data.SubGroupId)
}
}
// 类型为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.StypeE[key] == 1 { // 随机一组数据
for i := 0; i < int(this.SNumE[key]); i++ {
sztW := make([]int32, 0)
sztID := make([]*cfg.GameEventlotteryData, 0)
for _, _data := range this._groupType1E[key] {
sztW = append(sztW, _data.EventWt)
sztID = append(sztID, _data)
}
if len(sztW) == 0 {
continue
}
_data := sztID[comm.GetRandW(sztW)]
event = append(event, _data.EventID)
}
} else if this.StypeE[key] == 2 {
for _, _data := range this._groupType2E[key] {
if _data.EventWt >= comm.GetRandNum(1, 1000) { // 命中
event = append(event, _data.EventID)
}
}
}
}
}
}
this.module.Debugf("drop event result:%v", event)
return
}

View File

@ -42,7 +42,7 @@ type MCompConfigure struct {
_dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId
_sign map[int32]*cfg.GameSignData
// 新掉落表
_group map[int64][]int32 // key 小组ID value cid
//_group map[int64][]int32 // key 小组ID value cid
// 类型为1 的数据 该大组中的小组为权重掉落必定从N个小组中随机出1个小组
_lotteryType1 map[int32][]*cfg.GameLotteryData // key 大组ID value cid
// 类型为2 的数据 有多个小组ID
@ -79,7 +79,7 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com
configure.RegisterConfigure(game_drop, cfg.NewGameDrop, this.LoadDropData)
configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData)
configure.RegisterConfigure(game_price, cfg.NewGamePricegroup, this.LoadPriceGroup)
this._group = make(map[int64][]int32, 0)
//this._group = make(map[int64][]int32, 0)
this._lotteryType1 = make(map[int32][]*cfg.GameLotteryData, 0)
this._lotteryType2 = make(map[int32][]*cfg.GameLotteryData, 0)
this._groupType1 = make(map[int64][]*cfg.GameLotteryData, 0)
@ -97,7 +97,7 @@ func (this *MCompConfigure) LoadGroupData() {
if configure, ok := v.(*cfg.GameLottery); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
this._group = make(map[int64][]int32, 0)
//this._group = make(map[int64][]int32, 0)
this._lotteryType1 = make(map[int32][]*cfg.GameLotteryData, 0)
this._lotteryType2 = make(map[int32][]*cfg.GameLotteryData, 0)
this._groupType1 = make(map[int64][]*cfg.GameLotteryData, 0)
@ -115,7 +115,7 @@ func (this *MCompConfigure) LoadGroupData() {
groupid = value.Groupid
}
key := int64(value.Lotteryid)<<31 + int64(value.Groupid)
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 {