gamesink.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package gamelogic
  2. import (
  3. "math/rand"
  4. "time"
  5. "bet24.com/servers/games/luckyfruit_table/common"
  6. "bet24.com/servers/games/luckyfruit_table/config"
  7. "bet24.com/servers/insecureframe/frame"
  8. )
  9. var gs *gamesink
  10. func newGameSink() *gamesink {
  11. gs = new(gamesink)
  12. return gs
  13. }
  14. type gamesink struct {
  15. }
  16. func (gs *gamesink) GetServerPort() int {
  17. return config.Server.ServerPort
  18. }
  19. func (gs *gamesink) GetGameID() int {
  20. return common.GAMEID
  21. }
  22. func (gs *gamesink) GetGameName() string {
  23. return common.GAME_NAME
  24. }
  25. func (gs *gamesink) GetRoomName() string {
  26. return config.Server.ServerName
  27. }
  28. func (gs *gamesink) CreateTableSink(table frame.Table, data string) frame.TableSink {
  29. return newTableSink(table, data)
  30. }
  31. func (gs *gamesink) GetOfflineSeconds() int64 {
  32. return 0
  33. }
  34. func (gs *gamesink) GetCertFile() string {
  35. return config.Server.CertFile
  36. }
  37. func (gs *gamesink) GetKeyFile() string {
  38. return config.Server.KeyFile
  39. }
  40. func (gs *gamesink) GetServerAddr() string {
  41. return config.Rooms.Rooms[0].ServerIP
  42. }
  43. func (gs *gamesink) GetRobotCount() int {
  44. if len(config.Rooms.Rooms[0].RobotConfig) == 0 {
  45. return 0
  46. }
  47. max := 0
  48. for _, v := range config.Rooms.Rooms[0].RobotConfig {
  49. if v.CountMax > max {
  50. max = v.CountMax
  51. }
  52. }
  53. return max
  54. }
  55. func (gs *gamesink) GetRobotGoldLimit() (min, max int) {
  56. if len(config.Rooms.Rooms[0].RobotConfig) == 0 {
  57. return 0, 0
  58. }
  59. hour := time.Now().Hour()
  60. for _, v := range config.Rooms.Rooms[0].RobotConfig {
  61. if gs.isBetween(hour, v.HourStart, v.HourEnd) {
  62. min, max = v.GoldMin, v.GoldMax
  63. return
  64. }
  65. }
  66. min, max = config.Rooms.Rooms[0].RobotConfig[0].GoldMin, config.Rooms.Rooms[0].RobotConfig[0].GoldMax
  67. return
  68. }
  69. func (gs *gamesink) GetRobotOnlineSec() int {
  70. if len(config.Rooms.Rooms[0].RobotConfig) == 0 {
  71. return 0
  72. }
  73. hour := time.Now().Hour()
  74. for _, v := range config.Rooms.Rooms[0].RobotConfig {
  75. if gs.isBetween(hour, v.HourStart, v.HourEnd) {
  76. return v.Online
  77. }
  78. }
  79. return config.Rooms.Rooms[0].RobotConfig[0].Online
  80. }
  81. func (gs *gamesink) GetRoomDatas() []string {
  82. var ret []string
  83. for _, v := range config.Rooms.Rooms {
  84. ret = append(ret, v.RoomName)
  85. }
  86. return ret
  87. }
  88. func (gs *gamesink) GetMinRoomCount(roomData string) int {
  89. for _, v := range config.Rooms.Rooms {
  90. if roomData == v.RoomName {
  91. return v.MinRoom
  92. }
  93. }
  94. return 0
  95. }
  96. func (gs *gamesink) GetRoomRobotCount(roomName string) int {
  97. for _, v := range config.Rooms.Rooms {
  98. if roomName != v.RoomName {
  99. continue
  100. }
  101. hour := time.Now().Hour()
  102. for _, v1 := range v.RobotConfig {
  103. if gs.isBetween(hour, v1.HourStart, v1.HourEnd) {
  104. return gs.getRandom(v1.CountMin, v1.CountMax)
  105. }
  106. }
  107. }
  108. return 0
  109. }
  110. func (gs *gamesink) GetRoomRobotGoldLimit(roomName string) (min, max int) {
  111. for _, v := range config.Rooms.Rooms {
  112. if roomName != v.RoomName {
  113. continue
  114. }
  115. hour := time.Now().Hour()
  116. for _, v1 := range v.RobotConfig {
  117. if gs.isBetween(hour, v1.HourStart, v1.HourEnd) {
  118. return v1.GoldMin, v1.GoldMax
  119. }
  120. }
  121. }
  122. return 0, 0
  123. }
  124. func (gs *gamesink) IsChipRoom() bool {
  125. return config.Server.IsChipRoom
  126. }
  127. func (gs *gamesink) OnPlatformConfig(key string) {
  128. config.OnConfigChanged(key)
  129. }
  130. func (gs *gamesink) IsPrivateRoom() bool {
  131. return config.Server.IsPrivateRoom
  132. }
  133. func (gs *gamesink) GetChairCount() int {
  134. return 1
  135. }
  136. func (gs *gamesink) getRandom(min, max int) int {
  137. if min >= max {
  138. return min
  139. }
  140. return min + rand.Intn(max-min)
  141. }
  142. func (gs gamesink) isBetween(p, min, max int) bool {
  143. return p >= min && p <= max
  144. }
  145. func (gs *gamesink) GetRoomLevel(data string) int {
  146. return 0
  147. }
  148. func (gs *gamesink) GetVersionID() int {
  149. return config.Server.VersionID
  150. }