您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

187 行
4.7 KiB

  1. local GameAppBase = class("GameAppBase", cc.mvc.AppBase)
  2. function GameAppBase:ctor()
  3. GameAppBase.super.ctor(self);
  4. -- 保存所有配置
  5. self.config = require("luaScript.Config.Configs");
  6. --子游戏ID
  7. self.gameId = nil
  8. self.gameRule = nil
  9. --默认协议类型
  10. self.protocolType = PROTOCOL_TYPE.COMMON
  11. --子游戏协议
  12. self.room = nil
  13. -- 创建所有协议模块
  14. self:initAllProtocols()
  15. -- 初始化其他模块
  16. self:initModules()
  17. self:initOthers()
  18. end
  19. function GameAppBase:initAllProtocols()
  20. -- 非棋牌的审核版本,是不需要初始化各种协议的
  21. if isReviewWithMiniGame() then
  22. return
  23. end
  24. -- 网络层 - 连接配置服
  25. self.net = require("luaScript.Tools.NetGameServer"):new();
  26. -------------------- GameServer 协议 --------------------
  27. -- 服务器配置信息
  28. self.serverConfigs = require("luaScript.Protocol.Config.ProtocolConfig"):new(self.net)
  29. -- 用户协议
  30. self.user = require("luaScript.Protocol.ProtocolUser"):new(self.net);
  31. -- Hall
  32. self.hall = require("luaScript.Protocol.ProtocolHall"):new(self.net);
  33. -- 心跳协议
  34. self.heart = require("luaScript.Protocol.ProtocolHeart"):new(self.net);
  35. -------------------- PHP 协议 --------------------
  36. self.php = require("luaScript.Protocol.ProtocolPhp"):new()
  37. -- 商店协议
  38. self.phpShop = require("luaScript.Protocol.ProtocolPhpShop"):new()
  39. --茶馆
  40. self.club = require("luaScript.Protocol.Club.ClubProtocol"):new(self.net);
  41. --茶馆php
  42. self.club_php = require("luaScript.Protocol.Club.ClubProtocolPhp"):new(self.net);
  43. --茶馆战绩
  44. self.club_zhanji = require("luaScript.Protocol.ProtocolClubZhanji"):new(self.net);
  45. --大厅战绩
  46. self.allZhanji = require("luaScript.Protocol.ProtocolZhanJiGame"):new(-1, "zhanji_AllGame");
  47. -- 金币场
  48. self.coinProtocol = require("luaScript.Protocol.Coin.CoinProtocol"):new(self.net);
  49. -- 金币场php
  50. self.coinProtocolPhp = require("luaScript.Protocol.Coin.CoinProtocolPhp"):new(self.net);
  51. -- 比赛场
  52. self.match = require("luaScript.Protocol.Match.ProtocolMatch"):new(self.net)
  53. self.matchPhp = require("luaScript.Protocol.Match.ProtocolMatchPhp"):new(self.net)
  54. --红点消息管理器
  55. self.msgManager = require("luaScript.Tools.MessageManager"):new()
  56. --邮件php
  57. self.mail_php = require("luaScript.Protocol.Mail.MailProtocolPhp"):new()
  58. -- 战绩协议
  59. self.zhanji = {}
  60. end
  61. function GameAppBase:initModules()
  62. -- 非棋牌的审核版本,是不需要初始化各种协议的
  63. if isReviewWithMiniGame() then
  64. return
  65. end
  66. -- 子游戏配置
  67. self.subGameConfigManager = require("luaScript.SubGame.SubGameConfigManager"):new()
  68. -- 子游戏版本管理
  69. self.subGameManager = require("luaScript.SubGame.SubGameManager"):new()
  70. -- 管理本地的用户列表
  71. self.userManager = require("luaScript.User.UserManager"):new()
  72. -- 保存战绩中的所有玩家信息
  73. self.playerInfoManager = require("luaScript.Tools.PlayerInfoManager"):new()
  74. -- 创建插件
  75. self.plugin = require("luaScript.GlobalPlugin"):new();
  76. end
  77. -- 其他初始化
  78. function GameAppBase:initOthers()
  79. -- 系统设置
  80. self.systemSetting = require("luaScript.Protocol.ProtocolSystemSetting"):new();
  81. end
  82. --[[
  83. gameId : 游戏ID
  84. gameRule: 游戏玩法
  85. protocolType: 协议类型
  86. --]]
  87. function GameAppBase:changeGameProtocol(gameId, gameRule, protocolType)
  88. if not app.subGameManager:isInstaller(gameId) then
  89. showTooltip("游戏未安装")
  90. return
  91. end
  92. -- 记录
  93. self.gameId = gameId
  94. self.gameRule = gameRule
  95. self.protocolType = protocolType or PROTOCOL_TYPE.COMMON
  96. logD("GameAppBase:changeGameProtocol() ", gameId, gameRule)
  97. local protocolClass = getSubGameProtocolClass(gameId, gameRule, protocolType)
  98. if not protocolClass then
  99. logE(string.format("can not find protocolClass with id = %s, rule = %s", tostring(gameId), tostring(gameRule)))
  100. return
  101. end
  102. --如果是麻将 添加搜索路径 防止找不到路径问题
  103. local gameConfig=getSubGameConfig(gameId)
  104. if gameConfig and gameConfig.belongType==3 then
  105. MJFramework.Clean()
  106. elseif gameConfig and gameConfig.belongType==2 then
  107. ZPFramework.Clean()
  108. elseif gameConfig and gameConfig.belongType==1 then
  109. PKFramework.Clean()
  110. end
  111. -- 卸载旧的
  112. if self.room then
  113. self.room:unRegAll()
  114. self.room = nil
  115. end
  116. -- 加载新的
  117. logD("开始加载协议"..protocolClass)
  118. self.room = import(protocolClass):new(self.net);
  119. logD("加载协议完成")
  120. end
  121. function GameAppBase:addProtocolZhanJi(gameId)
  122. -- 加载战绩协议
  123. if not self.zhanji[gameId] then
  124. local protocolName = getSubGameProtocolZhanJi(gameId)
  125. if protocolName then
  126. self.zhanji[gameId] = import(protocolName):new()
  127. end
  128. end
  129. end
  130. -- 使用者请自行判断是否为空
  131. function GameAppBase:getProtocolZhanJi(gameId)
  132. return self.zhanji[gameId]
  133. end
  134. return GameAppBase;