2a6fe9a1-a83a-4293-9dc7-6ca56b5267ac.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. "use strict";
  2. cc._RF.push(module, '2a6femhqDpCk53HbKVrUmes', 'GameMgr');
  3. // scripts/Framework/GameMgr.ts
  4. "use strict";
  5. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  6. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  7. return new (P || (P = Promise))(function (resolve, reject) {
  8. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  9. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  10. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  11. step((generator = generator.apply(thisArg, _arguments || [])).next());
  12. });
  13. };
  14. var __generator = (this && this.__generator) || function (thisArg, body) {
  15. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  16. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  17. function verb(n) { return function (v) { return step([n, v]); }; }
  18. function step(op) {
  19. if (f) throw new TypeError("Generator is already executing.");
  20. while (_) try {
  21. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  22. if (y = 0, t) op = [op[0] & 2, t.value];
  23. switch (op[0]) {
  24. case 0: case 1: t = op; break;
  25. case 4: _.label++; return { value: op[1], done: false };
  26. case 5: _.label++; y = op[1]; op = [0]; continue;
  27. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  28. default:
  29. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  30. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  31. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  32. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  33. if (t[2]) _.ops.pop();
  34. _.trys.pop(); continue;
  35. }
  36. op = body.call(thisArg, _);
  37. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  38. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  39. }
  40. };
  41. Object.defineProperty(exports, "__esModule", { value: true });
  42. var GameCtr_1 = require("./GameCtr");
  43. var CocosZ_1 = require("./CocosZ");
  44. var Constant_1 = require("./Constant");
  45. var Msg_1 = require("./Msg");
  46. var Utils_1 = require("../../common-plugin/Scripts/Utils");
  47. var YZ_Constant_1 = require("../../common-plugin/Scripts/YZ_Constant");
  48. var YZ_LocalStorage_1 = require("../../common-plugin/Scripts/YZ_LocalStorage");
  49. // @ts-ignore
  50. var i18n = require('LanguageData');
  51. /**
  52. * 游戏管理
  53. */
  54. var GameMgr = /** @class */ (function () {
  55. function GameMgr() {
  56. this._state = Constant_1.GameState.None;
  57. this._gameCtr = new GameCtr_1.default();
  58. this.gameStartTime = 0;
  59. this.canTry = true;
  60. this.canGame = true;
  61. }
  62. Object.defineProperty(GameMgr, "inst", {
  63. get: function () {
  64. if (!GameMgr._inst) {
  65. GameMgr._inst = new GameMgr();
  66. }
  67. return GameMgr._inst;
  68. },
  69. enumerable: false,
  70. configurable: true
  71. });
  72. Object.defineProperty(GameMgr.prototype, "State", {
  73. get: function () {
  74. return this._state;
  75. },
  76. set: function (value) {
  77. this._state = value;
  78. },
  79. enumerable: false,
  80. configurable: true
  81. });
  82. ;
  83. Object.defineProperty(GameMgr.prototype, "gameCtr", {
  84. get: function () {
  85. return this._gameCtr;
  86. },
  87. enumerable: false,
  88. configurable: true
  89. });
  90. /**
  91. * 开始游戏
  92. * @param 关卡ID
  93. */
  94. GameMgr.prototype.gameStart = function (levelId) {
  95. return __awaiter(this, void 0, void 0, function () {
  96. var rangeLevel;
  97. return __generator(this, function (_a) {
  98. console.log('zh:GM.TS gameStart');
  99. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_RED_BAG_PROGRESS, '0');
  100. CocosZ_1.cocosz.curLevel = levelId;
  101. // 重置
  102. if (this.canTry) {
  103. this.canTry = false;
  104. this.gameCtr.curUseSkinId = -1;
  105. // 能否弹试用
  106. if (CocosZ_1.cocosz.isShowAd && CocosZ_1.cocosz.isADON && (CocosZ_1.cocosz.isDeBug || Utils_1.utils.isShowTrySkin(levelId))) {
  107. rangeLevel = CocosZ_1.cocosz.dataMgr.getGunInfo(CocosZ_1.cocosz.dataMgr.CurRange).Level;
  108. if (Math.random() < 0.5 && (rangeLevel < 3)) {
  109. // 武器升级弹窗
  110. CocosZ_1.cocosz.uiMgr.openPanel(Constant_1.PanelName.UIWeaponLevelPanel);
  111. }
  112. else {
  113. // 皮肤试用弹窗
  114. CocosZ_1.cocosz.uiMgr.openPanel(Constant_1.PanelName.UITrySkinPanel);
  115. }
  116. }
  117. // 进入游戏
  118. else if (this.canGame) {
  119. this.canGame = false;
  120. this._loadGameScene();
  121. }
  122. }
  123. // 能否进入游戏
  124. else if (this.canGame) {
  125. this.canGame = false;
  126. this._loadGameScene();
  127. }
  128. return [2 /*return*/];
  129. });
  130. });
  131. };
  132. GameMgr.prototype._loadGameScene = function () {
  133. var _this = this;
  134. // 使用皮肤
  135. if (this.gameCtr.curUseSkinId < 0) {
  136. this.gameCtr.curUseSkinId = CocosZ_1.cocosz.dataMgr.CurSkinId;
  137. }
  138. //上报游戏开始
  139. Utils_1.utils.StartGame(CocosZ_1.cocosz.getLevelId().toString());
  140. //进入游戏场景
  141. CocosZ_1.cocosz.sceneMgr.loadScene("Game", function () {
  142. _this.gameStartTime = new Date().getTime();
  143. _this.canTry = true;
  144. _this.canGame = true;
  145. _this._gamePrepare();
  146. //显示过度页面
  147. CocosZ_1.cocosz.uiMgr.openPage(Constant_1.PageName.UIGameLoadingPage);
  148. });
  149. };
  150. /** 游戏预加载 */
  151. GameMgr.prototype._gamePrepare = function () {
  152. try {
  153. this.State = Constant_1.GameState.Prepare;
  154. //调用游戏初始化
  155. this.gameCtr.init();
  156. }
  157. catch (error) {
  158. cc.error("erro >>", error);
  159. // 资源没有准备好, 无法进入游戏
  160. CocosZ_1.cocosz.sceneMgr.loadScene("Home", function () {
  161. CocosZ_1.cocosz.uiMgr.openPage(Constant_1.PageName.UIHomePage);
  162. Msg_1.default.Show(i18n.t("msg.net_error")); //当前网络状态不佳,请重启游戏
  163. });
  164. }
  165. };
  166. /** 游戏胜利 */
  167. GameMgr.prototype.gameSuccess = function () {
  168. cc.log('游戏胜利!');
  169. this.State = Constant_1.GameState.Success;
  170. CocosZ_1.cocosz.audioMgr.playEffectWinner();
  171. // 上报游戏时间
  172. var gameTime = Math.round((new Date().getTime() - this.gameStartTime) / 1000 / 60);
  173. Utils_1.utils.SendEvent("游戏时间:" + gameTime + "分钟");
  174. //保存关卡解锁数据
  175. var rewardCallFunc = function (res) {
  176. cc.log("获取激励组件奖励+" + res.rewardValue);
  177. if (res) {
  178. CocosZ_1.cocosz.dataMgr.CoinCount += res.rewardValue;
  179. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_COIN_CHANGE });
  180. }
  181. };
  182. var closeCallFunc = function () {
  183. cc.log("激励组件关闭!!!!!!");
  184. CocosZ_1.cocosz.uiMgr.openPage(Constant_1.PageName.UIOverPage);
  185. };
  186. //显示结算前广告
  187. Utils_1.utils.adManager.showBeforGameOverAd(CocosZ_1.cocosz.getLevelId(), YZ_Constant_1.LevelStatus.GameWin, 100, closeCallFunc, rewardCallFunc);
  188. };
  189. /** 游戏失败 */
  190. GameMgr.prototype.gameFailed = function () {
  191. cc.log('游戏失败!');
  192. this.State = Constant_1.GameState.Failed;
  193. CocosZ_1.cocosz.audioMgr.playEffectFailed();
  194. // 上报游戏时间
  195. var gameTime = Math.round((new Date().getTime() - this.gameStartTime) / 1000 / 60);
  196. Utils_1.utils.SendEvent("游戏时间:" + gameTime + "分钟");
  197. var rewardCallFunc = function (res) {
  198. cc.log("获取激励组件奖励+" + res.rewardValue);
  199. if (res) {
  200. //保存奖励值到本地
  201. CocosZ_1.cocosz.dataMgr.CoinCount += res.rewardValue;
  202. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_COIN_CHANGE });
  203. }
  204. };
  205. var closeCallFunc = function () {
  206. cc.log("激励组件关闭!!!!!!");
  207. CocosZ_1.cocosz.uiMgr.openPage(Constant_1.PageName.UIOverPage);
  208. };
  209. Utils_1.utils.adManager.showBeforGameOverAd(CocosZ_1.cocosz.getLevelId(), YZ_Constant_1.LevelStatus.GameFail, 50, closeCallFunc, rewardCallFunc);
  210. };
  211. return GameMgr;
  212. }());
  213. exports.default = GameMgr;
  214. cc._RF.pop();