Compare commits

...

2 Commits

Author SHA1 Message Date
by c671da56e6 Merge branch 'develop' of https://git.pogorockgames.com/mango-games/server/game into develop
# Conflicts:
#	etcd/keyconf.go
#	model/config.go
#	protocol/player/player.pb.go
#	protocol/player/player.proto
#	protocol/webapi/common.pb.go
#	protocol/webapi/common.proto
#	worldsrv/etcd.go
2024-07-09 17:43:14 +08:00
by 0484f1f47b 钻石抽奖实现 2024-07-09 17:35:55 +08:00
10 changed files with 369 additions and 24 deletions

View File

@ -292,6 +292,7 @@ const (
GainWayPermitExchangeCost = 96 // 赛季通行证兑换消耗
GainWayPermitExchangeGain = 97 // 赛季通行证兑换获得
GainWayItemTaskPermit = 98 // 赛季通行证任务
GainWayDiamondLottery = 99 //钻石抽奖
)
// 后台选择 金币变化类型 的充值 类型id号起始
@ -786,6 +787,7 @@ var PetIDs = []int32{PetIDChicken}
const (
ChannelSwitchExchange = 1
ChannelSwitchDropItem = 2
DiamondLottery = 4
)
// 特殊商品id

View File

@ -33,5 +33,7 @@ const (
ETCDKEY_ChannelSwitch = "/game/channel/switch" // 渠道开关
ETCDKEY_ACT_Invite = "/game/act_invite" // 邀请活动配置
ETCDKEY_ACT_Permit = "/game/act_permit" // 赛季通行证配置
ETCDKEY_DIAMOND_LOTTERY = "/game/diamond_lottery" // 钻石抽奖配置
ETCDKEY_Item = "/game/item" // 道具列表
)

View File

@ -149,9 +149,9 @@
"SlowMS": 500
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"Url": ["47.105.78.29:2379"],
"UserName": "root",
"Password": "win88",
"DialTimeout": 60
},
"costum": {

View File

@ -19,6 +19,7 @@ const (
OpContinuousPay = 4
OpPhoneLottery = 5
OpCollect = 6
OpDiamondLottery = 7
)
const (
@ -123,6 +124,7 @@ type AllConfig struct {
*webapi.ActPermitConfig
PermitStartTs int64 // 开始时间戳
PermitEndTs int64 // 结束时间戳
*webapi.DiamondLotteryConfig
// 道具配置
*webapi.ItemConfig
}

View File

@ -478,6 +478,7 @@ type PlayerData struct {
IScoreTs time.Time // 邀请积分更新时间
Permit time.Time // 赛季通行证领取时间
PermitStartTs int64 // 赛季通行证开始时间戳
DiamondLotteryScore int64 //钻石抽奖幸运值
}
// 七日签到数据

View File

@ -211,7 +211,14 @@ enum PlayerPacketID {
PACKET_SCExchangeChannel = 2826; //
PACKET_CSSMSConfig = 2827; //
PACKET_SCSMSConfig = 2828; //
PACKET_SCItem = 2830; //
PACKET_CS_DiamondLotteryInfo = 2829; //
PACKET_SC_DiamondLotteryInfo = 2830; //
PACKET_CS_DiamondLottery = 2831; //
PACKET_SC_DiamondLottery = 2832; //
PACKET_CSDiamondLotteryLuckyAward = 2833; //
PACKET_SCDiamondLotteryLuckyAward = 2834; //
PACKET_SCItem = 2835; //
}
//
@ -1153,6 +1160,7 @@ message LotteryItem{
int32 Id = 1;
int32 ItemId = 2;
int64 ItemNum =3;
int32 TypeId = 4;
}
//
@ -1194,7 +1202,7 @@ message CSExchangeChannel{
message ChannelSwitch {
repeated string OnChannelName = 1; //
int32 Tp = 2; // 1 2v卡掉落 3:
int32 Tp = 2; // 1 2v卡掉落 3: 4:
}
// PACKET_SCExchangeChannel
@ -1215,6 +1223,39 @@ message SMSInfo{
string SmsName = 2;
}
//
//PACKET_CS_DiamondLotteryInfo
message CSDiamondLotteryInfo{
}
//
//PACKET_SC_DiamondLotteryInfo
message SCDiamondLotteryInfo{
int64 LuckyScore = 1; //
repeated LotteryItem Item = 2;//
int32 MaxScore = 3;//
int32 DiamondNum = 4; //
}
//
//PACKET_CS_DiamondLottery
message CSDiamondLottery{
int32 LotteryType = 1; //1- 2-
}
//
//PACKET_SC_DiamondLottery
message SCDiamondLottery{
int64 LuckyScore = 1; //
repeated LotteryItem Item = 2; //
}
//
//PACKET_CSDiamondLotteryLuckyAward
message CSDiamondLotteryLuckyAward{
}
////PACKET_SCDiamondLotteryLuckyAward
message SCDiamondLotteryLuckyAward{
int64 LuckyScore = 1; //
repeated LotteryItem Item = 2; //
// PACKET_SCItem
message SCItem{
repeated server.DB_GameItem Items = 1; //

View File

@ -672,7 +672,7 @@ message WelfareCollectConfig{
// etcd /game/channel/switch
message ChannelSwitchConfig{
int32 Tp = 1; // 1. 2. 3.
int32 Tp = 1; // 1. 2. 3. 4.
string Platform = 2; // id
repeated string OnChannelName = 3; //
}
@ -737,6 +737,36 @@ message ActPermitConfig{
repeated PermitChannelConfig Configs = 4; //
}
//
message DiamondLotteryInfo{
int32 Id = 1;
int32 Type = 2;
string Name = 3;
int32 ItemId = 4;
int32 Grade = 5;
int32 Oddrate =6;
}
//
message DiamondLotteryPlayers{
int32 uid = 1;
int32 Count = 2; //
repeated int32 AwatdId = 3; //ID
}
message DiamondLotteryData{
string Channel = 1; //
repeated DiamondLotteryInfo Info = 2;
int32 MaxScore = 3; //
int32 DiamondNum = 4; //
repeated DiamondLotteryPlayers Players = 5;//
}
// etcd /game/diamond_lottery
message DiamondLotteryConfig{
string Platform = 1; //
repeated DiamondLotteryData LotteryData = 2;
}
// etcd /game/item
message ItemConfig {
string Platform = 1; //

View File

@ -6,6 +6,7 @@ import (
"mongo.games.com/game/common"
"mongo.games.com/game/model"
player_proto "mongo.games.com/game/protocol/player"
"mongo.games.com/game/protocol/webapi"
"mongo.games.com/game/srvdata"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
@ -24,7 +25,6 @@ func (this *CSPhoneLotteryInfoPacketFactory) CreatePacket() interface{} {
// 获取抽奖信息
func (this *CSPhoneLotteryInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
if _, ok := data.(*player_proto.CSPhoneLotteryInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
logger.Logger.Trace("客户端请求抽奖信息snid = ", p.SnId)
@ -80,7 +80,8 @@ func (this *CSPhoneLotteryHandler) Process(s *netlib.Session, packetid int, data
logger.Logger.Warn("CSPhoneLottery p == nil")
return nil
}
if WelfareMgrSington.GetPhoneLotteryStatus(p.Platform) == model.WelfareClose {
conf := PlatformMgrSingleton.GetConfig(p.Platform).ChannelSwitch[common.DiamondLottery]
if !model.GameParamData.CloseChannelSwitch && (conf == nil || !common.InSliceString(conf.OnChannelName, p.LastChannel)) {
return nil
}
countType := msg.GetLotteryType()
@ -91,10 +92,6 @@ func (this *CSPhoneLotteryHandler) Process(s *netlib.Session, packetid int, data
count = 10
}
logger.Logger.Tracef("玩家请求抽奖snid =%d,count = %d ", p.SnId, count)
if p == nil {
logger.Logger.Warn("CSPhoneLottery p == nil")
return nil
}
if p.LotteryCount < count {
logger.Logger.Trace("剩余抽奖次数不足,无法抽奖 count = ", count)
return nil
@ -209,6 +206,257 @@ func (this *CSPhoneLotteryHandler) Process(s *netlib.Session, packetid int, data
return nil
}
type CSDiamondLotteryInfoPacketFactory struct {
}
type CSDiamondLotteryInfoHandler struct {
}
func (this *CSDiamondLotteryInfoPacketFactory) CreatePacket() interface{} {
pack := &player_proto.CSDiamondLotteryInfo{}
return pack
}
// 获取钻石抽奖信息
func (this *CSDiamondLotteryInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
if _, ok := data.(*player_proto.CSPhoneLotteryInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
logger.Logger.Trace("客户端请求钻石抽奖信息snid = ", p.SnId)
if p == nil {
logger.Logger.Warn("CSPhoneLotteryInfo p == nil")
return nil
}
// 渠道开关
conf := PlatformMgrSingleton.GetConfig(p.Platform).ChannelSwitch[common.DiamondLottery]
if !model.GameParamData.CloseChannelSwitch && (conf == nil || !common.InSliceString(conf.OnChannelName, p.LastChannel)) {
return nil
}
pack := &player_proto.SCDiamondLotteryInfo{}
pack.LuckyScore = p.DiamondLotteryScore
info := WelfareMgrSington.GetConfig(p.Platform)
if info != nil && info.DiamondLotteryConfig != nil {
for _, data := range info.DiamondLotteryConfig.LotteryData {
if data.Channel == p.Channel {
pack.MaxScore = data.MaxScore
pack.DiamondNum = data.DiamondNum
for _, lotteryInfo := range data.Info {
item := &player_proto.LotteryItem{
Id: lotteryInfo.Id,
ItemId: lotteryInfo.ItemId,
ItemNum: int64(lotteryInfo.Grade),
TypeId: lotteryInfo.Type,
}
pack.Item = append(pack.Item, item)
}
}
}
}
p.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_DiamondLotteryInfo), pack)
logger.Logger.Trace("返回钻石抽奖信息:", pack.String())
}
return nil
}
type CSDiamondLotteryPacketFactory struct {
}
type CSDiamondLotteryHandler struct {
}
func (this *CSDiamondLotteryPacketFactory) CreatePacket() interface{} {
pack := &player_proto.CSDiamondLottery{}
return pack
}
// 玩家钻石抽奖
func (this *CSDiamondLotteryHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
if msg, ok := data.(*player_proto.CSDiamondLottery); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warn("CSDiamondLottery p == nil")
return nil
}
// 渠道开关
conf := PlatformMgrSingleton.GetConfig(p.Platform).ChannelSwitch[common.DiamondLottery]
if !model.GameParamData.CloseChannelSwitch && (conf == nil || !common.InSliceString(conf.OnChannelName, p.LastChannel)) {
return nil
}
countType := msg.GetLotteryType()
count := int32(0)
if countType == 1 {
count = 1
} else {
count = 10
}
logger.Logger.Tracef("玩家请求钻石抽奖snid =%d,count = %d ", p.SnId, count)
info := WelfareMgrSington.GetConfig(p.Platform)
var config *webapi.DiamondLotteryData
if info == nil && info.DiamondLotteryConfig != nil {
for _, data := range info.LotteryData {
if data.Channel == p.Channel {
config = data
break
}
}
if config == nil {
logger.Logger.Error("钻石抽奖未找到配置p.Channel = ", p.Channel)
return nil
}
//判断钻石数量
diamondNum := int64(config.DiamondNum * count)
if p.Diamond < diamondNum {
logger.Logger.Trace("钻石抽奖 ,钻石数量不足!")
return nil
}
p.AddDiamond(-diamondNum, 0, common.GainWayDiamondLottery, "sys", "钻石抽奖")
pack := &player_proto.SCDiamondLottery{}
weight := 0
for _, lotteryInfo := range config.Info {
if lotteryInfo.Type == 1 {
weight += int(lotteryInfo.Oddrate)
}
}
var items []*Item
for i := 1; i <= int(count); i++ {
random := rand.Intn(weight) + 1
value := 0
p.DiamondLotteryScore += 1
//判断是否白名单用户
whiteList := config.Players
status := false
var playerData *webapi.DiamondLotteryPlayers
for _, players := range whiteList {
if players.Uid == p.SnId {
playerData = players
break
}
}
if playerData != nil && p.DiamondLotteryScore%int64(playerData.Count) == 0 {
status = true
}
if status {
//白名单从列表里获取奖励
id := rand.Intn(len(playerData.AwatdId)) + 1
awardId := playerData.AwatdId[id]
for _, lotteryInfo := range config.Info {
if lotteryInfo.Id == awardId {
items = append(items, &Item{
ItemId: lotteryInfo.ItemId, // 物品id
ItemNum: int64(lotteryInfo.Grade), // 数量
})
itemData := &player_proto.LotteryItem{
Id: lotteryInfo.Id,
ItemId: lotteryInfo.ItemId,
ItemNum: int64(lotteryInfo.Grade),
}
pack.Item = append(pack.Item, itemData)
break
}
}
} else {
for _, lotteryInfo := range config.Info {
value += int(lotteryInfo.Oddrate)
if lotteryInfo.Type == 1 {
if random <= value {
items = append(items, &Item{
ItemId: lotteryInfo.ItemId, // 物品id
ItemNum: int64(lotteryInfo.Grade), // 数量
})
itemData := &player_proto.LotteryItem{
Id: lotteryInfo.Id,
ItemId: lotteryInfo.ItemId,
ItemNum: int64(lotteryInfo.Grade),
}
pack.Item = append(pack.Item, itemData)
break
}
}
}
}
}
BagMgrSingleton.AddItems(p, items, 0, common.GainWayDiamondLottery, "system", "钻石抽奖", 0, 0, false)
pack.LuckyScore = p.DiamondLotteryScore
p.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_DiamondLottery), pack)
logger.Logger.Trace("返回钻石抽奖信息:", pack.String())
}
}
return nil
}
// 领取保底奖励
type CSDiamondLotteryLuckyAwardPacketFactory struct {
}
type CSDiamondLotteryLuckyAwardHandler struct {
}
func (this *CSDiamondLotteryLuckyAwardPacketFactory) CreatePacket() interface{} {
pack := &player_proto.CSDiamondLotteryLuckyAward{}
return pack
}
// 玩家钻石抽奖保底奖励
func (this *CSDiamondLotteryLuckyAwardHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
if _, ok := data.(*player_proto.CSDiamondLotteryLuckyAward); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warn("CSDiamondLotteryLuckyAward p == nil")
return nil
}
// 渠道开关
conf := PlatformMgrSingleton.GetConfig(p.Platform).ChannelSwitch[common.DiamondLottery]
if !model.GameParamData.CloseChannelSwitch && (conf == nil || !common.InSliceString(conf.OnChannelName, p.LastChannel)) {
return nil
}
info := WelfareMgrSington.GetConfig(p.Platform)
var config *webapi.DiamondLotteryData
if info == nil && info.DiamondLotteryConfig != nil {
for _, data := range info.LotteryData {
if data.Channel == p.Channel {
config = data
break
}
}
if config == nil {
logger.Logger.Error("钻石抽奖未找到配置p.Channel = ", p.Channel)
return nil
}
if p.DiamondLotteryScore < int64(config.MaxScore) {
return nil
}
p.DiamondLotteryScore -= int64(config.MaxScore)
pack := &player_proto.SCDiamondLotteryLuckyAward{}
pack.LuckyScore = p.DiamondLotteryScore
//获取奖励
for _, lotteryInfo := range config.Info {
if lotteryInfo.Type == 2 {
var items []*Item
items = append(items, &Item{
ItemId: lotteryInfo.ItemId, // 物品id
ItemNum: int64(lotteryInfo.Grade), // 数量
})
itemData := &player_proto.LotteryItem{
Id: lotteryInfo.Id,
ItemId: lotteryInfo.ItemId,
ItemNum: int64(lotteryInfo.Grade),
}
BagMgrSingleton.AddItems(p, items, 0, common.GainWayDiamondLottery, "system", "钻石抽奖", 0, 0, false)
pack.Item = append(pack.Item, itemData)
break
}
}
p.SendToClient(int(player_proto.PlayerPacketID_PACKET_SCDiamondLotteryLuckyAward), pack)
logger.Logger.Trace("返回钻石抽奖领取保底奖励信息:", pack.String())
}
}
return nil
}
func init() {
// 抽奖信息
common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_PhoneLotteryInfo), &CSPhoneLotteryInfoHandler{})
@ -216,4 +464,13 @@ func init() {
// 抽奖
common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_PhoneLottery), &CSPhoneLotteryHandler{})
netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_CS_PhoneLottery), &CSPhoneLotteryPacketFactory{})
//钻石抽奖信息
common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_DiamondLotteryInfo), &CSDiamondLotteryInfoHandler{})
netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_SC_DiamondLotteryInfo), &CSDiamondLotteryInfoPacketFactory{})
// 钻石抽奖
common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CS_DiamondLottery), &CSDiamondLotteryHandler{})
netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_CS_DiamondLottery), &CSDiamondLotteryPacketFactory{})
//钻石抽奖保底奖励
common.RegisterHandler(int(player_proto.PlayerPacketID_PACKET_CSDiamondLotteryLuckyAward), &CSDiamondLotteryLuckyAwardHandler{})
netlib.RegisterFactory(int(player_proto.PlayerPacketID_PACKET_CSDiamondLotteryLuckyAward), &CSDiamondLotteryLuckyAwardPacketFactory{})
}

View File

@ -78,6 +78,8 @@ func init() {
etcd.Register(etcd.ETCDKEY_ACT_Invite, webapi.ActInviteConfig{}, platformConfigEvent)
// 赛季通行证
etcd.Register(etcd.ETCDKEY_ACT_Permit, webapi.ActPermitConfig{}, platformConfigEvent)
// 钻石抽奖
etcd.Register(etcd.ETCDKEY_DIAMOND_LOTTERY, webapi.DiamondLotteryConfig{}, platformConfigEvent)
// 道具列表
etcd.Register(etcd.ETCDKEY_Item, webapi.ItemConfig{}, platformConfigEvent)
}
@ -209,6 +211,8 @@ func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, e
ChessRankMgrSington.UpdateChessRankConfig(config)
case *webapi.WelfarePhoneLotteryStatus:
WelfareMgrSington.UpdatePhoneLotteryStatus(config)
case *webapi.DiamondLotteryConfig:
WelfareMgrSington.UpdateDiamondLotteryConfig(config)
case *webapi.ActInviteConfig:
PlatformMgrSingleton.GetConfig(config.Platform).ActInviteConfig = config
case *webapi.ActPermitConfig:

View File

@ -215,6 +215,12 @@ func (this *WelfareMgr) UpdatePhoneLotteryStatus(cfg *webapi_proto.WelfarePhoneL
}
}
// 更新钻石抽奖配置
func (this *WelfareMgr) UpdateDiamondLotteryConfig(cfg *webapi_proto.DiamondLotteryConfig) {
info := this.GetConfig(cfg.Platform)
info.DiamondLotteryConfig = cfg
}
func (this *WelfareMgr) GetPhoneLotteryStatus(platform string) int32 {
info := this.GetConfig(platform)
if info.WelfarePhoneLotteryStatus != nil {