This commit is contained in:
meixiongfeng 2023-08-11 20:43:34 +08:00
commit a956ac7d94
4 changed files with 352 additions and 187 deletions

View File

@ -1,57 +1,34 @@
[
{
"key": 0,
"show": [
{
"a": "attr",
"t": "gold",
"n": 1
},
{
"a": "attr",
"t": "diamond",
"n": 1
}
]
},
{
"key": 1001,
"show": [
{
"show": {
"a": "item",
"t": "23000001",
"n": 0
}
]
},
{
"key": 1003,
"show": [
{
"show": {
"a": "item",
"t": "23000002",
"n": 0
}
]
},
{
"key": 1004,
"show": [
{
"show": {
"a": "item",
"t": "23000003",
"n": 0
}
]
},
{
"key": 1005,
"show": [
{
"show": {
"a": "item",
"t": "23000004",
"n": 0
}
]
}
]

View File

@ -567,6 +567,11 @@ func (this *Buried) trigger(session comm.IUserSession, burieds ...*pb.BuriedPara
}
notify[mname] = append(notify[mname], cp)
}
} else {
if _, ok = notify[string(comm.ModuleWtask)]; !ok {
notify[string(comm.ModuleWtask)] = make([]*pb.ConIProgress, 0)
}
notify[string(comm.ModuleWtask)] = append(notify[string(comm.ModuleWtask)], cp)
}
}
@ -593,11 +598,9 @@ func (this *Buried) trigger(session comm.IUserSession, burieds ...*pb.BuriedPara
//异步通知指定模块
nmodule.BuriedsNotify(session, v)
}
} else {
this.wtask.BuriedsNotify(session, changes)
this.smithy.BuriedsNotify(session, changes)
// this.sociaty.BuriedsNotify(session, changes)
}
// this.wtask.BuriedsNotify(session, changes)
// this.smithy.BuriedsNotify(session, changes)
}
// 更新并校验完成

View File

@ -17,6 +17,7 @@ import (
"go_dreamfactory/pb"
"go_dreamfactory/services"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
"os"
@ -75,6 +76,11 @@ func GetMonthStartEnd() (int64, int64) {
fmt.Printf("%d,%d", _d1, _d2)
return _d1, _d2
}
const (
game_lottery = "game_lottery.json"
)
func TimerStar() {
//star := configure.Now()
@ -112,8 +118,185 @@ type sumy struct {
next *sumy
}
func Test_Main(t *testing.T) {
var (
// 新掉落表
_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 // 小组产出数量
)
func GetConfigure(name string) (v interface{}, err error) {
return configure.GetConfigure(name)
}
func GetLotterConfById(id int32) (data *cfg.GameLotteryData) {
if v, err := GetConfigure(game_lottery); err == nil {
if configure, ok := v.(*cfg.GameLottery); ok {
return configure.Get(id)
}
}
return
}
func GetGroupDataByLottery(lotteryId int32) (items []*cfg.Gameatn) {
if _, ok := _lotteryType1[lotteryId]; !ok {
if _, ok := _lotteryType2[lotteryId]; !ok {
fmt.Printf("not found config lotterId:%d", lotteryId)
return
}
}
// 优先校验大组ID 的类型
//if this.Btype[lotteryId] == 1 { // 该大组中的小组为权重掉落必定从N个小组中随机出1个小组
var (
szW []int32 // 权重数组
szID []int32 // 小组ID 数组
groupID int32
gourp map[int32]int32 // key 小组ID value 权重
)
gourp = make(map[int32]int32, 0)
// 随机小组id
for _, v := range _lotteryType1[lotteryId] {
if _data := GetLotterConfById(v); _data != nil {
if _, ok := gourp[_data.Groupid]; !ok {
gourp[_data.Groupid] = _data.Groupwt // 小组ID 权重赋值
szW = append(szW, _data.Groupwt)
szID = append(szID, _data.Groupid)
}
}
}
groupID = szID[comm.GetRandW(szW)] // 获得小组ID
//fmt.Printf("大组类型为1的,获得小组ID :%ddropID%d", groupID, lotteryId)
key := int64(lotteryId)<<31 + int64(groupID)
// 小组ID 类型判断
if Stype[key] == 1 { // 该小组的道具为权重掉落必定从N个道具中随机出1个道具
for i := 0; i < int(SNum[key]); i++ {
szW = make([]int32, 0)
szID = make([]int32, 0)
gourp = make(map[int32]int32, 0)
for _, v := range _groupType1[key] {
if _data := 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 := 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 Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
var wt int32
for _, v := range _groupType2[key] {
if _data := 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, // 小组产出数量
})
}
}
}
}
//}
//if this.Btype[lotteryId] == 2 { // 该大组中的小组为概率掉落,每个小组都会随机一次是否会掉落(单位为千分比)
// 每个小组id 都随机取一次
var szGroupID []int32 // 获得的权重数组
gourp1 := make([]*cfg.GameLotteryData, 0) // key 小组ID value 权重
for _, v := range _lotteryType2[lotteryId] {
if _data := GetLotterConfById(v); _data != nil {
gourp1 = append(gourp1, _data)
}
}
// 过滤 group
var wt int32
// 类型为2 可能会同时获得多个组id
for _, v := range gourp1 {
k := v.Groupid
if v.Groupwt != 0 {
wt = v.Groupwt
}
//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 Stype[key] == 1 { // 随机一组数据
for i := 0; i < int(SNum[key]); i++ {
szW := make([]int32, 0)
szID := make([]int32, 0)
gourp := make(map[int32]int32, 0)
for _, v := range _groupType1[key] {
if _data := 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 := 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 Stype[key] == 2 {
var wt int32
for _, v := range _groupType2[key] {
if _data := 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, // 小组产出数量
})
}
}
}
}
}
}
//}
return
}
func LoadConfigure(name string, fn interface{}) (err error) {
return configure.RegisterConfigure(name, fn, nil)
}
func Test_Main(t *testing.T) {
LoadConfigure(game_lottery, cfg.NewGameLottery)
GetGroupDataByLottery(1001)
value, err := strconv.Atoi("944005411")
fmt.Printf("%v,%v,%d", value, err, utils.WeekIntervalTime())
ids := utils.RandomNumbers(0, 10, 5)

View File

@ -51,7 +51,7 @@ type MCompConfigure struct {
_groupType1 map[int64][]int32 //value cid
// 小组类型为2
_groupType2 map[int64][]int32 //value cid
Btype map[int32]int32
//Btype map[int32]int32
Stype map[int64]int32 // subtype
SNum map[int64]int32 // 小组产出数量
@ -84,11 +84,13 @@ 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)
this.GetGroupDataByLottery(40001001, 0, 1)
this.GetGroupDataByLottery(1001, 0, 1)
return
}
@ -102,14 +104,20 @@ 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 tmp 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)
@ -124,26 +132,20 @@ 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 {
if tmp != key {
if value.Type == 1 || value.Type == 0 {
this._lotteryType1[value.Lotteryid] = append(this._lotteryType1[value.Lotteryid], value.Id)
tmp = key
}
} else if this.Btype[value.Lotteryid] == 2 {
if tmp != key {
if value.Type == 2 || value.Type == 0 {
this._lotteryType2[value.Lotteryid] = append(this._lotteryType2[value.Lotteryid], value.Id)
tmp = key
}
}
if this.Stype[key] == 1 { // 小组ID为1
@ -170,7 +172,7 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
}
}
// 优先校验大组ID 的类型
if this.Btype[lotteryId] == 1 { // 该大组中的小组为权重掉落必定从N个小组中随机出1个小组
//if this.Btype[lotteryId] == 1 { // 该大组中的小组为权重掉落必定从N个小组中随机出1个小组
var (
szW []int32 // 权重数组
szID []int32 // 小组ID 数组
@ -220,7 +222,7 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
N: _data.Itemid.N * count,
})
}
return
} else if this.Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
var wt int32
for _, v := range this._groupType2[key] {
@ -238,24 +240,24 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
}
}
}
return
}
}
if this.Btype[lotteryId] == 2 { // 该大组中的小组为概率掉落,每个小组都会随机一次是否会掉落(单位为千分比)
//}
//if this.Btype[lotteryId] == 2 { // 该大组中的小组为概率掉落,每个小组都会随机一次是否会掉落(单位为千分比)
// 每个小组id 都随机取一次
var szGroupID []int32 // 获得的权重数组
gourp := make([]*cfg.GameLotteryData, 0) // key 小组ID value 权重
gourp1 := 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)
gourp1 = append(gourp1, _data)
}
}
}
// 过滤 group
var wt int32
// 类型为2 可能会同时获得多个组id
for _, v := range gourp {
for _, v := range gourp1 {
k := v.Groupid
if v.Groupwt != 0 {
wt = v.Groupwt
@ -308,7 +310,7 @@ func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32,
}
}
}
}
//}
return
}