|
- local CoinData = import("luaScript.Views.Coin.Data.CoinData");
- local CoinMessage = import("luaScript.Protocol.Coin.CoinMessage");
- local CoinGameLogic = {}
-
- CoinGameLogic.curGameId = nil;
- CoinGameLogic.curGameRule = nil;
-
- --- CoinGameLogic.enterCoinGame 进入金币场
- -- @param gameId 游戏ID
- -- @param gameRule 游戏规则
- -- @param level 场次
- -- @param money 金币
- function CoinGameLogic.requestEnterCoinGame(gameId, gameRule, level, money)
- logD("CoinGameLogic.enterCoinGame", "gameId:", gameId)
- logD("CoinGameLogic.enterCoinGame", "gameRule:", gameRule)
- if not (gameId and gameRule) then
- return
- end
-
- local gameData = CoinData.getInstance():getGameData()
- if not gameData then
- logE("CoinGameLogic.enterCoinGame", "金币场数据不存在")
- return
- end
-
- if not gameData.ruleList then
- logE("CoinGameLogic.enterCoinGame", "玩法规则不存在 - 1", gameId)
- return
- end
-
- local gameRuleList = gameData.ruleList[tonumber(gameId)]
- if not gameRuleList then
- logE("CoinGameLogic.enterCoinGame", "玩法规则不存在 - 2", gameId)
- return
- end
-
- CoinGameLogic.curGameId = gameId;
- CoinGameLogic.curGameRule = gameRule;
-
- local limit = money
- local serverLevel = level
- local coinNum = app.user.loginInfo.curJingbiNum
-
- --快速加入计算可以我能进入的最大的那个金币场
- if not level and not money then
- local tt = {}
- --查同个游戏里同个规则的金币场
- for k, v in pairsByKeys(gameRuleList) do
- local first = string.sub(k, 0, 1)
- local second = string.sub(k, -1)
- first = tonumber(first)
- second = tonumber(second)
- if second == tonumber(gameRule) then
- tt[k] = v
- end
- end
- --查我能进入的最大的那个金币场
- local lastMoney = 0
- local lastLevel = 0
- for k, v in pairsByKeys(tt) do
- if v.min_money > tonumber(coinNum) then
- break
- end
- if tonumber(k) > tonumber(lastLevel) then
- lastMoney = v.min_money
- lastLevel = k
- end
- end
- limit = lastMoney
- serverLevel = lastLevel
- end
-
- if limit == 0 or serverLevel == 0 or tonumber(limit) > tonumber(coinNum) then
- --[[ if serverLevel == 0 then
- serverLevel = 11 --如果没有就弹出初级场
- end
- local view = import("luaScript.Views.Coin.CoinDuiHuan"):new(gameId, tonumber(serverLevel))
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)--]]
-
- local first = serverLevel
- if serverLevel == 0 then
- first = "1"..CoinGameLogic.curGameRule
- end
- local function showCoinDuiHuan()
- local view = import("luaScript.Views.Coin.CoinDuiHuan"):new(gameId,toNumber(first))
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
-
- if app.config.ModuleConfig.IsSupportCoinFreeCoin then
- local activityData = CoinData.getInstance():getGameActivityData()
- if activityData then
- if activityData.shareFreeTimes > 0 and tonumber(coinNum) < 500 then
- local view = import("luaScript.Views.Coin.Views.CoinFreeCoin"):new(true)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- else
- showCoinDuiHuan()
- end
- else
- CoinData.getInstance():requestCoinGameActivity();
- end
- else
- showCoinDuiHuan()
- end
- else
- logD("CoinGameLogic.enterCoinGame", "请求进入金币场。。。")
- local tt = {}
- tt.userInfo = app.user.userInfo
- tt.serverLevel = tonumber(serverLevel)
- tt.gameid = tonumber(gameId)
- app.coinProtocol:requestEnterCoinRoom(tt)
- app:changeGameProtocol(tonumber(gameId), tonumber(gameRule), PROTOCOL_TYPE.COIN)
- end
- end
-
- --- CoinGameLogic:onEnterCoinGameResponse 进入金币场回复
- -- @param data
- function CoinGameLogic.onEnterCoinGameResponse(data)
- if not data then
- return
- end
- local response = data.response
- local ret = response.ret
- if ret == 0 then
- logD("CoinGameLogic:onEnterCoinGameResponse", "快速加入金币场正常")
- else
- local errString = ENTER_ROOM_RET_STR[ret] or "房间不存在"
- showTooltip(errString)
- return
- end
- app:changeGameProtocol(tonumber(CoinGameLogic.curGameId), toNumber(CoinGameLogic.curGameRule), PROTOCOL_TYPE.COIN)
- end
-
- return CoinGameLogic
|