MapService.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. e =
  6. (this && this.__decorate) ||
  7. function(t, e, i, s) {
  8. var o,
  9. a = arguments.length,
  10. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  11. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  12. else
  13. for (var r = t.length - 1; 0 <= r; r--)
  14. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  15. return 3 < a && n && Object.defineProperty(e, i, n), n;
  16. },
  17. o =
  18. (this && this.__awaiter) ||
  19. function(t, n, r, l) {
  20. return new(r = r || Promise)(function(i, e) {
  21. function s(t) {
  22. try {
  23. a(l.next(t));
  24. } catch (t) {
  25. e(t);
  26. }
  27. }
  28. function o(t) {
  29. try {
  30. a(l.throw(t));
  31. } catch (t) {
  32. e(t);
  33. }
  34. }
  35. function a(t) {
  36. var e;
  37. t.done ?
  38. i(t.value) :
  39. ((e = t.value) instanceof r ?
  40. e :
  41. new r(function(t) {
  42. t(e);
  43. })
  44. ).then(s, o);
  45. }
  46. a((l = l.apply(t, n || [])).next());
  47. });
  48. };
  49. Object.defineProperty(i, "__esModule", { value: !0 });
  50. const d = t("App"),
  51. a = t("GridLayer"),
  52. n = t("AstarHoneycombRoadSeeker"),
  53. r = t("AStarRoadSeeker"),
  54. l = t("MapRoadUtils"),
  55. h = t("RoadNode"),
  56. c = t("RoadPointLayer"),
  57. u = t("Toast"),
  58. p = t("ControllerConst"),
  59. f = t("NotificationConst"),
  60. g = (t("ViewConst"), t("PlatformBase"), t("BagConst")),
  61. m = t("BuffMgr"),
  62. _ = t("GameConst"),
  63. y = t("GlobalAttr"),
  64. v = t("GameView"),
  65. U = t("AbilityInfoService"),
  66. Z = t("BaseService"),
  67. C = t("CurrencyService"),
  68. b = t("DeskService"),
  69. S = t("HelperCatService"),
  70. T = t("MachineService"),
  71. I = t("OrderService"),
  72. w = t("RoleService"),
  73. M = t("StageUpgradeService"),
  74. D = t("ViewportService"),
  75. { ccclass: A, property: E } = cc._decorator;
  76. t = s = class extends Z.default {
  77. constructor() {
  78. super(...arguments),
  79. (this.curBundle = null),
  80. (this.foodBundle = null),
  81. (this.gameView = null),
  82. (this.mapNode = null),
  83. (this.layer = null),
  84. (this.uiLayer = null),
  85. (this.langLayer = null),
  86. (this._roadDic = {}),
  87. (this.curCfg = null),
  88. (this.machineMenu = null),
  89. (this.define = null),
  90. (this.curId = -1),
  91. (this.mapSaveData = null),
  92. (this.loadingTime = 0);
  93. }
  94. onLoad() {
  95. s.ins = this;
  96. }
  97. init() {}
  98. desotrySelf() {
  99. (this.layer = null),
  100. b.default.ins,
  101. S.default.ins.desotrySelf(),
  102. m.default.ins.closeRegion(this.curId),
  103. T.default.ins.destorySelf(),
  104. this.gameView.node.destroyAllChildren(),
  105. this.curBundle &&
  106. (this.curBundle.releaseAll(), cc.assetManager.removeBundle(this.curBundle), (this.curBundle = null)),
  107. (this.mapNode = null),
  108. w.default.ins.destroySelf();
  109. }
  110. loadMap(c, t = 0) {
  111. return o(this, void 0, void 0, function*() {
  112. this.mapNode && this.desotrySelf();
  113. let t = c < 10 ? "map_0" + c : "map_" + c;
  114. 1e4 < c && (t = "map_04");
  115. let e = t,
  116. i = "food";
  117. "test" == versionInfo.packVersion ?
  118. ((e = t),
  119. (i = "food")) :
  120. (e = t),
  121. yield d.default.ResManager.loadDirInBundle(e, ""),
  122. yield d.default.ResManager.loadDirInBundle(i, ""),
  123. (this.curCfg = d.default.ConfigManager.getConfig("StageSet")[c]);
  124. let s = "map_icon_1";
  125. "test" == versionInfo.packVersion && (s = s),
  126. yield d.default.ResManager.loadBundle(s),
  127. (this.curId = c),
  128. (this.define = d.default.ConfigManager.getConfig("Define")),
  129. (this.machineMenu = d.default.ConfigManager.getConfig("MachineMenu")),
  130. (this.curBundle = cc.assetManager.getBundle(t)),
  131. (this.foodBundle = cc.assetManager.getBundle("food"));
  132. const o = this.curBundle.get("map/MapNode", cc.Prefab),
  133. a = (this.mapNode = cc.instantiate(o));
  134. this.gameView.node.addChild(a),
  135. (a.y = -a.height),
  136. (D.default.ins.map = a),
  137. D.default.ins.initViewportArea();
  138. var n = this.curBundle.get("map/MapData", cc.JsonAsset).json;
  139. if (!n) return u.default.launch("缺少地图路径数据!"), void Log.error("缺少地图路径数据!");
  140. this.setMapData(n), m.default.ins.openNewRegion(c), this.parseMap();
  141. const r = d.default.ControllerManager.getControllerModel(p.ControllerConst.Game);
  142. var l,
  143. h = 1e4 < c ? _.EmMapType.FB : _.EmMapType.MAIN;
  144. r.data.curMapType === h ?
  145. (l = r.getCurMapData()).curId !== c ?
  146. (this.mapSaveData = r.resetMapData(c)) :
  147. (this.mapSaveData = l) :
  148. ((r.data.curMapType = h), (this.mapSaveData = r.getCurMapData())),
  149. M.default.ins.init(),
  150. I.default.ins.init(),
  151. w.default.ins.init(),
  152. T.default.ins.init(),
  153. b.default.ins.init(),
  154. C.default.ins.init(),
  155. U.default.ins.init(),
  156. S.default.ins.init(),
  157. y.default.ins.calAll(),
  158. "test" == versionInfo.packVersion && this.debug(n),
  159. d.default.NotificationCenter.dispatch(f.NotificationConst.UPDATE_MONEY),
  160. d.default.NotificationCenter.dispatch(f.NotificationConst.ENTER_MAP),
  161. (this.loadingTime || d.default.ViewManager.isShow(38)) &&
  162. ((n = d.default.DateUtils.Now() - this.loadingTime),
  163. (this.loadingTime = 0),
  164. 3e3 <= n ?
  165. d.default.ViewManager.close(38) :
  166. d.default.TimerManager.doTimer(
  167. 3e3 - n,
  168. 1,
  169. () => {
  170. d.default.ViewManager.close(38);
  171. },
  172. this
  173. ));
  174. });
  175. }
  176. setMapData(i) {
  177. l.default.instance.updateMapInfo(i.mapWidth, i.mapHeight, i.nodeWidth, i.nodeHeight, i.type),
  178. (this._roadDic = {});
  179. var t = i.roadDataArr.length,
  180. s = i.roadDataArr[0].length;
  181. for (let e = 0; e < t; e++) {
  182. let t = 0;
  183. for (; t < s; t++) {
  184. var o = i.roadDataArr[e][t],
  185. a = l.default.instance.getNodeByDerect(t, e);
  186. (a.value = o), (this._roadDic[a.cx + "_" + a.cy] = a);
  187. }
  188. }
  189. 2 == i.type ?
  190. (this._roadSeeker = new n.default(this._roadDic)) :
  191. (this._roadSeeker = new r.default(this._roadDic));
  192. }
  193. parseMap() {
  194. const t = this.mapNode;
  195. this.layer = t.getChildByName("layer");
  196. const e = t.getChildByName("bg2");
  197. e && (e.zIndex = 4),
  198. (this.layer.zIndex = 3),
  199. (this.langLayer = new cc.Node()),
  200. (this.langLayer.name = "LangLayer"),
  201. (this.langLayer.zIndex = 3),
  202. t.addChild(this.langLayer),
  203. (this.uiLayer = new cc.Node()),
  204. (this.uiLayer.name = "UILayer"),
  205. (this.uiLayer.zIndex = 3),
  206. t.addChild(this.uiLayer);
  207. const i = t.getChildByName("GridLayer");
  208. i && i.destroy(),
  209. y.default.init(),
  210. w.default.ins.parse(t),
  211. b.default.ins.parse(t),
  212. T.default.ins.parse(t.getChildByName("Machines"));
  213. }
  214. getPaths(t, e) {
  215. var i = l.default.instance.getWorldPointByPixel(t.x, t.y),
  216. t = l.default.instance.getWorldPointByPixel(e.x, e.y),
  217. i = this._roadDic[i.x + "_" + i.y],
  218. t = this._roadDic[t.x + "_" + t.y],
  219. t = this._roadSeeker.seekPath(i, t);
  220. const s = new h.default();
  221. return (s.px = e.x), (s.py = e.y), 0 < t.length && t.pop(), t.push(s), t;
  222. }
  223. update(t) {
  224. this.layer && this.layer.children.sort((t, e) => e.y - t.y);
  225. }
  226. debug(t) {
  227. const e = new cc.Node();
  228. this.mapNode.addChild(e, 1),
  229. e.addComponent(a.default).drawGrid(t.mapWidth, t.mapHeight, t.nodeWidth, t.nodeHeight, t.type);
  230. const i = new cc.Node();
  231. this.mapNode.addChild(i, 2), i.addComponent(c.default).initRoadPointInfo(t), w.default.ins.createTestMan();
  232. }
  233. switchMap() {
  234. const e = this.curCfg.clear_reward_suitcasekey_idx,
  235. i = this.curCfg.clear_reward_suitcasekey_count,
  236. s = this.curId + 1,
  237. o = d.default.ConfigManager.getConfig("StageSet")[s];
  238. if (0 < i) {
  239. d.default.ControllerManager.applyFunc(p.ControllerConst.Item, g.BagConst.ADD_TIME, e, i);
  240. const a = d.default.ControllerManager.applyFunc(p.ControllerConst.Item, g.BagConst.GET_ITEM, e);
  241. let t = new _.CongratulationData();
  242. (t.iconUrl = a.getItemPic()),
  243. (t.name = a.getName()),
  244. (t.cnt = i),
  245. (t.type = _.CongratulationType.Pass),
  246. (t.passIcon = "stage/" + o.stage_icon),
  247. d.default.ViewManager.open(31, [t], 1, () => {
  248. d.default.ViewManager.open(38, this.curId),
  249. (this.loadingTime = d.default.DateUtils.Now()),
  250. this.loadMap(s, !0);
  251. });
  252. } else
  253. d.default.ViewManager.open(38, this.curId),
  254. (this.loadingTime = d.default.DateUtils.Now()),
  255. this.loadMap(s, !0);
  256. d.default.AnalyticMgr.recordState("level", 1, s);
  257. }
  258. getCurRegionCfgs() {
  259. var t,
  260. e = d.default.ConfigManager.getConfig("StageSet");
  261. let i = this.curCfg.region,
  262. s = [];
  263. for (t in e)
  264. if (e[t].region == i) s.push(e[t]);
  265. else if (e[t].region > i) break;
  266. return s;
  267. }
  268. };
  269. e([E(v.default)], t.prototype, "gameView", void 0), (t = s = e([A], t)), (i.default = t = s);