combomatchconfig.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package combomatch
  2. import (
  3. "bet24.com/log"
  4. item "bet24.com/servers/micros/item_inventory/proto"
  5. "bet24.com/servers/micros/matches/handler/matchbase"
  6. "time"
  7. )
  8. type matchroundconfig struct {
  9. MatchType int
  10. Target int // 目标,淘汰赛
  11. WinnerCount int // 本轮晋级玩家
  12. EliminateScore int // 淘汰分数
  13. ShrinkSec int // 缩圈秒数
  14. ShrinkScore int // 缩圈淘汰分数
  15. ScorePercentToNextRound int // 本轮累积多少分数进入下一轮
  16. EleminateByScore bool
  17. }
  18. type matchconfig struct {
  19. MatchId int
  20. Name string
  21. Desc string
  22. GameId int
  23. GameName string
  24. GameRule string
  25. TotalUser int // 实际比赛人数,会根据最终报名人数改变
  26. TableUser int
  27. PlayTime int
  28. Rounds []matchroundconfig // 轮次组合
  29. EnrollFee []item.ItemPack
  30. Prizes []matchbase.Prize_config
  31. matchbase.Time_config
  32. EnrollMin int // 最小报名人数
  33. EnrollMax int // 最大报名人数
  34. // 扩展部分
  35. OnlineUser int
  36. TotalPrizeAmount int
  37. DailyFreeCount int // 每日免费次数
  38. LeftFreeCount int // 剩余免费次数
  39. RobotConfig *matchbase.Robot_config `json:",omitempty"`
  40. StartSec int `json:",omitempty"` // 多少秒后开始,只有预报名才有
  41. EnrollOpen bool // 当前是否可报名
  42. MatchIcon string `json:",omitempty"` // 比赛Icon,空表示没有
  43. }
  44. func (mc *matchconfig) getScorePercentToNext(round int) int {
  45. if round < 0 || round >= len(mc.Rounds) {
  46. return 0
  47. }
  48. return mc.Rounds[round].ScorePercentToNextRound
  49. }
  50. func (mc *matchconfig) isEleminateByScore(round int) bool {
  51. if round < 0 {
  52. round = 0
  53. }
  54. return mc.Rounds[round].EleminateByScore
  55. }
  56. func (mc *matchconfig) dump() {
  57. log.Release(" MatchId[%d],Name[%s],GameName[%s],TotalUser[%d],MinMax[%d,%d],TableUser[%d],PlayTime[%d],Fee%v,Prizes%v,Online[%d],TotalPrize[%d]",
  58. mc.MatchId, mc.Name, mc.GameName, mc.TotalUser, mc.EnrollMin, mc.EnrollMax, mc.TableUser, mc.PlayTime, mc.EnrollFee, mc.Prizes, mc.OnlineUser, mc.TotalPrizeAmount)
  59. for i := 0; i < len(mc.Rounds); i++ {
  60. log.Release(" Round[%d] Type[%d] WinnerCount[%d] [t:%d,e:%d,ssec:%d,sscore:%d]",
  61. i, mc.Rounds[i].MatchType, mc.Rounds[i].WinnerCount,
  62. mc.Rounds[i].Target, mc.Rounds[i].EliminateScore, mc.Rounds[i].ShrinkSec, mc.Rounds[i].ShrinkScore)
  63. }
  64. if mc.RobotConfig != nil {
  65. log.Release(" RobotConfig:%v", *mc.RobotConfig)
  66. }
  67. }
  68. func (mc *matchconfig) getPrizes(rank int) []item.ItemPack {
  69. var ret []item.ItemPack
  70. for _, v := range mc.Prizes {
  71. if v.Rank == rank {
  72. return v.Prize
  73. }
  74. }
  75. return ret
  76. }
  77. func (mc *matchconfig) calTotalPrize() {
  78. if len(mc.EnrollFee) == 0 {
  79. mc.DailyFreeCount = 0
  80. }
  81. mc.TotalPrizeAmount = 0
  82. for _, v := range mc.Prizes {
  83. mc.TotalPrizeAmount += v.GetPrizeValue()
  84. }
  85. // 如果不是预报名
  86. if !mc.IsPreEnroll() {
  87. mc.EnrollMin = mc.TotalUser
  88. mc.EnrollMax = mc.TotalUser
  89. }
  90. }
  91. func (mc *matchconfig) addOnline(add int) {
  92. mc.OnlineUser += add
  93. if mc.OnlineUser < 0 {
  94. mc.OnlineUser = 0
  95. }
  96. }
  97. func (mc *matchconfig) setLeftFreeCount(userId int) {
  98. mc.RobotConfig = nil
  99. mc.StartSec = mc.GetNextStartTime() - int(time.Now().Unix())
  100. mc.EnrollOpen = mc.IsInTime()
  101. if mc.DailyFreeCount == 0 {
  102. return
  103. }
  104. mc.LeftFreeCount = mc.DailyFreeCount - getFreeCountManager().getUserFreeCount(userId, mc.MatchId)
  105. }
  106. func (mc *matchconfig) getMatchType(round int) int {
  107. if round >= len(mc.Rounds) {
  108. log.Release("combomatchconfig.isSimpleMatch round >= len %d,%d", round, len(mc.Rounds))
  109. return matchbase.MatchType_Invalid
  110. }
  111. return mc.Rounds[round].MatchType
  112. }
  113. func (mc *matchconfig) getTarget(round int) int {
  114. if round >= len(mc.Rounds) {
  115. log.Release("combomatchconfig.getTarget round >= len %d,%d", round, len(mc.Rounds))
  116. return 0
  117. }
  118. return mc.Rounds[round].Target
  119. }
  120. func (mc *matchconfig) getWinnerCount(round int) int {
  121. if round >= len(mc.Rounds) {
  122. log.Release("combomatchconfig.getWinnerCount round >= len %d,%d", round, len(mc.Rounds))
  123. return 0
  124. }
  125. return mc.Rounds[round].WinnerCount
  126. }
  127. func (mc *matchconfig) getPointMatchParams(round int) (int, int, int, int) {
  128. if round >= len(mc.Rounds) {
  129. log.Release("combomatchconfig.getTarget round >= len %d,%d ", round, len(mc.Rounds))
  130. return 0, 0, 0, 0
  131. }
  132. return mc.Rounds[round].EliminateScore, mc.Rounds[round].ShrinkSec, mc.Rounds[round].ShrinkScore, mc.Rounds[round].WinnerCount
  133. }
  134. func (mc *matchconfig) getTotalRound() int {
  135. return len(mc.Rounds)
  136. }