GameController.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s =
  5. (this && this.__awaiter) ||
  6. function (t, n, r, l) {
  7. return new (r = r || Promise)(function (i, e) {
  8. function s(t) {
  9. try {
  10. a(l.next(t));
  11. } catch (t) {
  12. e(t);
  13. }
  14. }
  15. function o(t) {
  16. try {
  17. a(l.throw(t));
  18. } catch (t) {
  19. e(t);
  20. }
  21. }
  22. function a(t) {
  23. var e;
  24. t.done
  25. ? i(t.value)
  26. : ((e = t.value) instanceof r
  27. ? e
  28. : new r(function (t) {
  29. t(e);
  30. })
  31. ).then(s, o);
  32. }
  33. a((l = l.apply(t, n || [])).next());
  34. });
  35. };
  36. Object.defineProperty(i, "__esModule", {value: !0});
  37. const o = t("App"),
  38. a = t("GameText"),
  39. n = t("BaseController"),
  40. r = t("ViewManager"),
  41. l = t("QueueExecutor"),
  42. h = t("ControllerConst"),
  43. c = t("NotificationConst"),
  44. d = (t("ViewConst"), t("LayerManager"), t("SoundEffectConst")),
  45. u = (t("ADController"), t("ADManageBase"), t("BagController")),
  46. p = t("GuideController"),
  47. f = t("TipView"),
  48. g = t("BuffMgr"),
  49. m = t("GameConst"),
  50. _ = t("GameModel"),
  51. y = t("GlobalAttr"),
  52. v = t("CurrencyService"),
  53. U = t("MachineService"),
  54. Z = t("MapService"),
  55. C = t("GameUIView"),
  56. b = t("GameView"),
  57. S = t("HelperCatInfoView"),
  58. T = t("InviteHelperCatView");
  59. i.default = class extends n.default {
  60. constructor() {
  61. super(),
  62. (this.gameView = null),
  63. (this.gameScene = null),
  64. (this.nextSaveTime = Date.now() + 3e4),
  65. (this._model = null),
  66. (this.gameConf = null),
  67. (this.curViewId = null),
  68. o.default.ViewManager.register(19, {
  69. prefabName: "StageUpgradeView",
  70. zIndex: 100,
  71. controller: this,
  72. dir: "gameUI"
  73. }),
  74. o.default.ViewManager.register(21, {
  75. prefabName: "StageUpgradeTipView",
  76. zIndex: 50,
  77. controller: this,
  78. isNotShowLoad: !0,
  79. dir: "gameUI"
  80. }),
  81. o.default.ViewManager.register(20, {
  82. prefabName: "SwitchMapView",
  83. zIndex: 100,
  84. controller: this,
  85. dir: "gameUI"
  86. }),
  87. o.default.ViewManager.register(8, {
  88. prefabName: "SettingView",
  89. zIndex: 100,
  90. controller: this,
  91. dir: "gameUI"
  92. }),
  93. o.default.ViewManager.register(22, {
  94. prefabName: "AbilityView",
  95. zIndex: 100,
  96. controller: this,
  97. dir: "gameUI"
  98. }),
  99. //注册离线收入
  100. o.default.ViewManager.register(17, {prefabName: "IdleView", zIndex: 100, controller: this, dir: "gameUI"}),
  101. o.default.ViewManager.register(31, {
  102. prefabName: "CongratulationView",
  103. zIndex: 100,
  104. controller: this,
  105. dir: "gameUI"
  106. }),
  107. o.default.ViewManager.register(38, {
  108. prefabName: "GameLoadingView",
  109. zIndex: 100,
  110. controller: this,
  111. dir: "gameUI"
  112. }),
  113. o.default.ViewManager.register(54, {
  114. prefabName: "WorldMapView",
  115. zIndex: 100,
  116. controller: this,
  117. dir: "gameUI"
  118. }),
  119. o.default.ViewManager.register1(S.default.VIEW_INFO, this),
  120. o.default.ViewManager.register1(T.default.VIEW_INFO, this),
  121. o.default.ViewManager.register1(b.default.VIEW_INFO, this),
  122. o.default.ViewManager.register1(C.default.VIEW_INFO, this),
  123. this.setModel(new _.default(this)),
  124. this.initModuleEvent(),
  125. this.initProtocolEvents(),
  126. o.default.NotificationCenter.addListener(c.NotificationConst.INIT_GAME, this.initGame, this, 100);
  127. }
  128. destroy() {
  129. super.destroy();
  130. }
  131. initModuleEvent() {
  132. this.registerFunc(m.GameConst.GET_IDLE, this.getIdle, this),
  133. this.registerFunc(m.GameConst.ENTER_FB_MAP, this.onEnterFBMap, this),
  134. this.registerFunc(m.GameConst.EXIT_FB_MAP, this.onExitFBMap, this);
  135. }
  136. initProtocolEvents() {
  137. o.default.NotificationCenter.addListener(r.ViewManagerEvent.VIEW_IS_CLOSE, this.onViewClose, this),
  138. o.default.NotificationCenter.addListener(c.NotificationConst.ADD_OPEN_VIEW, this.onAddView, this),
  139. o.default.NotificationCenter.addListener(c.NotificationConst.PLAY_MONEY_ANI, this.onPlayGetMoneyAni, this),
  140. o.default.NotificationCenter.addListener(c.NotificationConst.MACHINE_UPDATE, this.onUpdateProgress, this),
  141. o.default.NotificationCenter.addListener(c.NotificationConst.ENTER_MAP, this.onEnterMap, this);
  142. }
  143. onUpdateIntegral(t) {}
  144. initGame() {
  145. return s(this, void 0, void 0, function* () {
  146. this._model.init(),
  147. (this.queueExecutor = new l.QueueExecutor()),
  148. o.default.Platform.isShowDebugUI() && o.default.ViewManager.open(6),
  149. o.default.NotificationCenter.removeListener(c.NotificationConst.INIT_GAME, this.initGame, this),
  150. (this.gameConf = o.default.ConfigManager.gameConf.game),
  151. (this.gameScene = o.default.SceneManager.getCurrScene()),
  152. cc.game.on(cc.game.EVENT_HIDE, this.onHide, this),
  153. cc.game.on(cc.game.EVENT_SHOW, this.onShow, this),
  154. (g.default.ins = new g.default()),
  155. o.default.NotificationCenter.dispatch(c.NotificationConst.INIT_GAME_FINISH),
  156. yield Z.default.ins.loadMap(this._model.getCurMapData().curId),
  157. o.default.ViewManager.open(4),
  158. this.registerFunc(m.GameConst.SAVE_DAVE, this.saveToServe, this),
  159. (this.nextSaveTime = Date.now() + 18e4),
  160. o.default.TimerManager.doTimer(2e3, 0, this.routine, this),
  161. o.default.SoundManager.playBg(d.SoundsDefine.BG_GROUND),
  162. this.checkIdle();
  163. });
  164. }
  165. onHide() {
  166. return s(this, void 0, void 0, function* () {
  167. this._model.setIdleTime(), this.saveToServe(), o.default.SoundManager.stopBg(), cc.director.pause();
  168. });
  169. }
  170. onShow() {
  171. return s(this, void 0, void 0, function* () {
  172. for (cc.director.resume(), o.default.SoundManager.playBg(d.SoundsDefine.BG_GROUND); ; ) {
  173. if (
  174. (o.default.EasyLoading.showLoading(),
  175. !(300 < Math.abs(o.default.DateUtils.secondNow() - this._model.getCurMapData().startIdleTime)) ||
  176. (yield o.default.Platform.getServerTime()))
  177. ) {
  178. (this.nextSaveTime = Date.now() + 18e4),
  179. o.default.EasyLoading.hideLoading(),
  180. o.default.SaveManage.checkIsNeedUpdateData(),
  181. this.checkIdle(),
  182. o.default.NotificationCenter.dispatch(c.NotificationConst.ON_SHOW),
  183. (o.default.GameDataMsr.playerInfo.timestamp = Math.floor(o.default.DateUtils.Now() / 1e3)),
  184. o.default.AnalyticMgr.activityLogin();
  185. break;
  186. }
  187. yield new Promise(t => {
  188. o.default.EasyLoading.hideLoading(),
  189. o.default.ViewManager.open(14, {
  190. curState: f.TIPSTATE.SURE,
  191. leftBtnText: a.GameText.getText(17),
  192. leftFunc: () => {
  193. setTimeout(() => {
  194. t();
  195. }, 100);
  196. },
  197. leftThisObj: this,
  198. title: "提示",
  199. tipsStr: a.GameText.getText(54)
  200. });
  201. });
  202. }
  203. });
  204. }
  205. routine(t) {
  206. Date.now() > this.nextSaveTime && this.saveToServe(), o.default.SaveManage.checkIsNeedUpdateData();
  207. }
  208. saveToServe() {
  209. o.default.Platform.saveData(), o.default.AnalyticMgr.activityLogout(), (this.nextSaveTime = Date.now() + 18e4);
  210. }
  211. onOpenView(t) {
  212. switch (t.viewId) {
  213. case 6:
  214. break;
  215. case 4:
  216. this.onUpdateProgress();
  217. }
  218. }
  219. onViewClose(t) {
  220. this.curViewId == t && this.queueExecutor.finishFunc();
  221. }
  222. onEntreStreet(t) {
  223. this.queueExecutor.reset();
  224. }
  225. onAddView(t, e) {
  226. this.queueExecutor.regist(() => {
  227. p.default.isGuide ? this.queueExecutor.finishFunc() : ((this.curViewId = t), e());
  228. }, this);
  229. }
  230. checkIdle() {
  231. if (this._model.getCurMapData().startIdleTime) {
  232. let t = o.default.DateUtils.secondNow() - this._model.getCurMapData().startIdleTime;
  233. var e;
  234. t > y.default.ins.offlineRewardMinTime &&
  235. (t > y.default.ins.offlineRewardMaxTime && (t = y.default.ins.offlineRewardMaxTime),
  236. (e = v.default.ins.getIdleMoney(t)) && o.default.ViewManager.open(17, t, e));
  237. }
  238. }
  239. getIdle(t, e = !1) {
  240. return s(this, void 0, void 0, function* () {
  241. if (e) {
  242. const e = yield o.default.ControllerManager.applyFunc(h.ControllerConst.AD, 0, 0);
  243. if (!e || 0 !== e.code) return;
  244. t *= 2;
  245. }
  246. v.default.ins.addMoneyByIdle(t),
  247. (this._model.getCurMapData().startIdleTime = 0),
  248. o.default.ViewManager.close(17),
  249. this.onPlayGetMoneyAni(u.CostType.coin, v.default.ins.getIdleMoney(t));
  250. });
  251. }
  252. onEnterMap() {
  253. this.onUpdateProgress(), o.default.ViewManager.close(21);
  254. }
  255. onEnterFBMap(t) {
  256. Z.default.ins.loadMap(t || this._model.getFBMapData().curId);
  257. }
  258. onExitFBMap(t) {
  259. Z.default.ins.loadMap(t || this._model.getMainMapData().curId);
  260. }
  261. onUpdateProgress() {
  262. const t = o.default.ViewManager.getView(4);
  263. t && t.updateProgress(U.default.ins.getMachinProgress());
  264. }
  265. onPlayGetMoneyAni(t, e, i) {
  266. const s = o.default.ViewManager.getView(4);
  267. s && s.playGetCoinAni(t % 20001, e, i);
  268. }
  269. };