GameData.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. var reGameStates = require('GameStates');
  2. var AConfig = require('../Config');
  3. //全局数据类
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. //记录全部道路的index
  8. GameData_highwayIndex: {
  9. default: [],
  10. type: [cc.Integer],
  11. visible: false,
  12. serializable: false,
  13. },
  14. //记录建筑物存储的信息
  15. GameData_buildings: {
  16. default: [],
  17. visible: false,
  18. serializable: false,
  19. },
  20. HighWayPrefabs: cc.Prefab,
  21. //MyMapNode
  22. //建筑物的节点
  23. BuildingsParent: {
  24. default: null,
  25. type: cc.Node,
  26. },
  27. ManageUI: {
  28. default: null,
  29. type: cc.Node,
  30. },
  31. GameVersion: {
  32. default: -1,
  33. type: cc.Integer,
  34. },
  35. //读取数据
  36. readData: {
  37. default: null,
  38. visible: false,
  39. }
  40. },
  41. onLoad() {
  42. //初始化GameData全局变量
  43. GlobalD.GameData = this;
  44. this.GameConfig();
  45. },
  46. start() {
  47. this._tiledMap = GlobalD.TiledMap._tiledMap;
  48. //老铁 请选择 游戏模式
  49. //true 每次进入清除数据模式
  50. //false 正常带网络存档模式
  51. this.isDebugMode(false);
  52. // return;
  53. },
  54. //设置游戏模式
  55. isDebugMode: function (b) {
  56. if (b) {
  57. // 清除
  58. this.onClearAllData();
  59. this.getData();
  60. } else {
  61. // 正常游戏
  62. this.getData();
  63. }
  64. },
  65. getData: function () {
  66. //如果开局没有读取到网络数据,就这里初始化
  67. if (userData.readData == null) {
  68. // cc.log("本地数据:", cc.sys.localStorage.getItem('userdata'));
  69. let userdata = cc.sys.localStorage.getItem('userdata');
  70. if (userdata) {
  71. this.readData = JSON.parse(userdata);
  72. }
  73. this.Init();
  74. this.InitSceneInfo();
  75. } else {
  76. this.readData = userData.readData;
  77. // cc.log('读取到数据?:', this.readData)
  78. this.Init();
  79. this.InitSceneInfo();
  80. }
  81. },
  82. GameConfig() {
  83. this.AddBuildingCost = 5;
  84. this.RemoveBuildingCost = 5;
  85. },
  86. InitSceneInfo() {
  87. //根据顺序生成
  88. //初始化道路
  89. this.onSpawnHighway();
  90. //初始化时间ui
  91. cc.find("GameNode/ManageTimer").getComponent('ManageTimer').Init();
  92. //初始化金钱ui
  93. cc.find("GameNode/ManageGolden").getComponent('ManageGolden').InitManageGlodenUI();
  94. // //初始化地图物件
  95. // cc.find("GameNode/ManageMap").getComponent('ManageMap').InitManageMap();
  96. GlobalD.TiledMap.onInitSolid();
  97. //初始化生成房屋
  98. this.ManageUI.getComponent('ManageBuildings').InitBuildings();
  99. //初始化生成人物
  100. cc.find('GameNode/ManageWorker').getComponent('ManageWorker').InitWorkerAI();
  101. let _BFirstLoadGame = this.readData ? this.readData.BFirstLoadGame : false;
  102. //初始化新手教学
  103. GlobalD.ManageTask.InitTask(_BFirstLoadGame);
  104. this.ManageUI.getComponent('ManageUI').Init();
  105. // 自动存储数据
  106. this.AutoSaveData = function () {
  107. this.pushData();
  108. };
  109. this.schedule(this.AutoSaveData, 5);
  110. },
  111. //InitData
  112. Init: function () {
  113. // let BFirstLoadGame = parseInt(cc.sys.localStorage.getItem('BFirstLoadGame'));
  114. let _BFirstLoadGame = this.readData ? this.readData.BFirstLoadGame : false;
  115. //date
  116. this.GameYear = 0;
  117. this.GameMonth = 0;
  118. this.GameDay = 0;
  119. this.GameDate = '0000/00/01';
  120. this.Golden = 2000;
  121. this.Diamond = 100;
  122. this.WorkerLV = 0;
  123. this.WorkerNum = 0;
  124. this.CharacterInfoArray = [];
  125. this.WorkerCapacity = 5;
  126. this.TerritoryStateArray = [1, 1, 1, 1, 1, 1, 1, 1];//测试,全开地图
  127. // this.BuildingStateArray = [
  128. // 0, //公路
  129. // 0, //路铲
  130. // 1, //拆迁
  131. // 1, //农舍
  132. // 0, //单元楼
  133. // 0, //别墅
  134. // 1, //农田
  135. // 0, //伐木场
  136. // 0, //矿坑
  137. // 0, //加工厂
  138. // 1, //便利店
  139. // 0, //鲜花店
  140. // 0, //甜品店
  141. // 0, //汉堡店
  142. // 0, //咖啡店
  143. // 0, //洋装店
  144. // 0, //酒吧
  145. // 1, //绿化带
  146. // 0, //喷泉
  147. // 0, //游乐场
  148. // 0, //医院
  149. // 0,//警察局
  150. // 0];//银行
  151. this.BuildingStateArray = [
  152. 1, //公路
  153. 1, //路铲
  154. 1, //拆迁
  155. 1, //农舍
  156. 1, //单元楼
  157. 1, //别墅
  158. 1, //农田
  159. 1,//伐木场
  160. 1, //矿坑
  161. 1, //加工厂
  162. 1,//冷饮摊
  163. 1,//贩卖机
  164. 1,//面包房
  165. 1,//早餐车
  166. 1, //饮茶店
  167. 1,//点心店
  168. 1, //美食店
  169. 1,//西餐厅
  170. 1, //花店
  171. 1, //美发店
  172. 1,//洋装店
  173. 1, //珠宝店
  174. 1, //电影院
  175. 1,//路灯
  176. 1, //绿化带
  177. 1, //花坛
  178. 1,//喷泉
  179. 1, //警察局
  180. 1,//游乐场
  181. 1, //蓝色城堡
  182. 1 //粉色城堡
  183. ];
  184. this.BuildingLockStateArray = [
  185. 1, //公路
  186. 1, //路铲
  187. 1, //拆迁
  188. 1, //农舍
  189. 0, //单元楼
  190. 0, //别墅
  191. 1, //农田
  192. 0,//伐木场
  193. 0, //矿坑
  194. 1, //加工厂
  195. 0,//冷饮摊
  196. 0,//贩卖机
  197. 0,//面包房
  198. 0,//早餐车
  199. 0, //饮茶店
  200. 0,//点心店
  201. 0, //美食店
  202. 0,//西餐厅
  203. 0, //花店
  204. 0, //美发店
  205. 0,//洋装店
  206. 0, //珠宝店
  207. 0, //电影院
  208. 1,//路灯
  209. 1, //绿化带
  210. 1, //花坛
  211. 0,//喷泉
  212. 0, //警察局
  213. 0,//游乐场
  214. 0, //蓝色城堡
  215. 0 //粉色城堡
  216. ];
  217. // this.BuildingLockStateArray = [
  218. // 1, //公路
  219. // 1, //路铲
  220. // 1, //拆迁
  221. // 1, //农舍
  222. // 1, //单元楼
  223. // 1, //别墅
  224. // 1, //农田
  225. // 1,//伐木场
  226. // 1,//矿坑
  227. // 1, //加工厂
  228. // 1,//便利店
  229. // 1,//鲜花店
  230. // 1,//甜品店
  231. // 1, //汉堡店
  232. // 1,//咖啡店
  233. // 1, //洋装店
  234. // 1, //酒吧
  235. // 1, //绿化带
  236. // 1,//喷泉
  237. // 1,//游乐场
  238. // 0, //医院
  239. // 0,//警察局
  240. // 0];//银行
  241. this.BuildingNumArray = [
  242. 0, //公路
  243. 0, //路铲
  244. 0, //拆迁
  245. 4, //农舍
  246. 1, //单元楼
  247. 1, //别墅
  248. 4, //农田
  249. 1,//伐木场
  250. 1, //矿坑
  251. 2, //加工厂
  252. 2,//冷饮摊
  253. 1,//贩卖机
  254. 1,//面包房
  255. 1,//早餐车
  256. 1, //饮茶店
  257. 1,//点心店
  258. 1, //美食店
  259. 1,//西餐厅
  260. 1, //花店
  261. 1, //美发店
  262. 1,//洋装店
  263. 1, //珠宝店
  264. 1, //电影院
  265. 1,//路灯
  266. 1, //绿化带
  267. 1, //花坛
  268. 1,//喷泉
  269. 1, //警察局
  270. 1,//游乐场
  271. 1, //蓝色城堡
  272. 1 //粉色城堡
  273. ];
  274. // this.BuildingNumArray = [
  275. // 0, //公路
  276. // 0, //路铲
  277. // 0, //拆迁
  278. // 10, //农舍
  279. // 10, //单元楼
  280. // 10, //别墅
  281. // 10, //农田
  282. // 10, //伐木场
  283. // 10, //矿坑
  284. // 10, //加工厂
  285. // 10, //便利店
  286. // 9, //鲜花店
  287. // 8, //甜品店
  288. // 7,//汉堡店
  289. // 6,//咖啡店
  290. // 5,//洋装店
  291. // 4, //酒吧
  292. // 10, //绿化带
  293. // 10,//喷泉
  294. // 10, //游乐场
  295. // 0, //医院
  296. // 0, //警察局
  297. // 0];//银行
  298. //钻石消耗默认值
  299. this.DiamondNumArray = AConfig.DiamondArray;
  300. // cc.log('钻石消耗默认值',this.DiamondNumArray);
  301. this.EveryDayRewardsArray = [0, 0, 0, 0, 0, 0, 0];
  302. this.LastTimeEveryDayRewardsDate = '0000/00/00';
  303. this.LastTimeLuckDate = '0000/00/00';
  304. this.FoodTradeState = 1;
  305. this.WoodTradeState = 1;
  306. this.MineralTradeState = 1;
  307. //转盘分享给钻石金币
  308. this.shareGive = [200, 5];
  309. //签到分享给钻石金币
  310. this.signInGive = [200, 5];
  311. //每个月 给的 低保
  312. this.EveryGive = [500, 10];
  313. //公共分享
  314. this.publicGive = [200, 50];
  315. //每天抽奖次数
  316. this.LotteryTimes = 10;
  317. if (_BFirstLoadGame) {
  318. // cc.log('初始化网络数据');
  319. //读取日期数据
  320. this.GameYear = this.readData.GameYear;
  321. this.GameMonth = this.readData.GameMonth;
  322. this.GameDay = this.readData.GameDay;
  323. //读取金币
  324. this.Golden = this.readData.Golden;
  325. //读取钻石
  326. this.Diamond = this.readData.Diamond;
  327. // cc.log('this.readData.Diamond', this.readData.Diamond);
  328. //读取工人等级
  329. this.WorkerLV = this.readData.WorkerLV;
  330. //工人数量
  331. this.WorkerNum = this.readData.WorkerNum;
  332. //工人容量
  333. this.WorkerCapacity = this.readData.WorkerCapacity;
  334. this.GameDate = this.readData.GameDate;
  335. this.LastTimeEveryDayRewardsDate = this.readData.LastTimeEveryDayRewardsDate;
  336. this.LastTimeLuckDate = this.readData.LastTimeLuckDate;
  337. this.EveryDayRewardsArray = this.readData.EveryDayRewardsArray.split('_');
  338. this.TerritoryStateArray = this.readData.TerritoryStateArray.split('_');
  339. //面板状态
  340. this.BuildingStateArray = this.readData.BuildingStateArray.split('_');
  341. this.BuildingLockStateArray = this.readData.BuildingLockStateArray.split('_');
  342. this.BuildingNumArray = this.readData.BuildingNumArray.split('_');
  343. this.DiamondNumArray = this.readData.DiamondNumArray.split('_');
  344. this.FoodTradeState = this.readData.FoodTradeState;
  345. this.WoodTradeState = this.readData.WoodTradeState;
  346. this.MineralTradeState = this.readData.MineralTradeState;
  347. //工人工作信息
  348. this.CharacterInfoArray = this.readData.characterInfoArray;
  349. //道路数据
  350. this.GameData_highwayIndex = this.readData.highwayIndex;
  351. //建筑物数据
  352. this.GameData_buildings = this.readData.buildingsInfo;
  353. this.LotteryTimes = this.readData.LotteryTimes;
  354. //任务
  355. task.TaskIconCountClick = this.readData.TaskIconCountClick;
  356. //测试5W
  357. // this.PlusDiamond(50000);
  358. }
  359. },
  360. //GET / SET /Plus
  361. GetGameDate: function () {
  362. return this.GameDate;
  363. },
  364. SetGameDate: function (num) {
  365. this.GameDate = num;
  366. },
  367. PlusGameDate: function (num) {
  368. this.GameDate += num;
  369. },
  370. GetGolden: function () {
  371. return parseInt(this.Golden);
  372. },
  373. GetGoldenCallBack(_CallBack) {
  374. if (_CallBack)
  375. _CallBack({ resGolden: parseInt(this.Golden) });
  376. },
  377. SetGolden: function (Num) {
  378. let LastMoney = this.Golden;
  379. this.Golden = Num;
  380. let CurrentMoney = Num;
  381. this.ManageUI.getComponent('ManageUI').GoldenChangeCallBack(this.GetGolden(), LastMoney, CurrentMoney);
  382. },
  383. PlusGolden: function (Num) {
  384. if (this.Golden + Num < 0) {
  385. this.SetGolden(0);
  386. }
  387. else {
  388. this.SetGolden(this.Golden + Num);
  389. }
  390. // task.task50W();
  391. },
  392. GetDiamond: function () {
  393. return parseInt(this.Diamond);
  394. },
  395. SetDiamond: function (num) {
  396. let LastMoney = this.Diamond;
  397. this.Diamond = num;
  398. let CurrentMoney = num;
  399. this.ManageUI.getComponent('ManageUI').DiamondChangeCallBack(this.GetDiamond(), LastMoney, CurrentMoney);
  400. },
  401. PlusDiamond: function (num) {
  402. if (this.Diamond + num < 0) {
  403. this.SetDiamond(0);
  404. }
  405. else {
  406. this.SetDiamond(this.Diamond + num);
  407. }
  408. },
  409. GetWorkerLV: function () {
  410. return parseInt(this.WorkerLV);
  411. },
  412. SetWorkerLV: function (num) {
  413. this.WorkerLV = num;
  414. },
  415. PlusWorkerLV: function (num) {
  416. this.WorkerLV += num;
  417. },
  418. GetWorkerNum: function () {
  419. return parseInt(this.WorkerNum);
  420. },
  421. SetWorkerNum: function (num) {
  422. this.WorkerNum = num;
  423. },
  424. PlusWorkerNum: function (num) {
  425. this.WorkerNum += num;
  426. },
  427. GetLastTimeEveryDayRewardsDate: function () {
  428. return this.LastTimeEveryDayRewardsDate;
  429. },
  430. //获取转盘 时间
  431. GetLastTimeLuckDate: function () {
  432. return this.LastTimeLuckDate;
  433. },
  434. //设置转盘时间
  435. SetLastTimeLuckDate: function (DateString) {
  436. this.LastTimeLuckDate = DateString;
  437. },
  438. SetLastTimeEveryDayRewardsDate: function (DateString) {
  439. this.LastTimeEveryDayRewardsDate = DateString;
  440. },
  441. //工人信息数组
  442. GetWorkerCharacterInfoArray: function () {
  443. return this.CharacterInfoArray;
  444. },
  445. SetWorkerCharacterInfoArray: function (item) {
  446. this.CharacterInfoArray = item;
  447. },
  448. /*** */
  449. GetWorkerCapacity: function () {
  450. return parseInt((this.WorkerCapacity));
  451. },
  452. SetWorkerCapacity: function (num) {
  453. this.WorkerCapacity = num;
  454. },
  455. PlusWorkerCapacity: function (num) {
  456. this.WorkerCapacity += num;
  457. },
  458. GetTerritoryStateArray: function () {
  459. return this.TerritoryStateArray;
  460. },
  461. SetTerritoryStateArray: function (aTerritoryStateArray) {
  462. this.TerritoryStateArray = aTerritoryStateArray;
  463. },
  464. PlusTerritoryStateArray: function (Item) {
  465. this.TerritoryStateArray.push(Item);
  466. },
  467. GetBuildingStateArray: function () {
  468. return this.BuildingStateArray;
  469. },
  470. SetBuildingStateArray: function (aBuildingStateArray) {
  471. this.BuildingStateArray = aBuildingStateArray;
  472. },
  473. PlusBuildingStateArray: function (Item) {
  474. this.BuildingStateArray.push(Item);
  475. },
  476. GetBuildingLockStateArray: function () {
  477. return this.BuildingLockStateArray;
  478. },
  479. SetBuildingLockStateArray: function (aArray) {
  480. this.BuildingLockStateArray = aArray;
  481. },
  482. PlusBuildingLockStateArray: function (Item) {
  483. this.BuildingLockStateArray.push(Item);
  484. },
  485. GetBuildingNumArray: function () {
  486. return this.BuildingNumArray;
  487. },
  488. SetBuildingNumArray: function (aBuildingNumArray) {
  489. this.BuildingNumArray = aBuildingNumArray;
  490. },
  491. PlusBuildingNumArray: function (Item) {
  492. this.BuildingNumArray.push(Item);
  493. },
  494. //操作钻石数据
  495. GetDiamondNumArray: function () {
  496. return this.DiamondNumArray;
  497. },
  498. SetDiamondNumArray: function (aDiamondNumArray) {
  499. this.DiamondNumArray = aDiamondNumArray;
  500. },
  501. GetEveryDayRewardsArray: function () {
  502. return this.EveryDayRewardsArray;
  503. },
  504. SetEveryDayRewardsArray: function (aArray) {
  505. this.EveryDayRewardsArray = aArray;
  506. },
  507. PlusEveryDayRewardsArray: function (Item) {
  508. this.EveryDayRewardsArray.push(Item);
  509. },
  510. GetFoodTradeState: function () {
  511. return parseInt((this.FoodTradeState));
  512. },
  513. SetFoodTradeState: function (num) {
  514. this.FoodTradeState = num;
  515. },
  516. PlusFoodTradeState: function (num) {
  517. this.FoodTradeState += num;
  518. },
  519. GetWoodTradeState: function () {
  520. return parseInt((this.WoodTradeState));
  521. },
  522. SetWoodTradeState: function (num) {
  523. this.WoodTradeState = num;
  524. },
  525. PlusWoodTradeState: function (num) {
  526. this.WoodTradeState += num;
  527. },
  528. GetMineralTradeState: function () {
  529. return parseInt((this.MineralTradeState));
  530. },
  531. SetMineralTradeState: function (num) {
  532. this.MineralTradeState = num;
  533. },
  534. PlusMineralTradeState: function (num) {
  535. this.MineralTradeState += num;
  536. },
  537. GetLotteryTimes: function () {
  538. return parseInt((this.LotteryTimes));
  539. },
  540. SetLotteryTimes: function (num) {
  541. this.LotteryTimes = num;
  542. },
  543. PlusLotteryTimes: function (num) {
  544. this.LotteryTimes += num;
  545. },
  546. //初始化道路
  547. onSpawnHighway() {
  548. // 获取InitPoint层
  549. let InitPos = this._tiledMap.getLayer('InitPoint');
  550. InitPos.enabled = false;
  551. // //道路数据
  552. // highwayIndex: this.GameData_highwayIndex,
  553. // allHighwayStylesAndIndex: GlobalD.game.AllHighwayStylesAndIndex,
  554. // var highwayTemp = cc.sys.localStorage.getItem('highway');
  555. //创建公路数据
  556. if (this.readData) {
  557. //保存到内存中
  558. this.GameData_highwayIndex = this.readData.highwayIndex;
  559. //先赋值道路的对象数组
  560. let _AllHighwayAIndex = GlobalD.game.AllHighwayStylesAndIndex = this.readData.allHighwayStylesAndIndex;
  561. //获取最后建造公路的层级
  562. this.HighwayLayer = this._tiledMap.getLayer('Highway');
  563. for (let i = 0; i < _AllHighwayAIndex.length; i++) {
  564. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  565. highwayTemp.parent = this.HighwayLayer.node;
  566. let tiledTile = highwayTemp.addComponent('TiledTile');
  567. let _tiledPos = GlobalD.TiledMap.analyticalIndexData(_AllHighwayAIndex[i].highwayInfoIndex);
  568. tiledTile.x = _tiledPos.x;
  569. tiledTile.y = _tiledPos.y;
  570. //地图设置可行走区域公路设置
  571. AStar.setMapSolid(_tiledPos.x, _tiledPos.y, 0);
  572. // _buildId ==0 是公路
  573. let _buildId = 0;
  574. let occupyTemp = cc.v2(_buildId, _AllHighwayAIndex[i].highwayInfoIndex);
  575. GlobalD.game.OccupyArray.push(occupyTemp);
  576. highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(_AllHighwayAIndex[i].highwayInfoType);
  577. }
  578. } else {
  579. //如果用户没有存储数据
  580. //根据InitPoint 的数据,创建初始化的地图数据 的初始化数据
  581. this.HighwayLayer = this._tiledMap.getLayer('Highway');
  582. for (var i = 0; i < 32; i++) {
  583. //去除中间两条路
  584. if (i == 16 || i == 17) continue;
  585. for (var j = 0; j < 32; j++) {
  586. let tilesPos = cc.v2(i, j);
  587. if (InitPos.getTileGIDAt(tilesPos)) {
  588. let index = GlobalD.TiledMap.getIndex(tilesPos);
  589. this.GameData_highwayIndex.push(index);
  590. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  591. highwayTemp.parent = this.HighwayLayer.node;
  592. let tiledTile = highwayTemp.addComponent('TiledTile');
  593. tiledTile.x = tilesPos.x;
  594. tiledTile.y = tilesPos.y;
  595. // cc.log('onSpawnHighway2');
  596. //地图设置可行走区域公路设置
  597. AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
  598. // _buildId ==0 是公路
  599. let _buildId = 0;
  600. let occupyTemp = cc.v2(_buildId, index);
  601. GlobalD.game.OccupyArray.push(occupyTemp);
  602. let tile = InitPos.getTiledTileAt(tilesPos.x, tilesPos.y, true);
  603. let _MoveType = reGameStates.HighwayType.moveX;
  604. // if (tile.gid == 15) {
  605. // _MoveType = reGameStates.HighwayType.moveX;
  606. // } else
  607. if (tile.gid == 16) {
  608. _MoveType = reGameStates.HighwayType.moveY;
  609. } else if (tile.gid == 11) {
  610. _MoveType = reGameStates.HighwayType.ZebraCrossingX;
  611. } else if (tile.gid == 12) {
  612. _MoveType = reGameStates.HighwayType.ZebraCrossingY;
  613. }
  614. // return;
  615. //更换公路样式
  616. GlobalD.game.onCreateDifferentRoadStyles({
  617. _buildId: _buildId,
  618. _highwayType: _MoveType,
  619. _roadIndex: index,
  620. _hightwayNode: highwayTemp
  621. });
  622. }
  623. }
  624. }
  625. }
  626. //外面的两条路
  627. let initRoad = this._tiledMap.getLayer('Road');
  628. initRoad.enabled = false;
  629. for (var i = 16; i < 18; i++) {
  630. for (var j = 0; j < 32; j++) {
  631. let tilesPos = cc.v2(i, j);
  632. // cc.log('road tilesPos',tilesPos)
  633. if (initRoad.getTileGIDAt(tilesPos)) {
  634. let index = GlobalD.TiledMap.getIndex(tilesPos);
  635. this.GameData_highwayIndex.push(index);
  636. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  637. highwayTemp.parent = this.HighwayLayer.node;
  638. let tiledTile = highwayTemp.addComponent('TiledTile');
  639. tiledTile.x = tilesPos.x;
  640. tiledTile.y = tilesPos.y;
  641. // cc.log('initRoad');
  642. //地图设置可行走区域公路设置
  643. AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
  644. let _buildId = 0;
  645. let occupyTemp = cc.v2(_buildId, index);
  646. GlobalD.game.OccupyArray.push(occupyTemp);
  647. //更换公路样式
  648. // if (j >= 25 && j <= 27 || j >= 19 && j <= 21 || j >= 9 && j <= 11)
  649. // highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.none);
  650. // else
  651. // highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.moveY);
  652. }
  653. }
  654. }
  655. },
  656. //清除所有的数据
  657. onClearAllData() {
  658. this.unschedule(this.AutoSaveData);
  659. //任务索引
  660. cc.sys.localStorage.removeItem('userdata');
  661. //跳回登录场景
  662. // cc.director.loadScene('Login');
  663. },
  664. //保存数据请求
  665. pushData: function () {
  666. // cc.log(this.EveryDayRewardsArray);
  667. var datas = {
  668. version: this.GameVersion,
  669. BFirstLoadGame: 1,//只要push数据,就证明已经开始第一次游戏了
  670. //时间
  671. GameYear: this.GameYear,
  672. GameMonth: this.GameMonth,
  673. GameDay: this.GameDay,
  674. Golden: this.Golden,
  675. Diamond: this.Diamond,
  676. WorkerLV: this.WorkerLV,
  677. WorkerNum: this.WorkerNum,
  678. WorkerCapacity: this.WorkerCapacity,
  679. GameDate: this.GameDate,
  680. LastTimeEveryDayRewardsDate: this.LastTimeEveryDayRewardsDate,
  681. LastTimeLuckDate: this.LastTimeLuckDate,
  682. EveryDayRewardsArray: this.EveryDayRewardsArray.join('_'),
  683. TerritoryStateArray: this.TerritoryStateArray.join('_'),
  684. //面板状态
  685. BuildingStateArray: this.BuildingStateArray.join('_'),
  686. BuildingLockStateArray: this.BuildingLockStateArray.join('_'),
  687. BuildingNumArray: this.BuildingNumArray.join('_'),
  688. DiamondNumArray: this.DiamondNumArray.join('_'),
  689. FoodTradeState: this.FoodTradeState,
  690. WoodTradeState: this.WoodTradeState,
  691. MineralTradeState: this.MineralTradeState,
  692. LotteryTimes: this.LotteryTimes,
  693. //工人工作信息
  694. characterInfoArray: this.CharacterInfoArray,
  695. //道路数据
  696. highwayIndex: this.GameData_highwayIndex,
  697. allHighwayStylesAndIndex: GlobalD.game.AllHighwayStylesAndIndex,
  698. //建筑物数据
  699. buildingsInfo: this.GameData_buildings,
  700. //任务
  701. TaskIconCountClick: task.TaskIconCountClick
  702. }
  703. var data = [];
  704. data["openid"] = userData.openId;
  705. data["userdata"] = JSON.stringify(datas);
  706. //保存用户数据到本地
  707. cc.sys.localStorage.setItem('userdata', JSON.stringify(datas));
  708. return;
  709. // console.log("提交的数据是", datas);
  710. httpUtils.Post(httpUtils.setUserData, data, function (resData) {
  711. let _userData = resData.data.userdata;
  712. let _JsonData = JSON.parse(_userData);
  713. // console.log("push成功", resData, _JsonData);
  714. if (resData.code == 0) {
  715. // this.getText.string = data.data.userdata;
  716. }
  717. }.bind(this), function (resData) {
  718. // console.log("失败", resData);
  719. }.bind(this));
  720. },
  721. });