add 推币机转盘水池

This commit is contained in:
sk 2025-01-16 17:06:05 +08:00
parent 4c7c2dc287
commit 7b19859179
14 changed files with 2114 additions and 1639 deletions

View File

@ -1,11 +1,12 @@
 в† ЁГ иб†
ив† о±к
Р† фв†
Вв†  Ќ  в†
Ь ±к ђN иа†
о±к Р† ив†
ъўЌ  Ќ
иб† Р† Ь ±к
а† °к ъўЌ
 d»к ЂВЧ/
 жЩ

View File

@ -2,75 +2,65 @@
"Arr": [ "Arr": [
{ {
"Id": 1, "Id": 1,
"Rate": 4000,
"Gain": {
"50018": 5
},
"Value": 25000
},
{
"Id": 2,
"Rate": 1000,
"Gain": {
"50018": 10
},
"Value": 50000
},
{
"Id": 3,
"Rate": 450,
"Gain": {
"50018": 20
},
"Value": 100000
},
{
"Id": 4,
"Rate": 1500,
"Gain": {
"30001": 1
},
"Value": 10000
},
{
"Id": 5,
"Rate": 750,
"Gain": {
"30001": 5
},
"Value": 50000
},
{
"Id": 6,
"Rate": 250,
"Gain": {
"100002": 1
},
"Value": 100000
},
{
"Id": 7,
"Rate": 1000, "Rate": 1000,
"Gain": { "Gain": {
"50017": 1 "50017": 1
}
}, },
"Value": 50000 {
"Id": 2,
"Rate": 750,
"Gain": {
"30001": 5
}
},
{
"Id": 3,
"Rate": 500,
"Gain": {
"50018": 20
}
},
{
"Id": 4,
"Rate": 4000,
"Gain": {
"50018": 5
}
},
{
"Id": 5,
"Rate": 1000,
"Gain": {
"50016": 1
}
},
{
"Id": 6,
"Rate": 1000,
"Gain": {
"50018": 10
}
},
{
"Id": 7,
"Rate": 1500,
"Gain": {
"30001": 1
}
}, },
{ {
"Id": 8, "Id": 8,
"Rate": 950, "Rate": 250,
"Gain": { "Gain": {
"50016": 1 "100002": 1
}, }
"Value": 30000
}, },
{ {
"Id": 9, "Id": 9,
"Rate": 100,
"Gain": { "Gain": {
"30011": 1 "77030": 1
}, }
"Value": 100000000
} }
] ]
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -564,6 +564,9 @@ type PushCoinData struct {
Exchange map[int32]int32 // 兑换次数 兑换id:兑换次数 Exchange map[int32]int32 // 兑换次数 兑换id:兑换次数
Dram int // 抽奖次数 Dram int // 抽奖次数
Items map[int32]int64 // 道具 Items map[int32]int64 // 道具
Turn []int32 // 转盘
Next int32 // 下次中奖位置
PoolV []int64 // 奖池
} }
type WelfareData struct { type WelfareData struct {

View File

@ -474,7 +474,7 @@ type DrawInfo struct {
Id int32 `protobuf:"varint,1,opt,name=Id,proto3" json:"Id,omitempty"` //抽奖id Id int32 `protobuf:"varint,1,opt,name=Id,proto3" json:"Id,omitempty"` //抽奖id
ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //道具id ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //道具id
ItemNum int32 `protobuf:"varint,3,opt,name=ItemNum,proto3" json:"ItemNum,omitempty"` //道具数量 ItemNum int64 `protobuf:"varint,3,opt,name=ItemNum,proto3" json:"ItemNum,omitempty"` //道具数量
} }
func (x *DrawInfo) Reset() { func (x *DrawInfo) Reset() {
@ -523,7 +523,7 @@ func (x *DrawInfo) GetItemId() int32 {
return 0 return 0
} }
func (x *DrawInfo) GetItemNum() int32 { func (x *DrawInfo) GetItemNum() int64 {
if x != nil { if x != nil {
return x.ItemNum return x.ItemNum
} }
@ -825,7 +825,7 @@ var file_protocol_activity_pushcoin_proto_rawDesc = []byte{
0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x64, 0x12, 0x16,
0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x49, 0x74, 0x65, 0x6d, 0x4e, 0x75, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x49, 0x74, 0x65, 0x6d, 0x4e, 0x75,
0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x49, 0x74, 0x65, 0x6d, 0x4e, 0x75, 0x6d, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x49, 0x74, 0x65, 0x6d, 0x4e, 0x75, 0x6d,
0x22, 0x60, 0x0a, 0x0e, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x44, 0x72, 0x61, 0x77, 0x49, 0x6e, 0x22, 0x60, 0x0a, 0x0e, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x44, 0x72, 0x61, 0x77, 0x49, 0x6e,
0x66, 0x6f, 0x12, 0x26, 0x0a, 0x04, 0x44, 0x72, 0x61, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x66, 0x6f, 0x12, 0x26, 0x0a, 0x04, 0x44, 0x72, 0x61, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x12, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e, 0x44, 0x72, 0x61, 0x77, 0x32, 0x12, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e, 0x44, 0x72, 0x61, 0x77,

View File

@ -43,7 +43,7 @@ message ExchangeInfo{
message DrawInfo{ message DrawInfo{
int32 Id = 1; //id int32 Id = 1; //id
int32 ItemId = 2; //id int32 ItemId = 2; //id
int32 ItemNum = 3; // int64 ItemNum = 3; //
} }
// //

File diff suppressed because it is too large Load Diff

View File

@ -13,8 +13,6 @@ message DB_ACTPushCoin {
map<int64, int64> Gain = 3; map<int64, int64> Gain = 3;
int64 Value = 4;
} }
message DB_ACTPushCoinArray { message DB_ACTPushCoinArray {

View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"slices"
"sort" "sort"
"time"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/netlib"
@ -9,19 +11,19 @@ import (
"mongo.games.com/game/common" "mongo.games.com/game/common"
"mongo.games.com/game/model" "mongo.games.com/game/model"
"mongo.games.com/game/protocol/activity" "mongo.games.com/game/protocol/activity"
"mongo.games.com/game/protocol/webapi"
"mongo.games.com/game/srvdata" "mongo.games.com/game/srvdata"
) )
const ( const (
PowerMax = 700000 PowerMax = 50000
PowerInit = 400000 PowerInit = 0
) )
var PushCoinItemValue = map[int32]int64{ var PushCoinItemValue = map[int32]int64{
common.ItemIDBigCoin: 50000, common.ItemIDBigCoin: 50000,
common.ItemIDVCard: 10000, common.ItemIDVCard: 10000,
common.ItemIDPlum: 30000, common.ItemIDPlum: 30000,
30011: 100000000, // 话费卡
common.ItemIDCoin1: 5000, common.ItemIDCoin1: 5000,
common.ItemIDCoin2: 10000, common.ItemIDCoin2: 10000,
common.ItemIDCoin3: 15000, common.ItemIDCoin3: 15000,
@ -52,7 +54,7 @@ func CSPushCoinInfo(s *netlib.Session, packetid int, data interface{}, sid int64
return nil return nil
} }
if p.WelfData.PushCoin == nil { if p.WelfData.PushCoin == nil || len(p.WelfData.PushCoin.Turn) == 0 {
InitPlayerPushCoin(p) InitPlayerPushCoin(p)
} }
@ -105,14 +107,73 @@ func CSPushCoinInfo(s *netlib.Session, packetid int, data interface{}, sid int64
} }
} }
// 转盘 pack.DrawList = make([]*activity.DrawInfo, len(p.WelfData.PushCoin.Turn))
for _, v := range srvdata.PBDB_ACTPushCoinMgr.Datas.Arr {
for kk, vv := range v.GetGain() { for k, v := range p.WelfData.PushCoin.Turn {
pack.DrawList = append(pack.DrawList, &activity.DrawInfo{ info := &activity.DrawInfo{
Id: v.GetId(), Id: int32(k),
ItemId: int32(kk), }
ItemNum: int32(vv),
}) // 默认奖励
if slices.Contains(NormaIndex, k) {
d := srvdata.PBDB_ACTPushCoinMgr.GetData(v)
if d != nil {
for kk, vv := range d.GetGain() {
info.ItemId = int32(kk)
info.ItemNum = vv
break
}
pack.DrawList[k] = info
}
continue
}
// 奖池
if slices.Contains(PoolIndex, k) {
ii := slices.Index(PoolIndex, k)
if v == -1 {
// 从奖池中随机
var element *webapi.PushCoinPoolElement
var index int32
cfg := WelfareMgrSington.GetConfig(p.Platform).PushCoinConfig
if ii == 0 {
element, index = PushCoinPoolRandom(cfg.GetPool1().GetPool())
} else if ii == 1 {
element, index = PushCoinPoolRandom(cfg.GetPool2().GetPool())
} else if ii == 2 {
element, index = PushCoinPoolRandom(cfg.GetPool3().GetPool())
}
if index >= 0 && element != nil {
p.WelfData.PushCoin.Turn[k] = index
for _, v := range element.GetAward() {
info.ItemId = v.GetItemId()
info.ItemNum = v.GetItemNum()
break
}
pack.DrawList[k] = info
}
} else {
// 随机过了
f := func(index int, pool []*webapi.PushCoinPoolElement) {
if index < len(pool) {
for _, v := range pool[index].GetAward() {
info.ItemId = v.GetItemId()
info.ItemNum = v.GetItemNum()
break
}
pack.DrawList[k] = info
}
}
cfg := WelfareMgrSington.GetConfig(p.Platform).PushCoinConfig
if cfg != nil {
if ii == 0 {
f(int(v), cfg.GetPool1().GetPool())
} else if ii == 1 {
f(int(v), cfg.GetPool2().GetPool())
} else if ii == 2 {
f(int(v), cfg.GetPool3().GetPool())
}
}
}
} }
} }
@ -149,6 +210,18 @@ func CSPushCoinPlayerOp(s *netlib.Session, packetid int, data interface{}, sid i
return nil return nil
} }
// 活动时间检测
now := time.Now()
cfg := WelfareMgrSington.GetConfig(p.Platform).PushCoinConfig
if cfg == nil {
logger.Logger.Warn("CSPushCoinPlayerOp cfg == nil")
return nil
}
if cfg.GetOn() != common.On || now.Unix() < common.StrTimeToTs(cfg.GetStartTime()) || now.Unix() >= common.StrTimeToTs(cfg.GetEndTime()) {
logger.Logger.Warn("CSPushCoinPlayerOp cfg.GetOn() == common.Off or end")
return nil
}
pack := &activity.SCPushCoinPlayerOp{ pack := &activity.SCPushCoinPlayerOp{
OpRetCode: activity.OpResultPushCoinCode_OPRC_PushCoin_Error, OpRetCode: activity.OpResultPushCoinCode_OPRC_PushCoin_Error,
OpCode: msg.GetOpCode(), OpCode: msg.GetOpCode(),
@ -176,6 +249,8 @@ func CSPushCoinPlayerOp(s *netlib.Session, packetid int, data interface{}, sid i
PushCoinAddValue(p, map[int32]int64{ PushCoinAddValue(p, map[int32]int64{
int32(msg.GetOpParam()): 1, int32(msg.GetOpParam()): 1,
}) })
// 增加水池
PushCoinPoolMangerInstance.Add(p.Platform, item.GetNum())
case activity.OpCodes_OP_Gain: case activity.OpCodes_OP_Gain:
@ -209,12 +284,26 @@ func CSPushCoinPlayerOp(s *netlib.Session, packetid int, data interface{}, sid i
} }
} else { } else {
// 无效区 // 无效区
for _, v := range msg.GetOpItem() {
id := v.GetItemId()
val := v.GetItemNum()
if p.WelfData.PushCoin.Items[id] < val {
logger.Logger.Errorf("获得道具太多,无效区: %d, %d", p.WelfData.PushCoin.Items[id], val)
goto here
}
}
} }
for _, v := range msg.GetOpItem() { for _, v := range msg.GetOpItem() {
// 增加能量条 // 增加能量条
PushCoinAddPower(p, PushCoinItemValue[v.GetItemId()]*v.GetItemNum()) val := GetPushCoinValue(p.Platform, v.GetItemId())
if val <= 0 {
logger.Logger.Errorf("推币机价值查询bug itemId:%v", v.GetItemId())
}
logger.Logger.Debugf("推币机,掉落 ItemId:%v ItemNum:%v Value:%v", v.GetItemId(), v.GetItemNum(), val)
PushCoinAddPower(p, val*v.GetItemNum())
// 减少桌面道具 // 减少桌面道具
PushCoinAddValue(p, map[int32]int64{v.GetItemId(): -v.GetItemNum()}) PushCoinAddValue(p, map[int32]int64{v.GetItemId(): -v.GetItemNum()})
} }
@ -284,7 +373,6 @@ func CSPushCoinPlayerOp(s *netlib.Session, packetid int, data interface{}, sid i
}) })
if k == common.ItemIDShake { if k == common.ItemIDShake {
p.WelfData.PushCoin.Shake += int32(v) p.WelfData.PushCoin.Shake += int32(v)
continue
} }
gain = append(gain, &model.Item{ gain = append(gain, &model.Item{
ItemId: int32(k), ItemId: int32(k),
@ -334,6 +422,13 @@ func InitPlayerPushCoin(p *Player) {
common.ItemIDCoin1: 50, common.ItemIDCoin1: 50,
common.ItemIDPlum: 1, common.ItemIDPlum: 1,
}, },
Turn: []int32{ // 转盘表数据id
1, 4, -1,
3, -1, 2,
-1, 5, 9,
},
Next: -1,
PoolV: []int64{-1, -1, -1},
} }
} }
@ -346,10 +441,14 @@ func PushCoinAddPower(p *Player, value int64) {
if p.WelfData.PushCoin.Power > PowerMax { if p.WelfData.PushCoin.Power > PowerMax {
p.WelfData.PushCoin.Power = PowerMax p.WelfData.PushCoin.Power = PowerMax
} }
p.SendToClient(int(activity.PushCoinPacketID_PACKET_NotifyPowerLine), &activity.NotifyPowerLine{
pack := &activity.NotifyPowerLine{
PowerLine: p.WelfData.PushCoin.Power, PowerLine: p.WelfData.PushCoin.Power,
PowerLineMax: PowerMax, PowerLineMax: PowerMax,
}) }
p.SendToClient(int(activity.PushCoinPacketID_PACKET_NotifyPowerLine), pack)
logger.Logger.Tracef("刷新能量条: %v", pack)
if value <= 0 { if value <= 0 {
return return
} }
@ -363,64 +462,198 @@ func PushCoinDraw(p *Player) {
return return
} }
p.WelfData.PushCoin.Power = 0 p.WelfData.PushCoin.Power = 0
var index int32 = -1
var draw *activity.DrawInfo
var draw1 []*activity.DrawInfo
// 奖池返奖
f1 := func() bool {
pool := PushCoinPoolMangerInstance.PlatformConfig[p.Platform]
if pool == nil {
return false
}
// fp 奖池返奖,返回是否成功
fp := func(i int, poolInfo *PushCoinPoolInfo) bool {
// 是否返奖
if poolInfo == nil || poolInfo.Remain <= 0 {
return false
}
// 玩家奖池没有返过奖
if len(p.WelfData.PushCoin.PoolV) > i && p.WelfData.PushCoin.PoolV[i] < poolInfo.Version {
cfg := WelfareMgrSington.GetConfig(p.Platform).PushCoinConfig
poolIndex := p.WelfData.PushCoin.Turn[PoolIndex[i]]
value := int64(0) // 奖品价值
if int(poolIndex) < len(cfg.GetPool1().GetPool()) {
e := cfg.GetPool1().GetPool()[poolIndex]
if e != nil {
for _, v := range e.GetAward() {
iv, ok := PushCoinItemValue[v.GetItemId()]
if ok {
value = v.GetItemNum() * iv
} else {
value = v.GetItemNum() * e.GetValue() // 目前只有实物是自定义的价值
}
break
}
}
}
if value > 0 {
// 价值是否足够
if poolInfo.Remain-value < 0 {
return false
}
// 扣除价值
poolInfo.Remain -= value
// 刷新玩家奖池版本
p.WelfData.PushCoin.PoolV[i] = poolInfo.Version
// 下次中奖位置
p.WelfData.PushCoin.Next = int32(PoolIndex[i])
logger.Logger.Tracef("下次中奖池:%v", p.WelfData.PushCoin)
return true
}
}
return false
}
// 奖池1
if fp(0, pool.Pool1) {
return true
}
// 奖池2
if fp(1, pool.Pool2) {
return true
}
// 奖池3
if fp(2, pool.Pool3) {
return true
}
return false
}
switch p.WelfData.PushCoin.Dram { switch p.WelfData.PushCoin.Dram {
case 0: case 0:
// 必中大金币 // 必中大金币
for _, v := range srvdata.PBDB_ACTPushCoinMgr.Datas.Arr { draw = PushCoinNormalRandom(common.ItemIDBigCoin)
for kk := range v.GetGain() { draw.Id = 0 // 查表
if kk == common.ItemIDBigCoin { // 下次必中v卡
index = v.GetId() p.WelfData.PushCoin.Next = 1 // 查表
break
}
}
}
case 1:
// 必中v卡
for _, v := range srvdata.PBDB_ACTPushCoinMgr.Datas.Arr {
for kk := range v.GetGain() {
if kk == common.ItemIDVCard {
index = v.GetId()
break
}
}
}
default: default:
var n int32 // 使用预生成结果
rand := common.RandInt(10000) if p.WelfData.PushCoin.Next >= 0 {
for _, v := range srvdata.PBDB_ACTPushCoinMgr.Datas.Arr { k := p.WelfData.PushCoin.Next
if rand < int(n+v.GetRate()) { val := p.WelfData.PushCoin.Turn[p.WelfData.PushCoin.Next]
index = v.GetId() if slices.Contains(NormaIndex, int(k)) {
// 普通奖品
for kk, vv := range srvdata.PBDB_ACTPushCoinMgr.GetData(val).GetGain() {
draw = &activity.DrawInfo{
Id: k,
ItemId: int32(kk),
ItemNum: vv,
}
logger.Logger.Tracef("中奖普通奖品:%v", draw)
}
}
if slices.Contains(PoolIndex, int(k)) {
f := func(i int, list []*webapi.PushCoinPoolElement) {
// 本次奖品
if i < len(list) {
for _, v := range list[i].GetAward() {
draw = &activity.DrawInfo{
Id: p.WelfData.PushCoin.Next,
ItemId: v.GetItemId(),
ItemNum: v.GetItemNum(),
}
logger.Logger.Tracef("中奖奖池奖品:%v", draw)
break break
} }
n += v.GetRate() } else {
logger.Logger.Errorf("奖池抽奖bug: %d, %d, %d", k, i, len(list))
}
// 刷新奖池
e, index := PushCoinPoolRandom(list)
if e != nil {
p.WelfData.PushCoin.Turn[k] = index
for _, v := range e.GetAward() {
draw1 = append(draw1, &activity.DrawInfo{
Id: k,
ItemId: v.GetItemId(),
ItemNum: v.GetItemNum(),
})
logger.Logger.Tracef("刷新奖池奖品:%v", draw)
break
}
} else {
logger.Logger.Errorf("奖池刷新bug: %d, %d, %d", k, i, len(list))
} }
} }
// 水池奖品
var poolElements []*webapi.PushCoinPoolElement
switch slices.Index(PoolIndex, int(k)) {
case 0:
poolElements = WelfareMgrSington.GetConfig(p.Platform).PushCoinConfig.GetPool1().GetPool()
case 1:
poolElements = WelfareMgrSington.GetConfig(p.Platform).PushCoinConfig.GetPool2().GetPool()
case 2:
poolElements = WelfareMgrSington.GetConfig(p.Platform).PushCoinConfig.GetPool3().GetPool()
}
f(int(val), poolElements)
}
}
// 下次中奖位置
// 奖池返奖 或 普通抽奖
if !f1() {
// 普通抽奖
index := int(p.WelfData.PushCoin.Next) // 奖品位置
e := PushCoinNormalRandom(0)
if e != nil {
var has bool
for k, v := range p.WelfData.PushCoin.Turn {
if slices.Contains(NormaIndex, k) && v == e.GetId() {
has = true
index = k
break
}
}
if !has {
// 替换
if slices.Contains(PoolIndex, index) {
// 找一个普通奖品位置
index = NormaIndex[common.RandInt(len(NormaIndex[:len(NormaIndex)-1]))]
}
draw1 = append(draw1, &activity.DrawInfo{
Id: int32(index),
ItemId: e.GetItemId(),
ItemNum: e.GetItemNum(),
})
p.WelfData.PushCoin.Turn[index] = e.GetId()
}
p.WelfData.PushCoin.Next = int32(index)
logger.Logger.Tracef("下次中普通奖品index:%v ItemId:%v Num:%v", index, e.GetItemId(), e.GetItemNum())
}
}
}
p.WelfData.PushCoin.Dram++ p.WelfData.PushCoin.Dram++
if index >= 0 { if draw != nil {
d := srvdata.PBDB_ACTPushCoinMgr.GetData(index)
if d != nil {
pack := &activity.NotifyDrawInfo{ pack := &activity.NotifyDrawInfo{
Draw: &activity.DrawInfo{ Draw: draw,
Id: d.GetId(),
},
} }
for k, v := range d.GetGain() { if len(draw1) > 0 {
pack.Draw.ItemId = int32(k) pack.Info = draw1
pack.Draw.ItemNum = int32(v)
PushCoinAddValue(p, map[int32]int64{int32(k): v})
} }
if pack.Draw.ItemId > 0 {
PushCoinAddValue(p, map[int32]int64{draw.GetItemId(): draw.GetItemNum()})
p.SendToClient(int(activity.PushCoinPacketID_PACKET_NotifyDrawInfo), pack) p.SendToClient(int(activity.PushCoinPacketID_PACKET_NotifyDrawInfo), pack)
// 增加能量条 logger.Logger.Trace("NotifyDrawInfo: ", pack)
// 刷新能量条
PushCoinAddPower(p, 0) PushCoinAddPower(p, 0)
} }
} }
}
}
// PushCoinAddValue 增加桌面道具 // PushCoinAddValue 增加桌面道具
func PushCoinAddValue(p *Player, item map[int32]int64) { func PushCoinAddValue(p *Player, item map[int32]int64) {
@ -432,12 +665,111 @@ func PushCoinAddValue(p *Player, item map[int32]int64) {
p.WelfData.PushCoin.Items = make(map[int32]int64) p.WelfData.PushCoin.Items = make(map[int32]int64)
} }
for k, v := range item { for k, v := range item {
if v > 0 {
switch k {
default:
p.WelfData.PushCoin.Items[k] += v p.WelfData.PushCoin.Items[k] += v
logger.Logger.Tracef("桌面数据 ItemId:%v Change:%v Num:%v", k, v, p.WelfData.PushCoin.Items[k])
} }
} }
} }
func PushCoinPoolRandom(pool []*webapi.PushCoinPoolElement) (*webapi.PushCoinPoolElement, int32) {
var total int32
for _, v := range pool {
if v.GetOn() == common.On {
total += v.GetWeight()
} }
} }
if total <= 0 {
return nil, -1
}
var n int32
rn := int32(common.RandInt(int(total)))
for k, v := range pool {
if v.GetOn() == common.On {
n += v.GetWeight()
if rn < n {
return v, int32(k)
}
}
}
return nil, -1
}
func PushCoinNormalRandom(itemId int64) *activity.DrawInfo {
var total int32
var index = int32(-1) // 随机id
var n int32
if itemId == 0 {
// 随机抽奖
for _, vv := range srvdata.PBDB_ACTPushCoinMgr.Datas.GetArr() {
total += vv.GetRate()
}
rn := int32(common.RandInt(int(total)))
for _, vv := range srvdata.PBDB_ACTPushCoinMgr.Datas.GetArr() {
n += vv.GetRate()
if rn < n {
index = vv.GetId()
break
}
}
if index >= 0 {
for kk, vv := range srvdata.PBDB_ACTPushCoinMgr.GetData(index).GetGain() {
draw := &activity.DrawInfo{
Id: index,
ItemId: int32(kk),
ItemNum: vv,
}
return draw
}
}
return nil
}
// 前两次必中
for _, v := range srvdata.PBDB_ACTPushCoinMgr.Datas.GetArr() {
for kk, vv := range v.GetGain() {
if kk == itemId {
draw := &activity.DrawInfo{
ItemId: int32(kk),
ItemNum: vv,
}
return draw
}
}
}
return nil
}
// GetPushCoinValue 查询物品价值,没有的是后台配置的价值
func GetPushCoinValue(plt string, itemId int32) int64 {
val, ok := PushCoinItemValue[itemId]
if ok {
return val
}
cfg := WelfareMgrSington.GetConfig(plt).PushCoinConfig
if cfg != nil {
f := func(list []*webapi.PushCoinPoolElement) bool {
for _, vv := range list {
for _, vvv := range vv.GetAward() {
if vvv.GetItemId() == itemId {
val = vv.GetValue()
return true
}
}
}
return false
}
for {
if f(cfg.GetPool1().GetPool()) {
break
}
if f(cfg.GetPool2().GetPool()) {
break
}
if f(cfg.GetPool3().GetPool()) {
break
}
break
}
}
return val
}

View File

@ -0,0 +1,91 @@
package main
import (
"mongo.games.com/game/common"
"mongo.games.com/game/protocol/webapi"
"mongo.games.com/goserver/core/logger"
"time"
"mongo.games.com/goserver/core/module"
)
var (
NormaIndex = []int{0, 1, 3, 5, 7, 8} // 普通奖位置
PoolIndex = []int{2, 4, 6} // 水池位置
)
var PushCoinPoolMangerInstance = &PushCoinPoolManager{
PlatformConfig: map[string]*PushCoinPool{},
}
func init() {
module.RegisteModule(PushCoinPoolMangerInstance, time.Hour, 0)
}
type PushCoinPool struct {
Pool1 *PushCoinPoolInfo
Pool2 *PushCoinPoolInfo
Pool3 *PushCoinPoolInfo
}
type PushCoinPoolInfo struct {
CurCoin int64 // 当前金币
Remain int64 // 剩余金币
Version int64 // 版本号, 达到上限后更新
}
type PushCoinPoolManager struct {
PlatformConfig map[string]*PushCoinPool
}
func (p *PushCoinPoolManager) ModuleName() string {
return "PushCoinPoolManager"
}
func (p *PushCoinPoolManager) Init() {
// 加载水池
}
func (p *PushCoinPoolManager) Update() {
}
func (p *PushCoinPoolManager) Shutdown() {
// 保存水池
module.UnregisteModule(p)
}
func (p *PushCoinPoolManager) Add(platform string, val int64) {
cfg, ok := p.PlatformConfig[platform]
if !ok {
cfg = &PushCoinPool{
Pool1: &PushCoinPoolInfo{},
Pool2: &PushCoinPoolInfo{},
Pool3: &PushCoinPoolInfo{},
}
p.PlatformConfig[platform] = cfg
}
conf := WelfareMgrSington.GetConfig(platform).PushCoinConfig
if conf.GetOn() != common.On {
return
}
f := func(i int, poolInfo *PushCoinPoolInfo, pool *webapi.PushCoinPool, rate float64) {
if pool != nil && pool.GetOn() == common.On {
change := int64(float64(val) * rate)
poolInfo.CurCoin += change
if poolInfo.CurCoin >= pool.GetUpperLimit() {
poolInfo.Remain = pool.GetUpperLimit()
poolInfo.CurCoin -= pool.GetUpperLimit()
poolInfo.Version++
}
logger.Logger.Tracef("推币机 水池%v PoolInfo:%+v Change:%v Value:%v Rate:%v Limit:%v",
i, poolInfo, change, val, rate, pool.GetUpperLimit())
}
}
f(1, cfg.Pool1, conf.GetPool1(), 0.05)
f(2, cfg.Pool2, conf.GetPool2(), 0.005)
f(3, cfg.Pool3, conf.GetPool3(), 0.001)
}

View File

@ -119,6 +119,76 @@ func init() {
etcd.Register(etcd.KeyActConsume, webapi.ConsumeConfig{}, platformConfigEvent) etcd.Register(etcd.KeyActConsume, webapi.ConsumeConfig{}, platformConfigEvent)
// 推金币活动配置 // 推金币活动配置
etcd.Register(etcd.KeyActPushCoin, webapi.PushCoinConfig{}, platformConfigEvent) etcd.Register(etcd.KeyActPushCoin, webapi.PushCoinConfig{}, platformConfigEvent)
//WelfareMgrSington.UpdatePushCoinConfig(&webapi.PushCoinConfig{
// Platform: "1",
// On: 1,
// StartTime: "2024-01-01 00:00:00",
// EndTime: "2026-01-01 00:00:00",
// Pool1: &webapi.PushCoinPool{
// On: 1,
// Pool: []*webapi.PushCoinPoolElement{
// {
// On: 1,
// Tp: 0,
// Award: []*webapi.ItemInfo{
// {
// ItemId: common.ItemIDCoin1,
// ItemNum: 10,
// },
// },
// Weight: 100,
// },
// },
// UpperLimit: 100000,
// },
// Pool2: &webapi.PushCoinPool{
// On: 1,
// Pool: []*webapi.PushCoinPoolElement{
// {
// On: 1,
// Tp: 0,
// Award: []*webapi.ItemInfo{
// {
// ItemId: common.ItemIDCoin2,
// ItemNum: 10,
// },
// },
// Weight: 100,
// },
// },
// UpperLimit: 100000,
// },
// Pool3: &webapi.PushCoinPool{
// On: 1,
// Pool: []*webapi.PushCoinPoolElement{
// {
// On: 1,
// Tp: 0,
// Award: []*webapi.ItemInfo{
// {
// ItemId: common.ItemIDCoin1,
// ItemNum: 10,
// },
// },
// Weight: 100,
// },
// {
// On: 1,
// Tp: 1,
// Award: []*webapi.ItemInfo{
// {
// ItemId: 30011,
// ItemNum: 1,
// },
// },
// Weight: 100,
// Value: 100000,
// },
// },
// UpperLimit: 100000,
// },
//})
} }
func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) { func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {

Binary file not shown.