业务逻辑

This commit is contained in:
liuxiaobo 2025-06-09 19:10:18 +08:00
parent a70aa79e31
commit 774604644c
8 changed files with 540 additions and 343 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/fox/fox/log"
"github.com/fox/fox/processor"
"github.com/fox/fox/service"
"github.com/fox/fox/timer"
"github.com/golang/protobuf/proto"
"time"
)
@ -18,9 +19,9 @@ type BaseRoom[Seat ISeat] struct {
gameNo string
Seats []Seat
processor *processor.Processor
timeProcessor *processor.Processor
timeProcessor *processor.TimerProcessor
timeTypes map[TimerType]uint32
timeTypes map[timer.ITimeType]uint32
srv service.IService
}
@ -30,10 +31,10 @@ func NewBaseRoom[Seat ISeat](id, roomType, playType int, srv service.IService) (
roomType: roomType,
playType: playType,
gameNo: "",
timeTypes: make(map[TimerType]uint32),
timeTypes: make(map[timer.ITimeType]uint32),
srv: srv,
processor: processor.NewProcessor(),
timeProcessor: processor.NewProcessor(),
timeProcessor: processor.NewTimerProcessor(),
}
return room, pb.ErrCode_OK
@ -157,7 +158,7 @@ func (r *BaseRoom[Seat]) Broadcast(msgId pb.MsgId, msg proto.Message, exclude ..
}
}
func (r *BaseRoom[Seat]) NewTimer(timerType TimerType, duration time.Duration, args ...any) {
func (r *BaseRoom[Seat]) NewTimer(timerType timer.ITimeType, duration time.Duration, args ...any) {
if _, ok := r.timeTypes[timerType]; ok {
log.Error(r.Log("timer type:%v is exist.can not new timer", timerType.String()))
// if timerType == TtPlayerAct {
@ -166,7 +167,7 @@ func (r *BaseRoom[Seat]) NewTimer(timerType TimerType, duration time.Duration, a
return
}
tid := r.srv.NewTimer(duration+time.Duration(10)*time.Millisecond, func() {
if err := r.timeProcessor.Dispatch(int32(timerType), args...); err != nil {
if err := r.timeProcessor.Dispatch(timerType, args...); err != nil {
log.ErrorF(r.Log("timer dispatch err:%v", err))
}
}, true, r.Log("start type:%v timer", timerType.String()))
@ -174,7 +175,7 @@ func (r *BaseRoom[Seat]) NewTimer(timerType TimerType, duration time.Duration, a
// log.Debug(r.Log("start type:%v timer", timerType.String()))
}
func (r *BaseRoom[Seat]) CancelTimer(timerType TimerType) {
func (r *BaseRoom[Seat]) CancelTimer(timerType timer.ITimeType) {
if tid, ok := r.timeTypes[timerType]; ok {
r.srv.CancelTimer(tid)
delete(r.timeTypes, timerType)
@ -187,7 +188,7 @@ func (r *BaseRoom[Seat]) CancelAllTimer() {
r.srv.CancelTimer(tid)
// log.Debug(r.Log("start type:%v timer", timerType.String()))
}
r.timeTypes = make(map[TimerType]uint32)
r.timeTypes = make(map[timer.ITimeType]uint32)
}
func (r *BaseRoom[Seat]) Log(format string, a ...any) string {
@ -238,7 +239,7 @@ func (r *BaseRoom[Seat]) RegisterMessages(metas processor.RegisterMetas) {
r.processor.RegisterMessages(metas)
}
func (r *BaseRoom[Seat]) timerDispatch(user IPlayer, cmd int32, params ...any) error {
func (r *BaseRoom[Seat]) timerDispatch(user IPlayer, cmd timer.ITimeType, params ...any) error {
inp := make([]any, len(params)+1)
inp = append(inp, user)
inp = append(inp, params...)
@ -246,7 +247,7 @@ func (r *BaseRoom[Seat]) timerDispatch(user IPlayer, cmd int32, params ...any) e
}
// 注册时间事件及处理
func (r *BaseRoom[Seat]) RegisterTimerMessages(metas processor.RegisterMetas) {
func (r *BaseRoom[Seat]) RegisterTimerMessages(metas processor.RegisterTimerMetas) {
r.timeProcessor.RegisterMessages(metas)
}

View File

@ -1,55 +0,0 @@
package baseroom
type TimerType int
const (
TtUnknown TimerType = 0
TtDealPoker TimerType = 200 // 发牌结束后通知玩家行动
TtDecidingGame TimerType = 201 // 决胜局展示手牌及同意,放弃行动
TtPlayerAct TimerType = 202 // 玩家行动
TtPlayerRspRaise TimerType = 204 // 玩家回应行动
TtCmpPoker TimerType = 205 // 比牌
TtNextGame TimerType = 208 // 下一小局
// TtGameEnd TimerType = 205 // 大局结束,询问玩家是否继续
// TtContinue TimerType = 206 // 继续
TtSecond TimerType = 220 // 每秒定时器
TtGameReadyStart TimerType = 221 // 游戏开始倒计时
TtEnterRoom TimerType = 222
// TtEmote TimerType = 223 // 发送表情
TtPlayerCutLine TimerType = 401 // 插队
TtDelDisbandRoomInfo TimerType = 402 // 删除解散房间投票
)
func (t TimerType) String() string {
switch t {
case TtUnknown:
return "unknown"
case TtDealPoker:
return "TtDealPoker"
case TtDecidingGame:
return "TtDecidingGame"
case TtPlayerAct:
return "TtPlayerAct"
case TtPlayerRspRaise:
return "TtPlayerRspRaise"
case TtCmpPoker:
return "TtCmpPoker"
case TtNextGame:
return "TtNextGame"
case TtPlayerCutLine:
return "TtPlayerCutLine"
// case TtContinue:
// return "TtContinue"
case TtSecond:
return "TtSecond"
case TtGameReadyStart:
return "TtGameReadyStart"
case TtDelDisbandRoomInfo:
return "TtDelDisbandRoomInfo"
case TtEnterRoom:
return "TtEnterRoom"
}
return ""
}

View File

@ -11,6 +11,11 @@ import (
"github.com/go-redis/redis/v8"
)
const (
Hundred = 100 // 放大100倍
RateBase = 10000 // 概率或者权重的底数是1万
)
var Command *config.Command
var Cfg *config.Common[game.ColorConfig]
@ -45,38 +50,37 @@ func LoadColorConfig(rdb *redis.Client) {
}
Cfg.Special = &game.ColorConfig{}
Cfg.Special.GameTiming = &game.ColorGameTiming{
//Ready: 100, // 倒计时321
// Ready: 100, // 倒计时321
Start: 2000,
Betting: 15000,
EndBetting: 3000,
OpenThreeDice: 3000,
Settle: 7000,
//Ranking: 1000,
// Ranking: 1000,
}
WinSingleColorWeight := [3]int{50, 25, 25}
WinSingleColorMul := [3][]*game.ColorMulRate{
{{Mul: 0.6 * 100, Rate: 75 * 100}, {Mul: 1 * 100, Rate: 12 * 100},
{Mul: 1.5 * 100, Rate: 7.5 * 100}, {Mul: 2 * 100, Rate: 5.5 * 100}},
{{Mul: 1 * Hundred, Rate: 100 * Hundred}},
{{Mul: 2 * 100, Rate: 82.5 * 100}, {Mul: 3 * 100, Rate: 4 * 100},
{Mul: 4 * 100, Rate: 3.5 * 100}, {Mul: 5 * 100, Rate: 3.2 * 100},
{Mul: 6 * 100, Rate: 230}, {Mul: 7 * 100, Rate: 1.8 * 100},
{Mul: 8 * 100, Rate: 1.5 * 100}, {Mul: 9 * 100, Rate: 1.2 * 100}},
{{Mul: 2 * Hundred, Rate: 82.5 * Hundred}, {Mul: 3 * Hundred, Rate: 4 * Hundred},
{Mul: 4 * Hundred, Rate: 3.5 * Hundred}, {Mul: 5 * Hundred, Rate: 3.2 * Hundred},
{Mul: 6 * Hundred, Rate: 230}, {Mul: 7 * Hundred, Rate: 1.8 * Hundred},
{Mul: 8 * Hundred, Rate: 1.5 * Hundred}, {Mul: 9 * Hundred, Rate: 1.2 * Hundred}},
{{Mul: 3 * 100, Rate: 94 * 100}, {Mul: 9 * 100, Rate: 1.4 * 100},
{Mul: 14 * 100, Rate: 110}, {Mul: 19 * 100, Rate: 0.9 * 100},
{Mul: 29 * 100, Rate: 0.8 * 100}, {Mul: 49 * 100, Rate: 0.7 * 100},
{Mul: 99 * 100, Rate: 0.6 * 100}, {Mul: 9 * 100, Rate: 0.5 * 100}},
{{Mul: 3 * Hundred, Rate: 94 * Hundred}, {Mul: 9 * Hundred, Rate: 1.4 * Hundred},
{Mul: 14 * Hundred, Rate: 110}, {Mul: 19 * Hundred, Rate: 0.9 * Hundred},
{Mul: 29 * Hundred, Rate: 0.8 * Hundred}, {Mul: 49 * Hundred, Rate: 0.7 * Hundred},
{Mul: 99 * Hundred, Rate: 0.6 * Hundred}, {Mul: 9 * Hundred, Rate: 0.5 * Hundred}},
}
WinDoubleColorMul := []*game.ColorMulRate{{Mul: 8 * 100, Rate: 66 * 100}, {Mul: 11 * 100, Rate: 17 * 100},
{Mul: 14 * 100, Rate: 9 * 100}, {Mul: 19 * 100, Rate: 3.5 * 100},
{Mul: 24 * 100, Rate: 1.9 * 100}, {Mul: 54 * 100, Rate: 1.5 * 100},
{Mul: 74 * 100, Rate: 1.05 * 100}, {Mul: 99 * 100, Rate: 0.05 * 100}}
WinDoubleColorMul := []*game.ColorMulRate{{Mul: 8 * Hundred, Rate: 66 * Hundred}, {Mul: 11 * Hundred, Rate: 17 * Hundred},
{Mul: 14 * Hundred, Rate: 9 * Hundred}, {Mul: 19 * Hundred, Rate: 3.5 * Hundred},
{Mul: 24 * Hundred, Rate: 1.9 * Hundred}, {Mul: 54 * Hundred, Rate: 1.5 * Hundred},
{Mul: 74 * Hundred, Rate: 1.05 * Hundred}, {Mul: 99 * Hundred, Rate: 0.05 * Hundred}}
WinThreeColorMul := []*game.ColorMulRate{{Mul: 150 * 100, Rate: 84.5 * 100}, {Mul: 199 * 100, Rate: 5.5 * 100},
{Mul: 299 * 100, Rate: 4 * 100}, {Mul: 599 * 100, Rate: 3 * 100},
{Mul: 799 * 100, Rate: 2 * 100}, {Mul: 999 * 100, Rate: 1 * 100}}
WinThreeColorMul := []*game.ColorMulRate{{Mul: 150 * Hundred, Rate: 84.5 * Hundred}, {Mul: 199 * Hundred, Rate: 5.5 * Hundred},
{Mul: 299 * Hundred, Rate: 4 * Hundred}, {Mul: 599 * Hundred, Rate: 3 * Hundred},
{Mul: 799 * Hundred, Rate: 2 * Hundred}, {Mul: 999 * Hundred, Rate: 1 * Hundred}}
rmConfig := &game.ColorRoomConfig{
BetList: [][]int64{
@ -89,27 +93,14 @@ func LoadColorConfig(rdb *redis.Client) {
WinSingleColorMul: WinSingleColorMul[:],
WinDoubleColorMul: WinDoubleColorMul,
WinThreeColorMul: WinThreeColorMul,
InitJackpot: 2000000 * 100,
JackpotRate: 0.05 * 100,
JpXRate: 2 * 100,
JpYRate: 1 * 100,
JpXYRate: 1.5 * 100,
InitJackpot: 2000000 * Hundred,
JackpotRate: 0.05 * Hundred,
JpXRate: 2 * Hundred,
JpYRate: 1 * Hundred,
JpXYRate: 1.5 * Hundred,
AreaBetLimit: 500000,
NoBetCountMax: 10,
OpenRobot: false,
OneCreateMin: 3,
OneCreateMax: 5,
UserAddRobotNum: 80,
UserAddRobotNumMax: 100,
OneDeleteNum: 1,
BalanceMinDelete: 4000,
BalanceMin: 100000,
BalanceMax: 500000,
RobotCreateTime: 8000,
RobotDeleteTime: 5000,
RobotBetNumMin: 2,
RobotBetNumMax: 4,
AreaBetLimit: 500000,
NoBetCountMax: 10,
}
Cfg.Special.Rooms = append(Cfg.Special.Rooms, rmConfig)

View File

@ -2,56 +2,68 @@ package room
import (
"game/common/baseroom"
"game/common/config/game"
"game/common/proto/pb"
"github.com/fox/fox/log"
"github.com/fox/fox/processor"
"github.com/fox/fox/service"
)
const (
BET_TYPE_NUM = 18
)
type ColorRoom struct {
*baseroom.BaseRoom[ColorSeat]
//---------------------------------
//Status pb.ColorPinoyLiveGameStatus // 房间状态1 表示
//StatusTime int64 // 切换状态时的时间戳
roomCfg game.ColorRoomConfig
timingCfg game.ColorGameTiming
status pb.ColorGameStatus
statusTime int64 // 毫秒时间戳
jackpot int64
endBetAreaMul []*pb.ColorBetAreaMul // 下注结束后,每个区域更新是否爆奖以及实际赔率
// ---------------------------------
// Status pb.ColorPinoyLiveGameStatus // 房间状态1 表示
// StatusTime int64 // 切换状态时的时间戳
//
//NormalDices []byte // 普通骰子 3个
//StartDices []byte // 初始位置摆放的骰子 3个
// NormalDices []byte // 普通骰子 3个
// StartDices []byte // 初始位置摆放的骰子 3个
//
//// DefaultLuckyDice byte // 幸运骰子 1个 每局开始 放在拉杆上的骰子
//// DefaultNormalDices []byte // 普通骰子 3个 每局开始 放在拉杆上的骰子
// // DefaultLuckyDice byte // 幸运骰子 1个 每局开始 放在拉杆上的骰子
// // DefaultNormalDices []byte // 普通骰子 3个 每局开始 放在拉杆上的骰子
//
//TotalBets [BET_TYPE_NUM]int64 // 各区域的下注统计
//TotalBet int64 // 下注统计
////SceneInfo model.SceneInfo // 下注的玩家列表
// TotalBets [BET_TYPE_NUM]int64 // 各区域的下注统计
// TotalBet int64 // 下注统计
// //SceneInfo model.SceneInfo // 下注的玩家列表
//
//GameTrend *pb.ColorPinoyLiveTrend // 走势图
////OnlineUserList []*model.User // 所有的玩家列表 用于排序
//PokerMsg *pb.ColorPinoyLivePokerMsg // 扑克消息
//RoomCfg game.ColorRoomConfig // 房间配置
//GameTiming game.ColorGameTiming // 时间配置
//startAt int64
//endAt int64
// GameTrend *pb.ColorPinoyLiveTrend // 走势图
// //OnlineUserList []*model.User // 所有的玩家列表 用于排序
// PokerMsg *pb.ColorPinoyLivePokerMsg // 扑克消息
// RoomCfg game.ColorRoomConfig // 房间配置
// GameTiming game.ColorGameTiming // 时间配置
// startAt int64
// endAt int64
//
//ServerStatus int32
//wd *sync.WaitGroup
//TrendRedisKey string
//_aniLuckyDiceRouteIndex int32 // 幸运骰子动画路径
//_aniThreeDiceRouteIndex int32 // 3个骰子动画路径
//BigWinner []*pb.ColorPinoyLiveBigWinner
//LiveMgr *LiveMgr
//dealerName []string // 主播名字
//betEndBetAreasOdds []*pb.ColorPinoyLiveGameBetAreaInfo // 下注结束后,每个区域更新是否爆奖
//afterBetAreaOdds []*pb.ColorPinoyLiveBetAreaOdd // 开奖后,更新每个区域的赔率(主要是单色投注区开奖后三个赔率变为1个赔率)
// ServerStatus int32
// wd *sync.WaitGroup
// TrendRedisKey string
// _aniLuckyDiceRouteIndex int32 // 幸运骰子动画路径
// _aniThreeDiceRouteIndex int32 // 3个骰子动画路径
// BigWinner []*pb.ColorPinoyLiveBigWinner
// LiveMgr *LiveMgr
// dealerName []string // 主播名字
// betEndBetAreasOdds []*pb.ColorPinoyLiveGameBetAreaInfo // 下注结束后,每个区域更新是否爆奖
// afterBetAreaOdds []*pb.ColorPinoyLiveBetAreaOdd // 开奖后,更新每个区域的赔率(主要是单色投注区开奖后三个赔率变为1个赔率)
}
func newColorRoom(id, roomType int, srv service.IService) (baseroom.IRoom, pb.ErrCode) {
rm := &ColorRoom{}
rm := &ColorRoom{
BaseRoom: nil,
roomCfg: game.ColorRoomConfig{},
timingCfg: game.ColorGameTiming{},
status: 0,
statusTime: 0,
jackpot: 0,
endBetAreaMul: make([]*pb.ColorBetAreaMul, 0, len(pb.ColorBetArea_name)),
}
playType := 0
code := pb.ErrCode_OK
rm.BaseRoom, code = baseroom.NewBaseRoom[ColorSeat](id, roomType, playType, srv)
@ -65,8 +77,17 @@ func newColorRoom(id, roomType int, srv service.IService) (baseroom.IRoom, pb.Er
func (rm *ColorRoom) OnInit() {
rm.RegisterMessages(processor.RegisterMetas{
pb.MsgId_C2SMatchRoomId: {pb.C2SMatchRoom{}, rm.OnEnterRoom},
pb.MsgId_ReqMatchRoomId: {pb.ReqMatchRoom{}, rm.OnEnterRoom},
})
rm.RegisterTimerMessages(processor.RegisterTimerMetas{
TtGameStart: rm.gameStart,
TtStartBetting: rm.startBetting,
TtEndBet: rm.endBetting,
TtOpenThreeDices: rm.openThreeDices,
TtSettle: rm.settle,
})
rm.gameStart()
return
}
@ -86,22 +107,22 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// ---------------------------------------------------------------------------------------------------
//
//const (
// const (
// BigWinnerCount = 6
// GameName = "ColorPinoyLive"
//)
// )
//
//func (rm *ColorRoom) SetGameStatus(status pb.ColorPinoyLiveGameStatus) {
// func (rm *ColorRoom) SetGameStatus(status pb.ColorPinoyLiveGameStatus) {
// rm.Status = status
// rm.StatusTime = time.Now().UnixMilli()
// log.DebugF(rm.Log("设置房间状态:%v", status))
//}
//func (rm *ColorRoom) GetGameStatus() pb.ColorPinoyLiveGameStatus {
// }
// func (rm *ColorRoom) GetGameStatus() pb.ColorPinoyLiveGameStatus {
// return rm.Status
//}
// }
//
//// 客户端显示赔率范围
//func (rm *ColorRoom) MulRangeConfig() []*pb.BetAreaMulRangeConfig {
// // 客户端显示赔率范围
// func (rm *ColorRoom) MulRangeConfig() []*pb.BetAreaMulRangeConfig {
// var mulRangeCfg []*pb.BetAreaMulRangeConfig
// for pos, mul := range rm.RoomCfg.WinSingleColorMul {
// if len(mul) > 0 {
@ -136,9 +157,9 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// log.Debug(rm.Log("pos:%v 赔率区间:%v-%v", pos, v.MinMul, v.MaxMul))
// }
// return mulRangeCfg
//}
// }
//
//func (rm *ColorRoom) InitBigOddsBetAreas() {
// func (rm *ColorRoom) InitBigOddsBetAreas() {
// if len(rm.betEndBetAreasOdds) == 0 {
// rm.betEndBetAreasOdds = make([]*pb.ColorPinoyLiveGameBetAreaInfo, 0, len(pb.ColorPinoyLiveBetTypeJP_name))
// }
@ -188,27 +209,27 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// for _, betArea := range rm.betEndBetAreasOdds {
// log.Debug(rm.Log("初始化投注区域:%v 倍率:%v 是否爆奖:%v 是否jackpot:%v", betArea.BetType, betArea.Odd, betArea.IsBigOdd, betArea.IsJackpot))
// }
//}
// }
//
//func (rm *ColorRoom) Log(format string, args ...any) string {
// func (rm *ColorRoom) Log(format string, args ...any) string {
// s := fmt.Sprintf(format, args...)
// head := fmt.Sprintf("gameno:%v ", rm.Table.GetGameRoundId())
// return head + s
//}
// }
//
//func (rm *ColorRoom) LogEx(user *model.User, format string, args ...any) string {
// func (rm *ColorRoom) LogEx(user *model.User, format string, args ...any) string {
// s := fmt.Sprintf(format, args...)
// head := fmt.Sprintf("gameno:%v user:%v", rm.Table.GetGameRoundId(), user.UserID)
// return head + s
//}
// }
//
//
//func (rm *ColorRoom) ResetConfigPrivate() bool {
// func (rm *ColorRoom) ResetConfigPrivate() bool {
// rm.RoomCfg = config.ResetConfigPrivate()
// rm.Cfg = &rm.RoomCfg.ColorPinoyLiveConfig
// return true
//}
//func (rm *ColorRoom) GetPlayer(userid int64) *model.User {
// }
// func (rm *ColorRoom) GetPlayer(userid int64) *model.User {
// user, ok := rm.AllUserList.Load(userid)
// if !ok {
// return nil
@ -218,17 +239,17 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// return nil
// }
// return player
//}
//func (rm *ColorRoom) AddPlayer(player *model.User) {
// }
// func (rm *ColorRoom) AddPlayer(player *model.User) {
// rm.AllUserList.Store(player.UserInetr.GetId(), player)
// rm.MutexUserList.Lock()
// rm.OnlineUserList = append(rm.OnlineUserList, player)
// rm.MutexUserList.Unlock()
//}
// }
//
//type TraverseFunc func(v *model.User) bool
// type TraverseFunc func(v *model.User) bool
//
//func (rm *ColorRoom) Traverse(f TraverseFunc) {
// func (rm *ColorRoom) Traverse(f TraverseFunc) {
// function := func(key, value interface{}) bool {
// if value != nil {
// us, ok := value.(*model.User)
@ -241,22 +262,22 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// return true
// }
// rm.AllUserList.Range(function)
//}
// }
//
//
//func (rm *ColorRoom) DeletePlayer(uid int64) {
// func (rm *ColorRoom) DeletePlayer(uid int64) {
// p := rm.GetPlayer(uid)
// if p != nil {
// rm.AllUserList.Delete(uid)
// rm.DeleteExitUserFromOnlineUserListSlice(p)
// }
//}
// }
//
//
//
//
//
//func (rm *ColorRoom) UserExit(user inter.UserInetr) bool {
// func (rm *ColorRoom) UserExit(user inter.UserInetr) bool {
// u := rm.getUser(user)
// // 有下注时不让玩家离开
// if u.TotalBet != 0 {
@ -264,8 +285,8 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// }
// rm.KickOutUser(u)
// return true
//}
//func (rm *ColorRoom) LeaveGame(user inter.UserInetr) bool {
// }
// func (rm *ColorRoom) LeaveGame(user inter.UserInetr) bool {
// u := rm.getUser(user)
// if u.TotalBet != 0 {
// // msg := new(pb.KickOutUserMsg)
@ -276,10 +297,10 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
//
// rm.KickOutUser(u)
// return true
//}
// }
//
//// 游戏消息
//func (rm *ColorRoom) OnGameMessage(subCmd int32, buffer []byte, user inter.UserInetr) {
// // 游戏消息
// func (rm *ColorRoom) OnGameMessage(subCmd int32, buffer []byte, user inter.UserInetr) {
// // log.Debug("收到客户端消息:", subCmd)
// switch pb.ColorPinoyLiveReceiveFromClientMessageType(subCmd) {
// case pb.ColorPinoyLiveReceiveFromClientMessageType_ColorPinoyLiveApplyRefresh:
@ -302,18 +323,18 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// case pb.ColorPinoyLiveReceiveFromClientMessageType_ColorPinoyLiveApplyLeave:
// monitor.GoSafe(rm.ApplyLeave, buffer, user)
// }
//}
// }
//
//func (rm *ColorRoom) initDefaultDiceGameRoundReady() {
// func (rm *ColorRoom) initDefaultDiceGameRoundReady() {
// // rm.DefaultLuckyDice = rm.GamePoker.ShuffleDices(1)[0]
// //
// // rm.DefaultNormalDices[0] = rm.GamePoker.ShuffleDices(1)[0]
// // rm.DefaultNormalDices[1] = rm.GamePoker.ShuffleDices(1)[0]
// // rm.DefaultNormalDices[2] = rm.GamePoker.ShuffleDices(1)[0]
//}
// }
//
//// 开lucky dice
//func (rm *ColorRoom) OpenLuckyDice() {
// // 开lucky dice
// func (rm *ColorRoom) OpenLuckyDice() {
//
// dealDice := rm.GetPairDice(1, 0, 1)
//
@ -323,10 +344,10 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// deck := model.GetInitialDeck()
// rm.LuckyDice = deck[dealDice[0]-1]
// }
//}
// }
//
//// 开3个普通 dice
//func (rm *ColorRoom) OpenThreeDice() {
// // 开3个普通 dice
// func (rm *ColorRoom) OpenThreeDice() {
//
// dealDice := rm.GetPairDice(3, 1, 4)
// if dealDice == nil || len(dealDice) < 3 {
@ -339,9 +360,9 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// rm.NormalDices[1] = deck[dealDice[1]-1]
// rm.NormalDices[2] = deck[dealDice[2]-1]
// }
//}
// }
//
//func (rm *ColorRoom) getUser(user inter.UserInetr) *model.User {
// func (rm *ColorRoom) getUser(user inter.UserInetr) *model.User {
// // u, ok := rm.AllUserList[user.GetId()]
// u := rm.GetPlayer(user.GetId())
// if u == nil {
@ -357,9 +378,9 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// }
//
// return u
//}
// }
//
//func (rm *ColorRoom) getRobotUser(user inter.UserInetr) *model.User {
// func (rm *ColorRoom) getRobotUser(user inter.UserInetr) *model.User {
// // u, ok := rm.AllUserList[user.GetId()]
// u := rm.GetPlayer(user.GetId())
// if u == nil {
@ -376,10 +397,10 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// }
//
// return u
//}
// }
//
//// 游戏开始入口.....
//func (rm *ColorRoom) GameStart() bool {
// // 游戏开始入口.....
// func (rm *ColorRoom) GameStart() bool {
// if rm.GetGameStatus() == 0 {
// rm.Ready()
// rm.SyncServerMaintenance(0, "")
@ -394,18 +415,18 @@ func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
// }
//
// return true
//}
// }
//
//func (rm *ColorRoom) GameRoundStart() {
// func (rm *ColorRoom) GameRoundStart() {
// rm.RoomCfg = config.ResetConfig()
// rm.Cfg = &rm.RoomCfg.ColorPinoyLiveConfig
// rm.ServerStatus = gconfig.GConfig.GServConfig.Status
//}
// }
//
//func (rm *ColorRoom) ResetTable() {
// func (rm *ColorRoom) ResetTable() {
// rm.SetGameStatus(0)
//}
// }
//
//// 关闭桌子
//func (rm *ColorRoom) CloseTable() {
//}
// // 关闭桌子
// func (rm *ColorRoom) CloseTable() {
// }

View File

@ -1,7 +1,131 @@
package room
import (
"game/common/config/game"
"game/common/proto/pb"
"github.com/fox/fox/log"
"github.com/fox/fox/xrand"
"github.com/fox/fox/xtime"
)
func (rm *ColorRoom) setStatus(status pb.ColorGameStatus) {
rm.status = status
rm.statusTime = xtime.Now().TimestampMilli()
}
// 状态结束时间点,毫秒
func (rm *ColorRoom) endTimeStatus() int64 {
duration := int64(0)
switch rm.status {
case pb.ColorGameStatus_CGS_Start:
duration = rm.timingCfg.Start
case pb.ColorGameStatus_CGS_Betting:
duration = rm.timingCfg.Betting
case pb.ColorGameStatus_CGS_BetEnd:
duration = rm.timingCfg.EndBetting
case pb.ColorGameStatus_CGS_OpenThreeDice:
duration = rm.timingCfg.OpenThreeDice
case pb.ColorGameStatus_CGS_Settle:
duration = rm.timingCfg.Settle
}
return rm.statusTime + duration
}
// 游戏开始时展示每个区域的默认赔率
func (rm *ColorRoom) initEndBetAreaMul() {
rm.endBetAreaMul = rm.endBetAreaMul[0:0]
for pos := 0; pos < len(pb.ColorBetArea_name); pos++ {
prizeArea := pb.ColorPrizeArea_CPA_Single_0
var mul = rm.roomCfg.WinSingleColorMul[0]
switch pos / 6 {
case 1:
prizeArea = pb.ColorPrizeArea_CPA_Double
mul = rm.roomCfg.WinDoubleColorMul
case 2:
prizeArea = pb.ColorPrizeArea_CPA_Three
mul = rm.roomCfg.WinThreeColorMul
}
rm.endBetAreaMul = append(rm.endBetAreaMul, &pb.ColorBetAreaMul{
Area: pb.ColorBetArea(pos),
PrizeArea: prizeArea,
PrizeType: pb.ColorPrizeType_CPT_Normal,
Mul: mul[0].Mul,
})
}
}
// 随机出某个奖励档位下的赔率数组,档位,赔率数组概率之和
func (rm *ColorRoom) randArrMul(area pb.ColorBetArea) (singleMul []*game.ColorMulRate, prizeArea pb.ColorPrizeArea, sumRate int) {
switch area / 6 {
case 0:
maxWeight := 0
for _, w := range rm.roomCfg.WinSingleColorWeight {
maxWeight += w
}
weight := xrand.RandRange[int](0, maxWeight)
case 1:
case 2:
default:
log.Error("area:%v is not exist")
return
}
// log.Debug(rm.Log("单色投注区获取爆奖在双色还是三色,随机值为:%v 最大值:%v", weight, maxWeight))
return nil, 0
}
// 下注结束后,更新每个区域的实际赔率
func (rm *ColorRoom) updateEndBetAreaMul() {
for pos, _ := range pb.ColorBetArea_name {
}
for pos, betArea := range rm.betEndBetAreasOdds {
log.Debug(rm.Log("区域:%v 随机前 爆奖状态:%v", pb.ColorPinoyLiveBetTypeJP(pos), betArea.IsBigOdd))
betArea.IsBigOdd = false
// 区域位置 0-2分别为单色、双色、三色投注区域
index := pos / 6
singlePos := 0
var mulRangeW []*MulRangeW
if index == 0 {
mulRangeW, singlePos = rm.randSingle(rm.Cfg)
} else {
mulRangeW = mulRangeWs[index+2]
}
if mulRangeW == nil {
log.Error(rm.Log("投注区域:%v 获取爆奖权重数组为nil", pos))
continue
}
rdv := rand.RandInt(mulRangeW[0].MinW, mulRangeW[len(mulRangeW)-1].MaxW)
for mulPos, mul := range mulRangeW {
if rdv < mul.MinW || rdv >= mul.MaxW {
continue
}
if index == 0 {
betArea.Odd[singlePos] = mul.Mul
if singlePos != 0 && mulPos != 0 {
log.Debug(rm.Log("区域:%v 爆奖位置:%v", pb.ColorPinoyLiveBetTypeJP(pos), mul.ColorPos))
betArea.IsBigOdd = true
}
} else {
betArea.Odd[0] = mul.Mul
if mulPos != 0 {
log.Debug(rm.Log("区域:%v 爆奖位置:%v", pb.ColorPinoyLiveBetTypeJP(pos), mul.ColorPos))
betArea.IsBigOdd = true
}
}
betArea.BigSingleColorOddPos = mul.ColorPos
break
}
log.Debug(rm.Log("区域:%v 爆奖权重区间:[%v,%v],随机数:%v betArea:%+v", pb.ColorPinoyLiveBetTypeJP(pos),
mulRangeW[0].MinW, mulRangeW[len(mulRangeW)-1].MaxW, rdv, betArea))
}
}
//
//import (
// import (
// "encoding/json"
// "fmt"
// "game/common/proto/pb"
@ -10,15 +134,15 @@ package room
// "sort"
// "sync"
// "time"
//)
// )
//
//func (rm *ColorRoom) SceneUserSitDown(user *model.User) {
// func (rm *ColorRoom) SceneUserSitDown(user *model.User) {
// _ = user
// rm.SendOnlinePlayerNum()
//}
// }
//
//// CheckAndBet 检查并下注
//func (rm *ColorRoom) CheckAndBet(user *model.User, bets []*pb.ColorPinoyLiveBetReq) {
// // CheckAndBet 检查并下注
// func (rm *ColorRoom) CheckAndBet(user *model.User, bets []*pb.ColorPinoyLiveBetReq) {
// if len(bets) == 0 {
// log.Error(rm.Log("玩家(%d) bets data err :%v ", bets))
// model.SendBetFailMessage(model.DataErr, user)
@ -121,9 +245,9 @@ package room
// Bet: totalBetAmount,
// Avatar: user.UserInetr.GetHead(),
// })
//}
// }
//
//func (rm *ColorRoom) UndoBet(user *model.User, undoType pb.ColorPinoyLiveUndoType) {
// func (rm *ColorRoom) UndoBet(user *model.User, undoType pb.ColorPinoyLiveUndoType) {
//
// betInfos := [config.BET_TYPE_NUM]int64{}
// betCountInfos := [config.BET_TYPE_NUM]int64{}
@ -222,8 +346,8 @@ package room
// // log.Debug("undoBetMessage %v", undoBetMessage)
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeUndoBet), undoBetMessage)
//
//}
//func (rm *ColorRoom) KickOutUser(u *model.User) {
// }
// func (rm *ColorRoom) KickOutUser(u *model.User) {
// // delete(rm.AllUserList, k)
// rm.DeletePlayer(u.UserID)
// if u.SceneChairId != 0 {
@ -237,8 +361,8 @@ package room
// }
// log.Debug(rm.Log("删除(%s(%d) 金额:%d 输赢:%d", role, u.UserID, u.Balance, u.Balance-u.UserInetr.GetScore()))
// rm.SendOnlinePlayerNum()
//}
//func (rm *ColorRoom) TransInoutGameBet(user *model.User, bet int64) error {
// }
// func (rm *ColorRoom) TransInoutGameBet(user *model.User, bet int64) error {
// if config.CHIPS_DEBUG {
// user.Balance -= bet
// return nil
@ -254,8 +378,8 @@ package room
// user.UserInetr.SetPreserve(transferInOutResp.Preserve)
// // time.Sleep(10 * time.Second)
// return nil
//}
//func (rm *ColorRoom) TransInoutGameEnd(user *model.User, bet int64, amountWin int64, tax int64) (int64, error) {
// }
// func (rm *ColorRoom) TransInoutGameEnd(user *model.User, bet int64, amountWin int64, tax int64) (int64, error) {
// if config.CHIPS_DEBUG || user.IsRobot {
// user.Balance += amountWin
// return amountWin, nil
@ -272,9 +396,9 @@ package room
// user.TransWin += amountWin
// // time.Sleep(10 * time.Second)
// return transferInOutResp.RealTransfer, nil
//}
// }
//
//func (rm *ColorRoom) ResetUserBet(user *model.User) {
// func (rm *ColorRoom) ResetUserBet(user *model.User) {
// rm.MutexData.Lock()
// for i, bet := range user.TotalBets {
// rm.TotalBets[i] -= bet
@ -286,9 +410,9 @@ package room
// user.TotalBets = [config.BET_TYPE_NUM]int64{}
// // user.BetNumber = [config.BET_TYPE_NUM]int64{}
//
//}
// }
//
//func (rm *ColorRoom) StartTransInoutBet() {
// func (rm *ColorRoom) StartTransInoutBet() {
// wg := new(sync.WaitGroup)
// var failUser []*model.User
// failMutx := &sync.Mutex{}
@ -377,10 +501,10 @@ package room
// if rm.jackpotX > 0 || rm.jackpotY > 0 {
// rm.kafkaJackpotUserRepaid(rm.jackpotX, rm.jackpotY)
// }
//}
// }
//
//// 计算 下注区域中奖得分返回是否有jp奖jp奖位置中奖人数
//func (rm *ColorRoom) CalculateJackpotScore() (pb.ColorPinoyLiveBetTypeJP, map[int64]int64) {
// // 计算 下注区域中奖得分返回是否有jp奖jp奖位置中奖人数
// func (rm *ColorRoom) CalculateJackpotScore() (pb.ColorPinoyLiveBetTypeJP, map[int64]int64) {
// jackpotArea := pb.ColorPinoyLiveBetTypeJP(-1)
// for _, winArea := range rm.PokerMsg.WinBetArea {
// if !winArea.IsJackpot || !winArea.IsWin {
@ -406,10 +530,10 @@ package room
// }
// log.Debug(rm.Log("本局是否中jackpot奖:%v, 玩家一起分走jackpot:%v, 当前jackpot值:%v", rm.costJackpot > 0, rm.costJackpot, rm.jackpotMgr.GetJackpot()))
// return jackpotArea, rm.jackpotUser
//}
// }
//
//// 计算 所有玩家的下注区域中奖得分
//func (rm *ColorRoom) CalculateAllUserScore() {
// // 计算 所有玩家的下注区域中奖得分
// func (rm *ColorRoom) CalculateAllUserScore() {
// // 赢钱会清空jackpot池
// jpArea, userJackPot := rm.CalculateJackpotScore()
// var jackpotUserName []string
@ -444,10 +568,10 @@ package room
// user.SettleMsg.JackpotUserName = jackpotUserName
// return true
// })
//}
// }
//
//// 计算 下注区域中奖得分
//func (rm *ColorRoom) CalculateScore(user *model.User, jpArea pb.ColorPinoyLiveBetTypeJP, jpScore int64, msg *pb.ColorPinoyLiveUserSettleMsg) {
// // 计算 下注区域中奖得分
// func (rm *ColorRoom) CalculateScore(user *model.User, jpArea pb.ColorPinoyLiveBetTypeJP, jpScore int64, msg *pb.ColorPinoyLiveUserSettleMsg) {
// for _, winArea := range msg.WinAreaOdd {
// if msg.UserBets[winArea.BetArea] <= 0 {
// continue
@ -489,15 +613,15 @@ package room
// }
// }
//
//}
// }
//
//type areaWin struct {
// type areaWin struct {
// areaId int64
// win int64
//}
// }
//
//// 更新大赢家
//func (rm *ColorRoom) updateBigWinner(allWinner []*pb.ColorPinoyLiveBigWinner) {
// // 更新大赢家
// func (rm *ColorRoom) updateBigWinner(allWinner []*pb.ColorPinoyLiveBigWinner) {
// // log.Debug(fmt.Sprintf("allWinner:%+v", allWinner))
// rm.BigWinner = rm.BigWinner[:0]
// sort.Slice(allWinner, func(i, j int) bool {
@ -525,10 +649,10 @@ package room
// }
// }
// rm.BigWinner = allWinner
//}
// }
//
//// 和平台做结算
//func (rm *ColorRoom) SetUserSettleMsg() {
// // 和平台做结算
// func (rm *ColorRoom) SetUserSettleMsg() {
// var allWinner []*pb.ColorPinoyLiveBigWinner
// rm.CalculateAllUserScore()
// wg := new(sync.WaitGroup)
@ -576,13 +700,13 @@ package room
// rm.TimerJob, _ = rm.Table.AddTimer(time.Duration(rm.RoomCfg.TimeConf.Endpay), func() {
// rm.Rank()
// })
//}
// }
//
//func (rm *ColorRoom) CountUser(u *model.User) {
// func (rm *ColorRoom) CountUser(u *model.User) {
// u.Icon = 0
// // rm.OnlineUserList = append(rm.OnlineUserList, u)
//}
//func (rm *ColorRoom) ResetData(all bool) {
// }
// func (rm *ColorRoom) ResetData(all bool) {
// rm.TotalBets = [config.BET_TYPE_NUM]int64{}
// rm.TotalBet = 0
// rm.LuckyDice = 0
@ -599,8 +723,8 @@ package room
// return true
// })
// }
//}
//func (rm *ColorRoom) GetPairDice(count int, startIndex int, endIndex int) []byte {
// }
// func (rm *ColorRoom) GetPairDice(count int, startIndex int, endIndex int) []byte {
// if gconfig.GConfig.IsProd() {
// return nil
// }
@ -639,9 +763,9 @@ package room
// }
// }
// return res
//}
// }
//
//func (rm *ColorRoom) GetGameTrend() (luckyRates []int32) {
// func (rm *ColorRoom) GetGameTrend() (luckyRates []int32) {
// // var mapLuckyRate = map[pb.ColorPinoyLiveDiceColorType]int32{}
// // for _, trend := range rm.GameTrend.ListTrendGroup {
// // mapLuckyRate[trend.LuckyDice]++
@ -660,9 +784,9 @@ package room
//
// return luckyRates
//
//}
// }
//
//func (rm *ColorRoom) SetGameTrend() {
// func (rm *ColorRoom) SetGameTrend() {
//
// trendGroup := new(pb.ColorPinoyLiveTrendGroup)
// trendGroup.LuckyDice = pb.ColorPinoyLiveDiceColorType(model.GetColor(rm.LuckyDice))
@ -687,10 +811,10 @@ package room
// // log.Debug("SetGameTrend 保存走势图到redis :", str)
//
// }
//}
// }
//
//// 获取投注区域的颜色
//func getColorByBetArea(area pb.ColorPinoyLiveBetTypeJP) pb.ColorPinoyLiveDiceColorType {
// // 获取投注区域的颜色
// func getColorByBetArea(area pb.ColorPinoyLiveBetTypeJP) pb.ColorPinoyLiveDiceColorType {
// switch area {
// case pb.ColorPinoyLiveBetTypeJP_CLJ_Yellow, pb.ColorPinoyLiveBetTypeJP_CLJ_Double_Yellow, pb.ColorPinoyLiveBetTypeJP_CLJ_Three_Yellow:
// return pb.ColorPinoyLiveDiceColorType_ColorPinoyLiveType_YELLOW
@ -706,9 +830,9 @@ package room
// return pb.ColorPinoyLiveDiceColorType_ColorPinoyLiveType_GREEN
// }
// return pb.ColorPinoyLiveDiceColorType_ColorPinoyLiveType_Void
//}
// }
//
//func getColorCount(result []byte, color pb.ColorPinoyLiveDiceColorType) int {
// func getColorCount(result []byte, color pb.ColorPinoyLiveDiceColorType) int {
// count := 0
// for _, c := range result {
// if model.GetColor(c) == int32(color) {
@ -716,18 +840,18 @@ package room
// }
// }
// return count
//}
// }
//
//func stringDices(result []byte) string {
// func stringDices(result []byte) string {
// s := ""
// for _, c := range result {
// s += fmt.Sprintf("%v", pb.ColorPinoyLiveDiceColorType(model.GetColor(c)))
// }
// return s
//}
// }
//
//// 检查投掷结果是否匹配某个下注区域
//func isWinningArea(result []byte, area pb.ColorPinoyLiveBetTypeJP) (win bool, bigPos pb.ColorPinoyLiveBigBetAreaPos, colorCount int) {
// // 检查投掷结果是否匹配某个下注区域
// func isWinningArea(result []byte, area pb.ColorPinoyLiveBetTypeJP) (win bool, bigPos pb.ColorPinoyLiveBigBetAreaPos, colorCount int) {
// color := getColorByBetArea(area)
// colorCount = getColorCount(result, color)
// if colorCount == 0 {
@ -752,10 +876,10 @@ package room
// }
// }
// return false, 0, colorCount
//}
// }
//
//// 计算开奖结果
//func (rm *ColorRoom) CompareDiceResult() {
// // 计算开奖结果
// func (rm *ColorRoom) CompareDiceResult() {
// var wins []*pb.ColorPinoyLiveBetAreaOdd
// // // 存储中奖区域
// result := rm.NormalDices
@ -831,10 +955,10 @@ package room
// betAreaOdd.ViewOdd, betAreaOdd.IsBigOdd, betAreaOdd.BigSingleColorOddPos))
// }
// rm.PokerMsg.WinBetArea = wins
//}
// }
//
//// 检查用户是否被踢掉
//func (rm *ColorRoom) checkUserBet() {
// // 检查用户是否被踢掉
// func (rm *ColorRoom) checkUserBet() {
// kickMsg, isKick := redisf.RSC.IsGameMaintenance(gconfig.GConfig.GRoomConfig.ChannelId, gconfig.GConfig.GServConfig.GameId)
// rm.Traverse(func(u *model.User) bool {
// u.NoBetCount++
@ -876,10 +1000,10 @@ package room
//
// return true
// })
//}
// }
//
//// 初始走势图
//func (rm *ColorRoom) InitWinTrend() {
// // 初始走势图
// func (rm *ColorRoom) InitWinTrend() {
// rm.TrendRedisKey = fmt.Sprintf("pb.:%d:%d:trend", gconfig.GConfig.GDataConfig.VersionMode, rm.RoomCfg.Level)
// if rm.ServerStatus == define.GameStatusNoraml {
// winTrend := redisf.RSC.GetColorGameTrend(rm.TrendRedisKey)
@ -901,9 +1025,9 @@ package room
//
// }
//
//}
// }
//
//func (rm *ColorRoom) DeleteExitUserFromOnlineUserListSlice(user *model.User) {
// func (rm *ColorRoom) DeleteExitUserFromOnlineUserListSlice(user *model.User) {
// rm.MutexUserList.Lock()
// defer rm.MutexUserList.Unlock()
// for k, v := range rm.OnlineUserList {
@ -912,9 +1036,9 @@ package room
// break
// }
// }
//}
// }
//
//func (rm *ColorRoom) SelectUserListBalanceTopSitDownChair() {
// func (rm *ColorRoom) SelectUserListBalanceTopSitDownChair() {
// rm.MutexUserList.Lock()
// rm.SceneInfo.ClearSceneChairId()
// rm.SceneInfo.Init()
@ -934,15 +1058,15 @@ package room
// }
// rm.MutexUserList.Unlock()
//
//}
// }
//
//func (rm *ColorRoom) CopyArr(arr [config.BET_TYPE_NUM]int64) []int64 {
// func (rm *ColorRoom) CopyArr(arr [config.BET_TYPE_NUM]int64) []int64 {
// slice := make([]int64, len(arr))
// copy(slice, arr[:])
// return slice
//}
// }
//
//func (rm *ColorRoom) GameDiscard() {
// func (rm *ColorRoom) GameDiscard() {
// rm.TimerJob.Cancel()
// rm.GameUserDiscard()
// // rm.TimerJob, _ = rm.Table.AddTimer(1000, func() {
@ -959,9 +1083,9 @@ package room
// return true
// })
// rm.Ready()
//}
// }
//
//func (rm *ColorRoom) sendUserMainte(user *model.User, cmd int32) {
// func (rm *ColorRoom) sendUserMainte(user *model.User, cmd int32) {
// userinfo := new(pb.ColorPinoyLiveUserInfo)
// userinfo.NikeName = user.UserInetr.GetNike()
// userinfo.UserGlod = user.Balance
@ -972,9 +1096,9 @@ package room
// MaintMsg: rm.LiveMgr.MainteMsg,
// ReturnGold: user.RetrunGold,
// })
//}
// }
//
//func (rm *ColorRoom) GameUserDiscard() {
// func (rm *ColorRoom) GameUserDiscard() {
// rm.MutexStatus.RLock()
// defer rm.MutexStatus.RUnlock()
// log.Debug(rm.Log("流局,状态:%v,分出去的jackpot:%v", rm.GetGameStatus(), rm.costJackpot))
@ -1089,18 +1213,18 @@ package room
// log.Error(rm.Log("[%s] fail to Produce TongitsGameEndEvent(%+v), err: %v", gameRecordData.GameNo, gameRecordData, err))
// }
// }()
//}
// }
//
//func (rm *ColorRoom) LoadDealerNames() {
// func (rm *ColorRoom) LoadDealerNames() {
// ssv := redisf.RSC.DealerNameGet(gconfig.GConfig.GDataConfig.VersionMode, gconfig.GConfig.GRoomConfig.GameId, GameName)
// var dealerNames []string
// _ = json.Unmarshal([]byte(ssv), &dealerNames)
// rm.dealerName = dealerNames
// log.Debug(rm.Log("dealerNames:%v", rm.dealerName))
//}
// }
//
//// 发送垫资kafka
//func (rm *ColorRoom) kafkaJackpotFunding(funding int64) {
// // 发送垫资kafka
// func (rm *ColorRoom) kafkaJackpotFunding(funding int64) {
// msg := &events.JackpotEvent{
// EventType: events.JackpotEvent_et_funding,
// GameId: rm.RoomCfg.GameId,
@ -1115,10 +1239,10 @@ package room
// }
// }()
// log.Debug(rm.Log("kafka 垫资:%v", funding))
//}
// }
//
//// 发送赎回及追加kafka
//func (rm *ColorRoom) kafkaJackpotUserRepaid(jpx, jpy int64) {
// // 发送赎回及追加kafka
// func (rm *ColorRoom) kafkaJackpotUserRepaid(jpx, jpy int64) {
// msg := &events.JackpotEvent{
// EventType: events.JackpotEvent_et_user_repaid,
// GameId: rm.RoomCfg.GameId,
@ -1133,10 +1257,10 @@ package room
// }
// }()
// log.Debug(rm.Log("kafka 赎回jpx:%v 追加jpy:%v", jpx, jpy))
//}
// }
//
//// 中jackpot分奖
//func (rm *ColorRoom) kafkaHitJackpot(jackpot int64, userJp map[int64]int64) {
// // 中jackpot分奖
// func (rm *ColorRoom) kafkaHitJackpot(jackpot int64, userJp map[int64]int64) {
// msg := &events.JackpotEvent{
// EventType: events.JackpotEvent_et_hit_jackpot,
// GameId: rm.RoomCfg.GameId,
@ -1151,9 +1275,9 @@ package room
// }
// }()
// log.Debug(rm.Log("kafka 中jackpot:%v", jackpot))
//}
// }
//
//func (rm *ColorRoom) kafkaBackJackpot(jackpot, jpx, jpy int64, userJp map[int64]int64) {
// func (rm *ColorRoom) kafkaBackJackpot(jackpot, jpx, jpy int64, userJp map[int64]int64) {
// userJp2 := make(map[int64]int64)
// for k, v := range userJp {
// userJp2[k] = -v
@ -1177,4 +1301,4 @@ package room
// }
// }()
// log.Debug(rm.Log("kafka 回退jackpot:%v jpx:%v jpy:%v", -jackpot, -jpx, -jpy))
//}
// }

View File

@ -1,14 +1,50 @@
package room
import (
"game/common/proto/pb"
"time"
)
func (rm *ColorRoom) gameStart() {
rm.setStatus(pb.ColorGameStatus_CGS_Start)
rm.notifyGameStart()
rm.NewTimer(TtStartBetting, time.Duration(rm.timingCfg.Start)*time.Millisecond)
}
func (rm *ColorRoom) startBetting() {
rm.setStatus(pb.ColorGameStatus_CGS_Betting)
rm.notifyBetting()
rm.NewTimer(TtEndBet, time.Duration(rm.timingCfg.Betting)*time.Millisecond)
}
func (rm *ColorRoom) endBetting() {
rm.setStatus(pb.ColorGameStatus_CGS_BetEnd)
rm.updateEndBetAreaMul()
rm.notifyEndBetting()
rm.NewTimer(TtOpenThreeDices, time.Duration(rm.timingCfg.EndBetting)*time.Millisecond)
}
func (rm *ColorRoom) openThreeDices() {
rm.setStatus(pb.ColorGameStatus_CGS_OpenThreeDice)
rm.notifyOpenThreeDice()
rm.NewTimer(TtSettle, time.Duration(rm.timingCfg.OpenThreeDice)*time.Millisecond)
}
func (rm *ColorRoom) settle() {
rm.setStatus(pb.ColorGameStatus_CGS_Settle)
rm.notifySettle()
rm.NewTimer(TtGameStart, time.Duration(rm.timingCfg.Settle)*time.Millisecond)
}
//
//import (
// import (
// "encoding/json"
// "game/common/proto/pb"
// "github.com/fox/fox/ipb"
// "time"
//)
// )
//
//func (rm *ColorRoom) Ready() {
// func (rm *ColorRoom) Ready() {
// rm.Table.ResetGameRoundId()
// rm.ResetData(true)
// rm.Table.EndGame()
@ -37,9 +73,9 @@ package room
// msg.StatusTime = int32(rm.RoomCfg.TimeConf.Startmove)
// msg.Jackpot = rm.jackpotMgr.GetJackpot()
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameReady), msg)
//}
// }
//
//func (rm *ColorRoom) Start() {
// func (rm *ColorRoom) Start() {
// rm.GameRoundStart()
// rm.InitBigOddsBetAreas()
// // 推送房间筹码选择规则
@ -56,9 +92,9 @@ package room
// // rm.jackpotMgr.Load(rm.Cfg.InitJackpot)
// msg.Jackpot = rm.jackpotMgr.GetJackpot()
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameStart), msg)
//}
// }
//
//func (rm *ColorRoom) StartBet() {
// func (rm *ColorRoom) StartBet() {
// rm.SetGameStatus(pb.ColorPinoyLiveGameStatus_ColorPinoyLiveBetStatus)
// rm.TimerJob, _ = rm.Table.AddTimer(time.Duration(rm.RoomCfg.TimeConf.Startbet), func() {
// rm.EndBet()
@ -71,9 +107,9 @@ package room
// msg.Jackpot = rm.jackpotMgr.GetJackpot()
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameStartBet), msg)
// // log.Debug("pb. 开始下注.....StartBet()")
//}
// }
//
//func (rm *ColorRoom) EndBet() {
// func (rm *ColorRoom) EndBet() {
// rm.SetGameStatus(pb.ColorPinoyLiveGameStatus_ColorPinoyLiveEndBetMovie)
// // 停止下注就扣钱
// rm.StartTransInoutBet()
@ -86,10 +122,10 @@ package room
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameEndBet), msg)
//
// // log.Debug("pb. 停止下注.....EndBet()")
//}
// }
//
//// 开3个 dice
//func (rm *ColorRoom) openThreeDice() {
// // 开3个 dice
// func (rm *ColorRoom) openThreeDice() {
// // log.Debug("aabb openThreeDice")
// rm.SetGameStatus(pb.ColorPinoyLiveGameStatus_ColorPinoyLiveOpenThreeDice)
// rm.Table.AddTimer(time.Duration(rm.RoomCfg.TimeConf.OpenThreeDice), func() {
@ -107,12 +143,12 @@ package room
// msg.Color = append(msg.Color, pb.ColorPinoyLiveDiceColorType(model.GetColor(dice)))
// }
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameOpenThreeDice), msg)
//}
// }
//
//// 结算
//func (rm *ColorRoom) Settle() {
// // 结算
// func (rm *ColorRoom) Settle() {
// // log.Debug("aabb 结算")
// rm.SetGameStatus(pb.ColorPinoyLiveGameStatus_ColorPinoyLiveSettleStatus)
// rm.endAt = time.Now().Unix()
// rm.SetUserSettleMsg()
//}
// }

View File

@ -1,7 +1,47 @@
package room
import "game/common/proto/pb"
func (rm *ColorRoom) notifyGameStart() {
ntf := &pb.NtfColorGameStart{
EndTime: rm.endTimeStatus(),
Jackpot: rm.jackpot,
}
rm.Broadcast(pb.MsgId_NtfColorGameStartId, ntf)
}
func (rm *ColorRoom) notifyBetting() {
ntf := &pb.NtfColorBetting{EndTime: rm.endTimeStatus()}
rm.Broadcast(pb.MsgId_NtfColorBettingId, ntf)
}
func (rm *ColorRoom) notifyEndBetting() {
ntf := &pb.NtfColorEndBetting{
EndTime: rm.endTimeStatus(),
AreaMul: rm.endBetAreaMul,
Jackpot: rm.jackpot,
}
rm.Broadcast(pb.MsgId_NtfColorEndBettingId, ntf)
}
func (rm *ColorRoom) notifyOpenThreeDice() {
ntf := &pb.NtfColorEndBetting{
// EndTime: rm.statusTime + rm.timingCfg.Start,
// Jackpot: 0,
}
rm.Broadcast(pb.MsgId_NtfColorOpenThreeDiceId, ntf)
}
func (rm *ColorRoom) notifySettle() {
ntf := &pb.NtfColorEndBetting{
// EndTime: rm.statusTime + rm.timingCfg.Start,
// Jackpot: 0,
}
rm.Broadcast(pb.MsgId_NtfColorOpenThreeDiceId, ntf)
}
//
//import (
// import (
// "encoding/json"
// "fmt"
// "game/common/config/game"
@ -11,10 +51,10 @@ package room
// "math"
// "sort"
// "time"
//)
// )
//
//// 发送场景消息
//func (rm *ColorRoom) SendSceneMsg(u *model.User) {
// // 发送场景消息
// func (rm *ColorRoom) SendSceneMsg(u *model.User) {
//
// rm.MutexUserList.RLock()
// defer rm.MutexUserList.RUnlock()
@ -141,9 +181,9 @@ package room
// // log.Debug("同步房间信息发送场景信息 msg:", msg)
// // log.Debug(msg)
// u.SendMsg(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameSync), msg)
//}
// }
//
//func (rm *ColorRoom) SendUserBet(u *model.User) {
// func (rm *ColorRoom) SendUserBet(u *model.User) {
// msg := new(pb.ColorPinoyLiveSceneBetInfo)
// msg.UserBets = u.TotalBets[:]
// msg.TotalBets = rm.TotalBets[:]
@ -155,9 +195,9 @@ package room
// msg.UserInfo.NikeName = u.UserInetr.GetNike()
// msg.UserInfo.Head = u.UserInetr.GetHead()
// _ = u.UserInetr.SendMsg(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameUserBet), msg)
//}
// }
//
//func (rm *ColorRoom) SendRuleInfo() {
// func (rm *ColorRoom) SendRuleInfo() {
// // 后台配置的下注档位信息
// msg := new(pb.ColorPinoyLiveRoomBetRuleMsg)
// for _, v := range rm.RoomCfg.ColorPinoyLiveConfig.BetList {
@ -170,14 +210,14 @@ package room
// msg.MulRangeConfig = rm.MulRangeConfig()
// // log.Debug("发送规则 2222 BroadcastRuleInfo:", msg)
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeRoomBetRuleMsg), msg)
//}
// }
//
//func (rm *ColorRoom) SendScene(user inter.UserInetr) bool {
// func (rm *ColorRoom) SendScene(user inter.UserInetr) bool {
// _ = user
// return true
//}
// }
//
//func (rm *ColorRoom) copyBetAreaOdds() []*pb.ColorPinoyLiveBetAreaOdd {
// func (rm *ColorRoom) copyBetAreaOdds() []*pb.ColorPinoyLiveBetAreaOdd {
// var betAreaMul []*pb.ColorPinoyLiveBetAreaOdd
// // 游戏下注区域倍率
// for _, areaOdds := range rm.afterBetAreaOdds {
@ -193,9 +233,9 @@ package room
// betAreaMul = append(betAreaMul, area)
// }
// return betAreaMul
//}
// }
//
//func (rm *ColorRoom) GameSync(user inter.UserInetr) {
// func (rm *ColorRoom) GameSync(user inter.UserInetr) {
// // 玩家加入 牌桌
// u := rm.getUser(user)
// rm.SendSceneMsg(u)
@ -204,10 +244,10 @@ package room
// rm.sendUserMainte(u, int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeGameMainte))
// }
// })
//}
// }
//
//// 向客户端发送结算消息
//func (rm *ColorRoom) sendSettleMsg2Client() {
// // 向客户端发送结算消息
// func (rm *ColorRoom) sendSettleMsg2Client() {
//
// MaxWinGold := int64(0)
// MaxWinUserID := int64(0)
@ -477,40 +517,40 @@ package room
// }
// }()
//
//}
// }
//
//func (rm *ColorRoom) SendOnlinePlayerNum() {
// func (rm *ColorRoom) SendOnlinePlayerNum() {
// msg := new(pb.ColorPinoyLiveS2COnlinePlayerNum)
// msg.Num = int64(len(rm.OnlineUserList))
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeOnlinePlayerNum), msg)
//}
// }
//
//func (rm *ColorRoom) SendRoomInfo() {
// func (rm *ColorRoom) SendRoomInfo() {
// // if rm.GetGameStatus() == 0 {
// // return
// // }
// // msg := new(pb.UpdateRoomInfoMsg)
// // msg.OnlineNum = int64(len(rm.OnlineUserList))
// // rm.Table.Broadcast(int32(pb.SendToClientMessageType_NoticeUpdateRoomInfo), msg)
//}
// }
//
//// 广播主播名字
//func (rm *ColorRoom) NotifyDealerName() {
// // 广播主播名字
// func (rm *ColorRoom) NotifyDealerName() {
// msg := new(pb.ColorPinoyLiveDealerName)
// msg.DealerName = rm.dealerName
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeDealerName), msg)
// log.Debug(rm.Log("NotifyDealerName:%v", msg))
//}
// }
//
//type MulRangeW struct {
// type MulRangeW struct {
// *game.ColorMulRate
// MinW int // 权重转换成数值区间
// MaxW int // 权重转换成数值区间
// ColorPos pb.ColorPinoyLiveBigBetAreaPos // 0:单色区域基础倍率 1:单色区域双色倍率 2:单色区域开三色倍率 3:双色区域 4:三色区域
//}
// }
//
//// 带有权重信息的五行倍率数组(单色单,单色双,单色三,双色,三色倍率数组)
//func (rm *ColorRoom) initMulRangeW() (mulRangeW [][]*MulRangeW) {
// // 带有权重信息的五行倍率数组(单色单,单色双,单色三,双色,三色倍率数组)
// func (rm *ColorRoom) initMulRangeW() (mulRangeW [][]*MulRangeW) {
// mulRangeW = make([][]*MulRangeW, 0, 5)
//
// for pos, mulWs := range rm.Cfg.WinSingleColorMul {
@ -543,10 +583,10 @@ package room
// }
//
// return mulRangeW
//}
// }
//
//// 返回单色投注区爆奖的权重数组及是爆在双色还是三色位置
//func (rm *ColorRoom) randSingle(cfg *config.ColorPinoyLiveConfig) (singleMul []*MulRangeW, singlePos int) {
// // 返回单色投注区爆奖的权重数组及是爆在双色还是三色位置
// func (rm *ColorRoom) randSingle(cfg *config.ColorPinoyLiveConfig) (singleMul []*MulRangeW, singlePos int) {
// maxWeight := 0
// for _, w := range cfg.WinSingleColorWeight {
// maxWeight += w
@ -576,10 +616,10 @@ package room
// return singleMul, pos
// }
// return nil, 0
//}
// }
//
//// 更新
//func (rm *ColorRoom) updateBetEndBetAreasOdds(mulRangeWs [][]*MulRangeW) {
// // 更新
// func (rm *ColorRoom) updateBetEndBetAreasOdds(mulRangeWs [][]*MulRangeW) {
// for pos, betArea := range rm.betEndBetAreasOdds {
// log.Debug(rm.Log("区域:%v 随机前 爆奖状态:%v", pb.ColorPinoyLiveBetTypeJP(pos), betArea.IsBigOdd))
// betArea.IsBigOdd = false
@ -623,9 +663,9 @@ package room
// // 更新jackpot标记
// _ = rm.randJackpotArea()
// return
//}
// }
//
//func (rm *ColorRoom) randJackpotArea() []pb.ColorPinoyLiveBetTypeJP {
// func (rm *ColorRoom) randJackpotArea() []pb.ColorPinoyLiveBetTypeJP {
// betAreaInfo := make(map[int]*pb.ColorPinoyLiveGameBetAreaInfo)
// for pos, betArea := range rm.betEndBetAreasOdds {
// betAreaInfo[pos] = betArea
@ -648,10 +688,10 @@ package room
// }
// }
// return nil
//}
// }
//
//// 区域爆奖
//func (rm *ColorRoom) NotifyBigBetAreaMul() {
// // 区域爆奖
// func (rm *ColorRoom) NotifyBigBetAreaMul() {
// mulRangeW := rm.initMulRangeW()
// rm.updateBetEndBetAreasOdds(mulRangeW)
//
@ -663,9 +703,9 @@ package room
// msg.BetAreas = rm.betEndBetAreasOdds
// rm.Table.Broadcast(int32(pb.ColorPinoyLiveSendToClientMessageType_ColorPinoyLiveNoticeBigOddBetArea), msg)
// log.Debug(rm.Log("ColorPinoyLiveNtfBigOddBetArea:%v", msg))
//}
// }
//
//func (rm *ColorRoom) formatScore(score int64) string {
// func (rm *ColorRoom) formatScore(score int64) string {
// s := float64(score / 100.0)
// numStr := fmt.Sprintf("%.2f", s)
//
@ -678,9 +718,9 @@ package room
// // }
// return numStr
// // return result
//}
// }
//
//func (rm *ColorRoom) BroadHitJackpot(user *model.User, jpScore int64) {
// func (rm *ColorRoom) BroadHitJackpot(user *model.User, jpScore int64) {
// go func() {
// req := &fmsg.ChatReq{
// Uid: user.UserID,
@ -702,4 +742,4 @@ package room
// log.Error(rm.Log("fail to Produce SingleMsgToLobbyEvent_mtl_chat, err: %v", err))
// }
// }()
//}
// }

View File

@ -0,0 +1,39 @@
package room
type TimerType int
const (
TtSecond TimerType = 5 // 每秒定时器
TtGameStart TimerType = 300
TtStartBetting TimerType = 305
TtEndBet TimerType = 310
TtOpenThreeDices TimerType = 315
TtSettle TimerType = 320
TtGameEnd TimerType = 325
)
func (t TimerType) Number() int32 {
return int32(t)
}
func (t TimerType) String() string {
switch t {
case TtSecond:
return "TtSecond"
case TtGameStart:
return "TtGameStart"
case TtStartBetting:
return "TtStartBetting"
case TtEndBet:
return "TtEndBet"
case TtOpenThreeDices:
return "TtOpenThreeDices"
case TtSettle:
return "TtSettle"
case TtGameEnd:
return "TtGameEnd"
}
return "unknown"
}