You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.4 KiB

  1. local CoinData = import("luaScript.Views.Coin.Data.CoinData");
  2. local CoinMessage = import("luaScript.Protocol.Coin.CoinMessage");
  3. local CoinGameLogic = {}
  4. CoinGameLogic.curGameId = nil;
  5. CoinGameLogic.curGameRule = nil;
  6. --- CoinGameLogic.enterCoinGame 进入金币场
  7. -- @param gameId 游戏ID
  8. -- @param gameRule 游戏规则
  9. -- @param level 场次
  10. -- @param money 金币
  11. function CoinGameLogic.requestEnterCoinGame(gameId, gameRule, level, money)
  12. logD("CoinGameLogic.enterCoinGame", "gameId:", gameId)
  13. logD("CoinGameLogic.enterCoinGame", "gameRule:", gameRule)
  14. if not (gameId and gameRule) then
  15. return
  16. end
  17. local gameData = CoinData.getInstance():getGameData()
  18. if not gameData then
  19. logE("CoinGameLogic.enterCoinGame", "金币场数据不存在")
  20. return
  21. end
  22. if not gameData.ruleList then
  23. logE("CoinGameLogic.enterCoinGame", "玩法规则不存在 - 1", gameId)
  24. return
  25. end
  26. local gameRuleList = gameData.ruleList[tonumber(gameId)]
  27. if not gameRuleList then
  28. logE("CoinGameLogic.enterCoinGame", "玩法规则不存在 - 2", gameId)
  29. return
  30. end
  31. CoinGameLogic.curGameId = gameId;
  32. CoinGameLogic.curGameRule = gameRule;
  33. local limit = money
  34. local serverLevel = level
  35. local coinNum = app.user.loginInfo.curJingbiNum
  36. --快速加入计算可以我能进入的最大的那个金币场
  37. if not level and not money then
  38. local tt = {}
  39. --查同个游戏里同个规则的金币场
  40. for k, v in pairsByKeys(gameRuleList) do
  41. local first = string.sub(k, 0, 1)
  42. local second = string.sub(k, -1)
  43. first = tonumber(first)
  44. second = tonumber(second)
  45. if second == tonumber(gameRule) then
  46. tt[k] = v
  47. end
  48. end
  49. --查我能进入的最大的那个金币场
  50. local lastMoney = 0
  51. local lastLevel = 0
  52. for k, v in pairsByKeys(tt) do
  53. if v.min_money > tonumber(coinNum) then
  54. break
  55. end
  56. if tonumber(k) > tonumber(lastLevel) then
  57. lastMoney = v.min_money
  58. lastLevel = k
  59. end
  60. end
  61. limit = lastMoney
  62. serverLevel = lastLevel
  63. end
  64. if limit == 0 or serverLevel == 0 or tonumber(limit) > tonumber(coinNum) then
  65. --[[ if serverLevel == 0 then
  66. serverLevel = 11 --如果没有就弹出初级场
  67. end
  68. local view = import("luaScript.Views.Coin.CoinDuiHuan"):new(gameId, tonumber(serverLevel))
  69. view:setAnchorPoint(cc.p(0.5, 0.5))
  70. app:showWaitDialog(view)--]]
  71. local first = serverLevel
  72. if serverLevel == 0 then
  73. first = "1"..CoinGameLogic.curGameRule
  74. end
  75. local function showCoinDuiHuan()
  76. local view = import("luaScript.Views.Coin.CoinDuiHuan"):new(gameId,toNumber(first))
  77. view:setAnchorPoint(cc.p(0.5, 0.5))
  78. app:showWaitDialog(view)
  79. end
  80. if app.config.ModuleConfig.IsSupportCoinFreeCoin then
  81. local activityData = CoinData.getInstance():getGameActivityData()
  82. if activityData then
  83. if activityData.shareFreeTimes > 0 and tonumber(coinNum) < 500 then
  84. local view = import("luaScript.Views.Coin.Views.CoinFreeCoin"):new(true)
  85. view:setAnchorPoint(cc.p(0.5, 0.5))
  86. app:showWaitDialog(view)
  87. else
  88. showCoinDuiHuan()
  89. end
  90. else
  91. CoinData.getInstance():requestCoinGameActivity();
  92. end
  93. else
  94. showCoinDuiHuan()
  95. end
  96. else
  97. logD("CoinGameLogic.enterCoinGame", "请求进入金币场。。。")
  98. local tt = {}
  99. tt.userInfo = app.user.userInfo
  100. tt.serverLevel = tonumber(serverLevel)
  101. tt.gameid = tonumber(gameId)
  102. app.coinProtocol:requestEnterCoinRoom(tt)
  103. app:changeGameProtocol(tonumber(gameId), tonumber(gameRule), PROTOCOL_TYPE.COIN)
  104. end
  105. end
  106. --- CoinGameLogic:onEnterCoinGameResponse 进入金币场回复
  107. -- @param data
  108. function CoinGameLogic.onEnterCoinGameResponse(data)
  109. if not data then
  110. return
  111. end
  112. local response = data.response
  113. local ret = response.ret
  114. if ret == 0 then
  115. logD("CoinGameLogic:onEnterCoinGameResponse", "快速加入金币场正常")
  116. else
  117. local errString = ENTER_ROOM_RET_STR[ret] or "房间不存在"
  118. showTooltip(errString)
  119. return
  120. end
  121. app:changeGameProtocol(tonumber(CoinGameLogic.curGameId), toNumber(CoinGameLogic.curGameRule), PROTOCOL_TYPE.COIN)
  122. end
  123. return CoinGameLogic