common.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package common
  2. import (
  3. "fmt"
  4. "bet24.com/servers/games/masharie_table/config"
  5. userservices "bet24.com/servers/micros/userservices/proto"
  6. )
  7. const (
  8. GAMEID = 40
  9. GAME_NAME = "masharie"
  10. )
  11. const (
  12. GameState_Bet = iota
  13. GameState_Open
  14. GameState_Prizes
  15. )
  16. const (
  17. TIMERID_CHECKROBOT = iota
  18. )
  19. type UserSetScore struct {
  20. UserId int
  21. Score int
  22. }
  23. const (
  24. Invalid = iota
  25. Win
  26. Lose
  27. )
  28. var result_desc = []string{"n/a", "Win", "Lose"}
  29. type HandCards struct {
  30. Cards []int
  31. Project CardProject
  32. ProjectLength int
  33. MaxCard int
  34. }
  35. // 牌组 5组 默认情况下 最后组是庄家的牌
  36. type CardDeck struct {
  37. HandCards
  38. Ranking int //名次
  39. }
  40. type GameState struct {
  41. RoomName string
  42. SerialNumber int
  43. State int // 当前状态
  44. Sec int // 当前阶段已使用时间
  45. TrumpCard int // 主牌(投注阶段下发)
  46. BankerCards HandCards // 庄家手牌
  47. DiamondCards HandCards // 方块手牌
  48. ClubCards HandCards // 梅花手牌
  49. HeartCards HandCards // 红心手牌
  50. SpadeCards HandCards // 黑桃手牌
  51. AreaResult []int // 每个区域的开奖结果
  52. Historys []config.OpenHistory // 历史纪录
  53. UserCount int // 在线用户数
  54. TableUser ScoreUsers // 幸运星和赢金榜的玩家
  55. PrizePool int // 彩池
  56. PrizeArea int // 彩池区域
  57. //RichList []int // 富豪榜
  58. //BetList []int //下注榜
  59. Scores []UserSetScore // 结算阶段,广播所有人的分数,给桌面玩家或者自己头像飘分用
  60. BetCmds []Bet // 本局下注列表
  61. BankerInfo BankerInfo
  62. BankerSettle int // 庄家结算金额
  63. }
  64. type BankerProfile struct {
  65. UserId int
  66. NickName string
  67. FaceId int
  68. FaceUrl string
  69. VipLevel int
  70. VipExpire int
  71. Decorations []userservices.UserDecoration
  72. }
  73. // 上庄等待队列
  74. type BankerCandidate struct {
  75. BankerProfile
  76. Take int // 携带金币
  77. }
  78. type BankerInfo struct {
  79. BankerProfile
  80. Gold int // 庄家当前金币 系统庄为9999999999每局重置
  81. Score int // 输赢分数
  82. SetCount int // 局数
  83. Candidates []BankerCandidate // 等待上庄列表
  84. Tax int `json:"-"`
  85. }
  86. type BetBase struct {
  87. BetId int
  88. Amount int
  89. IsFree bool
  90. IsRobot bool `json:"-"`
  91. }
  92. type Bet struct {
  93. BetBase
  94. UserId int
  95. Index int // 添加一个索引,用于失败撤销
  96. }
  97. type Batch_Bet struct {
  98. UserId int
  99. Bets []BetBase
  100. }
  101. type RankingUser struct {
  102. UserId int
  103. Score int
  104. }
  105. // 是否相同下注类型
  106. func (b *Bet) IsSameBet(b2 *Bet) bool {
  107. return b.BetId == b2.BetId && b.IsFree == b2.IsFree
  108. }
  109. type BetRet struct {
  110. ErrorMsg string
  111. }
  112. type Result struct {
  113. Bet
  114. WinAmount int
  115. LoseAmount int
  116. AreaResult []int
  117. Tax int // 税收
  118. }
  119. type RecordInfo struct {
  120. Result
  121. SerialNumber int
  122. }
  123. type UserClear struct {
  124. RoomName string
  125. UserId int
  126. }
  127. // 连胜用户和累计下注用户
  128. type ScoreUser struct {
  129. UserId int
  130. NickName string
  131. FaceId int
  132. FaceUrl string
  133. VipLevel int
  134. VipExpire int
  135. Decorations []userservices.UserDecoration
  136. Amount int
  137. IsRobot bool `json:"-"`
  138. BetAmount int
  139. Info []int
  140. }
  141. type ScoreUsers struct {
  142. LuckyStarUsers []ScoreUser //幸运星
  143. PrizeLuckyStarUsers []ScoreUser
  144. WinGoldRankingUsers []ScoreUser
  145. BetGoldRankingUsers []ScoreUser
  146. }
  147. // 结算信息
  148. type SettleInfo struct {
  149. BetAmount int
  150. ActualBetAmount int //实际下注的,用于庄家结算
  151. WinAmount int
  152. ActualWinAmount int //实际赢金,用于庄家结算
  153. TaxAmount int //台费用于上报水池
  154. LoseAmount int
  155. TotalOdds float64
  156. BetDesc string
  157. ResultDesc string
  158. }
  159. func IsInTopN(rankList []ScoreUser, userId, n int) bool {
  160. for i, v := range rankList {
  161. if i >= n {
  162. break
  163. }
  164. if v.UserId == userId {
  165. return true
  166. }
  167. }
  168. return false
  169. }
  170. func GetRedisKey(key string) string {
  171. return fmt.Sprintf("%s:%s", GAME_NAME, key)
  172. }