GameData.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  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(function () {
  59. this.getData();
  60. }.bind(this));
  61. } else {
  62. // 正常游戏
  63. this.getData();
  64. }
  65. },
  66. getData: function () {
  67. //如果开局没有读取到网络数据,就这里初始化
  68. if (userData.readData == null) {
  69. //开局初始化的数据
  70. this.getNetworkData((res) => {
  71. //获取网络数据后处理
  72. if (res.code == 0) {
  73. //记录读取的数据到内存里面
  74. this.readData = JSON.parse(res.data.userdata);
  75. console.log("获取数据this.ReadData:", this.readData);
  76. // console.log("获取数据this.ReadData data:", res.data);
  77. // console.log("获取数据this.ReadData res.data.userdata:", res.data.userdata);
  78. //不管网络数据回调成功或者失败。都会进行初始化操作
  79. //后面初始化失败,是要进行其他操作的;
  80. this.Init();
  81. this.InitSceneInfo();
  82. } else {
  83. //失败
  84. cc.log('读取网络数据失败!', res);
  85. this.readData = null;
  86. //todo
  87. //打出提示,网络状态,考虑重新登录等。
  88. //不管网络数据回调成功或者失败。都会进行初始化操作
  89. //后面初始化失败,是要进行其他操作的;
  90. this.Init();
  91. this.InitSceneInfo();
  92. }
  93. });
  94. } else {
  95. this.readData = JSON.parse(userData.readData);
  96. cc.log('读取到数据?:', this.readData)
  97. this.Init();
  98. this.InitSceneInfo();
  99. }
  100. },
  101. GameConfig() {
  102. this.AddBuildingCost = 5;
  103. this.RemoveBuildingCost = 5;
  104. },
  105. InitSceneInfo() {
  106. let _BFirstLoadGame = this.readData ? this.readData.BFirstLoadGame : false;
  107. //根据顺序生成
  108. //初始化道路
  109. this.onSpawnHighway();
  110. //初始化时间ui
  111. cc.find("GameNode/ManageTimer").getComponent('ManageTimer').Init(_BFirstLoadGame);
  112. //初始化金钱ui
  113. cc.find("GameNode/ManageGolden").getComponent('ManageGolden').InitManageGlodenUI();
  114. //初始化地图物件
  115. cc.find("GameNode/ManageMap").getComponent('ManageMap').InitManageMap();
  116. //初始化生成房屋
  117. this.ManageUI.getComponent('ManageBuildings').InitBuildings();
  118. //初始化生成人物
  119. cc.find('GameNode/ManageWorker').getComponent('ManageWorker').InitWorkerAI();
  120. //初始化新手教学
  121. GlobalD.ManageTask.InitTask(_BFirstLoadGame);
  122. this.ManageUI.getComponent('ManageUI').Init();
  123. // 自动存储数据
  124. this.AutoSaveData = function () {
  125. // this.onAutoSaveData();
  126. this.pushData();
  127. };
  128. this.schedule(this.AutoSaveData, 5);
  129. },
  130. //InitData
  131. Init: function () {
  132. // let BFirstLoadGame = parseInt(cc.sys.localStorage.getItem('BFirstLoadGame'));
  133. let _BFirstLoadGame = this.readData ? this.readData.BFirstLoadGame : false;
  134. //date
  135. this.GameYear = 0;
  136. this.GameMonth = 0;
  137. this.GameDay = 0;
  138. this.GameDate = '0000/00/01';
  139. this.Golden = 210;
  140. this.Diamond = 5;
  141. this.WorkerLV = 0;
  142. this.WorkerNum = 0;
  143. this.CharacterInfoArray = [];
  144. this.WorkerCapacity = 5;
  145. this.TerritoryStateArray = [1, 1, 1, 1, 1, 1, 1, 1];//测试,全开地图
  146. // this.BuildingStateArray = [
  147. // 0, //公路
  148. // 0, //路铲
  149. // 1, //拆迁
  150. // 1, //农舍
  151. // 0, //单元楼
  152. // 0, //别墅
  153. // 1, //农田
  154. // 0, //伐木场
  155. // 0, //矿坑
  156. // 0, //加工厂
  157. // 1, //便利店
  158. // 0, //鲜花店
  159. // 0, //甜品店
  160. // 0, //汉堡店
  161. // 0, //咖啡店
  162. // 0, //洋装店
  163. // 0, //酒吧
  164. // 1, //绿化带
  165. // 0, //喷泉
  166. // 0, //游乐场
  167. // 0, //医院
  168. // 0,//警察局
  169. // 0];//银行
  170. this.BuildingStateArray = [
  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. 1, //甜品店
  184. 1, //汉堡店
  185. 1, //咖啡店
  186. 1, //洋装店
  187. 1,//酒吧
  188. 1,//绿化带
  189. 1, //喷泉
  190. 1,//游乐场
  191. 0, //医院
  192. 0, //警察局
  193. 0];//银行
  194. this.BuildingLockStateArray = [
  195. 1, //公路
  196. 1, //路铲
  197. 1, //拆迁
  198. 1, //农舍
  199. 0, //单元楼
  200. 0, //别墅
  201. 1, //农田
  202. 0,//伐木场
  203. 0, //矿坑
  204. 1, //加工厂
  205. 1,//便利店
  206. 0,//鲜花店
  207. 0,//甜品店
  208. 0,//汉堡店
  209. 0, //咖啡店
  210. 0,//洋装店
  211. 0, //酒吧
  212. 1,//绿化带
  213. 0, //喷泉
  214. 0, //游乐场
  215. 0,//医院
  216. 0, //警察局
  217. 0];//银行
  218. // this.BuildingLockStateArray = [
  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. // 1,//游乐场
  239. // 0, //医院
  240. // 0,//警察局
  241. // 0];//银行
  242. this.BuildingNumArray = [
  243. 0,//公路
  244. 0, //路铲
  245. 0, //拆迁
  246. 4, //农舍
  247. 1, //单元楼
  248. 1, //别墅
  249. 4, //农田
  250. 1, //伐木场
  251. 1, //矿坑
  252. 2,//加工厂
  253. 2, //便利店
  254. 1, //鲜花店
  255. 1, //甜品店
  256. 1, //汉堡店
  257. 1, //咖啡店
  258. 1,//洋装店
  259. 1, //酒吧
  260. 1,//绿化带
  261. 1,//喷泉
  262. 1, //游乐场
  263. 0,//医院
  264. 0,//警察局
  265. 0];//银行
  266. // this.BuildingNumArray = [
  267. // 0, //公路
  268. // 0, //路铲
  269. // 0, //拆迁
  270. // 10, //农舍
  271. // 10, //单元楼
  272. // 10, //别墅
  273. // 10, //农田
  274. // 10, //伐木场
  275. // 10, //矿坑
  276. // 10, //加工厂
  277. // 10, //便利店
  278. // 9, //鲜花店
  279. // 8, //甜品店
  280. // 7,//汉堡店
  281. // 6,//咖啡店
  282. // 5,//洋装店
  283. // 4, //酒吧
  284. // 10, //绿化带
  285. // 10,//喷泉
  286. // 10, //游乐场
  287. // 0, //医院
  288. // 0, //警察局
  289. // 0];//银行
  290. //钻石消耗默认值
  291. this.DiamondNumArray = AConfig.DiamondArray;
  292. // cc.log('钻石消耗默认值',this.DiamondNumArray);
  293. this.EveryDayRewardsArray = [0, 0, 0, 0, 0, 0, 0];
  294. this.LastTimeEveryDayRewardsDate = '0000/00/00';
  295. this.LastTimeLuckDate = '0000/00/00';
  296. this.FoodTradeState = 1;
  297. this.WoodTradeState = 1;
  298. this.MineralTradeState = 1;
  299. //转盘分享给钻石金币
  300. this.shareGive = [200, 50];
  301. //签到分享给钻石金币
  302. this.signInGive = [200, 50];
  303. //每个月 给的 低保
  304. this.EveryGive = [500, 10];
  305. //公共分享
  306. this.publicGive = [200, 50];
  307. //观看视频给予的奖励
  308. this.videoAdGive = [2000, 50];
  309. //解锁视频时候视频给予的奖励
  310. this.manageUIVideoAdGive = [800, 15];
  311. //第二次登录给的奖励
  312. this.secondLoginAdGive = [1000, 15];
  313. //每天抽奖次数
  314. this.LotteryTimes = 10;
  315. // if (!_BFirstLoadGame) {
  316. // cc.sys.localStorage.setItem('BFirstLoadGame', 1);
  317. // // init date
  318. // this.InitDateFirst();
  319. // this.InitGoldenFirst();
  320. // this.InitDiamondFirst();
  321. // this.InitWorkerLVFirst();
  322. // this.InitWorkerNumFirst();
  323. // this.InitWorkerCapacityFirst();
  324. // this.InitTerritoryStateArrayFirst();
  325. // this.InitBuildingStateArrayFirst();
  326. // this.InitBuildingLockStateArrayFirst();
  327. // this.InitBuildingNumArrayFirst();
  328. // this.InitEveryDayRewardsArrayFirst();
  329. // this.InitLastTimeEveryDayRewardsDateFirst();
  330. // this.InitFoodTradeStateFirst();
  331. // this.InitWoodTradeStateFirst();
  332. // this.InitMineralTradeStateFirst();
  333. // }
  334. // else {
  335. // this.InitDate();
  336. // this.InitGolden();
  337. // this.InitDiamond();
  338. // this.InitWorkerLV();
  339. // this.InitWorkerNum();
  340. // this.InitWorkerCapacity();
  341. // this.InitTerritoryStateArray();
  342. // this.InitBuildingStateArray();
  343. // this.InitBuildingLockStateArray();
  344. // this.InitBuildingNumArray();
  345. // this.InitEveryDayRewardsArray();
  346. // this.InitLastTimeEveryDayRewardsDate();
  347. // this.InitFoodTradeState();
  348. // this.InitWoodTradeState();
  349. // this.InitMineralTradeState();
  350. // }
  351. if (_BFirstLoadGame) {
  352. cc.log('初始化网络数据');
  353. //读取日期数据
  354. this.GameYear = this.readData.GameYear;
  355. this.GameMonth = this.readData.GameMonth;
  356. this.GameDay = this.readData.GameDay;
  357. //读取金币
  358. this.Golden = this.readData.Golden;
  359. //读取钻石
  360. this.Diamond = this.readData.Diamond;
  361. // cc.log('this.readData.Diamond', this.readData.Diamond);
  362. //读取工人等级
  363. this.WorkerLV = this.readData.WorkerLV;
  364. //工人数量
  365. this.WorkerNum = this.readData.WorkerNum;
  366. //工人容量
  367. this.WorkerCapacity = this.readData.WorkerCapacity;
  368. this.GameDate = this.readData.GameDate;
  369. this.LastTimeEveryDayRewardsDate = this.readData.LastTimeEveryDayRewardsDate;
  370. this.LastTimeLuckDate = this.readData.LastTimeLuckDate;
  371. this.EveryDayRewardsArray = this.readData.EveryDayRewardsArray.split('_');
  372. this.TerritoryStateArray = this.readData.TerritoryStateArray.split('_');
  373. //面板状态
  374. this.BuildingStateArray = this.readData.BuildingStateArray.split('_');
  375. this.BuildingLockStateArray = this.readData.BuildingLockStateArray.split('_');
  376. this.BuildingNumArray = this.readData.BuildingNumArray.split('_');
  377. //既然价格是定死的,就不用读取了
  378. this.DiamondNumArray = AConfig.DiamondArray;//this.readData.DiamondNumArray.split('_');
  379. this.FoodTradeState = this.readData.FoodTradeState;
  380. this.WoodTradeState = this.readData.WoodTradeState;
  381. this.MineralTradeState = this.readData.MineralTradeState;
  382. //工人工作信息
  383. this.CharacterInfoArray = this.readData.characterInfoArray;
  384. //道路数据
  385. this.GameData_highwayIndex = this.readData.highwayIndex;
  386. //建筑物数据
  387. this.GameData_buildings = this.readData.buildingsInfo;
  388. this.LotteryTimes = this.readData.LotteryTimes;
  389. //任务
  390. task.TaskIconCountClick = this.readData.TaskIconCountClick;
  391. //测试5W
  392. // this.PlusDiamond(50000);
  393. }
  394. // //初始化工人信息
  395. // let characterInfo = cc.sys.localStorage.getItem('CharacterInfoArray');
  396. // if (characterInfo) {
  397. // this.CharacterInfoArray = JSON.parse(characterInfo);
  398. // }
  399. // //初始化存储的建筑信息
  400. // let getbuildingsData = cc.sys.localStorage.getItem('Buildings');
  401. // if (getbuildingsData)
  402. // this.GameData_buildings = JSON.parse(getbuildingsData);
  403. // // cc.log('getbuildingsData= '+getbuildingsData);
  404. },
  405. InitDateFirst: function () {
  406. cc.sys.localStorage.setItem('GameYear', this.GameYear);
  407. cc.sys.localStorage.setItem('GameMonth', this.GameMonth);
  408. cc.sys.localStorage.setItem('GameDay', this.GameDay);
  409. },
  410. InitDate: function () {
  411. if (cc.sys.localStorage.getItem('GameYear')) {
  412. this.GameYear = cc.sys.localStorage.getItem('GameYear');
  413. this.GameMonth = cc.sys.localStorage.getItem('GameMonth');
  414. this.GameDay = cc.sys.localStorage.getItem('GameDay');
  415. }
  416. else {
  417. this.InitDateFirst();
  418. }
  419. },
  420. InitGameDateFirst: function () {
  421. cc.sys.localStorage.setItem('GameDate', this.GameDate);
  422. },
  423. InitGameDate: function () {
  424. if (cc.sys.localStorage.getItem('GameDate')) {
  425. this.GameDate = cc.sys.localStorage.getItem('GameDate');
  426. }
  427. else {
  428. this.InitGameDateFirst();
  429. }
  430. },
  431. InitGoldenFirst: function () {
  432. cc.sys.localStorage.setItem('Golden', this.Golden);
  433. },
  434. InitGolden: function () {
  435. if (cc.sys.localStorage.getItem('Golden')) {
  436. this.Golden = parseInt(cc.sys.localStorage.getItem('Golden'));
  437. }
  438. else {
  439. this.InitGoldenFirst();
  440. }
  441. },
  442. InitDiamondFirst: function () {
  443. cc.sys.localStorage.setItem('Diamond', this.Diamond);
  444. },
  445. InitDiamond: function () {
  446. if (cc.sys.localStorage.getItem('Diamond')) {
  447. this.Diamond = parseInt(cc.sys.localStorage.getItem('Diamond'));
  448. }
  449. else {
  450. this.InitDiamondFirst();
  451. }
  452. },
  453. InitWorkerLVFirst: function () {
  454. cc.sys.localStorage.setItem('WorkerLV', this.WorkerLV);
  455. },
  456. InitWorkerLV: function () {
  457. if (cc.sys.localStorage.getItem('WorkerLV')) {
  458. this.WorkerLV = parseInt(cc.sys.localStorage.getItem('WorkerLV'));
  459. }
  460. else {
  461. this.InitWorkerNumFirst();
  462. }
  463. },
  464. InitWorkerNumFirst: function () {
  465. cc.sys.localStorage.setItem('WorkerNum', this.WorkerNum);
  466. },
  467. InitWorkerNum: function () {
  468. if (cc.sys.localStorage.getItem('WorkerNum'))
  469. this.WorkerNum = parseInt(cc.sys.localStorage.getItem('WorkerNum'));
  470. else
  471. cc.warn('没有 workerNum 数据!');
  472. },
  473. InitWorkerCapacityFirst: function () {
  474. cc.sys.localStorage.setItem('WorkerCapacity', this.WorkerCapacity);
  475. },
  476. InitWorkerCapacity: function () {
  477. if (cc.sys.localStorage.getItem('WorkerCapacity')) {
  478. this.WorkerCapacity = parseInt(cc.sys.localStorage.getItem('WorkerCapacity'));
  479. }
  480. else {
  481. this.InitWorkerCapacityFirst();
  482. }
  483. },
  484. InitTerritoryStateArrayFirst: function () {
  485. cc.sys.localStorage.setItem('TerritoryStateArray', this.TerritoryStateArray.join('_'));
  486. },
  487. InitTerritoryStateArray: function () {
  488. if (cc.sys.localStorage.getItem('TerritoryStateArray')) {
  489. this.TerritoryStateArray = cc.sys.localStorage.getItem('TerritoryStateArray').split('_');
  490. }
  491. else {
  492. this.InitTerritoryStateArrayFirst();
  493. }
  494. },
  495. InitBuildingStateArrayFirst: function () {
  496. cc.sys.localStorage.setItem('BuildingStateArray', this.BuildingStateArray.join('_'));
  497. },
  498. InitBuildingStateArray: function () {
  499. if (cc.sys.localStorage.getItem('BuildingStateArray')) {
  500. this.BuildingStateArray = cc.sys.localStorage.getItem('BuildingStateArray').split('_');
  501. }
  502. else {
  503. this.InitBuildingStateArrayFirst();
  504. }
  505. },
  506. InitBuildingLockStateArrayFirst: function () {
  507. cc.sys.localStorage.setItem('BuildingLockStateArray', this.BuildingLockStateArray.join('_'));
  508. },
  509. InitBuildingLockStateArray: function () {
  510. if (cc.sys.localStorage.getItem('BuildingLockStateArray')) {
  511. this.BuildingLockStateArray = cc.sys.localStorage.getItem('BuildingLockStateArray').split('_');
  512. }
  513. else {
  514. this.InitBuildingLockStateArrayFirst();
  515. }
  516. },
  517. InitBuildingNumArrayFirst: function () {
  518. cc.sys.localStorage.setItem('BuildingNumArray', this.BuildingNumArray.join('_'));
  519. },
  520. InitBuildingNumArray: function () {
  521. if (cc.sys.localStorage.getItem('BuildingNumArray')) {
  522. this.BuildingNumArray = cc.sys.localStorage.getItem('BuildingNumArray').split('_');
  523. }
  524. else {
  525. this.InitBuildingNumArrayFirst();
  526. }
  527. },
  528. InitEveryDayRewardsArrayFirst: function () {
  529. cc.sys.localStorage.setItem('EveryDayRewardsArray', this.EveryDayRewardsArray.join('_'));
  530. },
  531. InitEveryDayRewardsArray: function () {
  532. if (cc.sys.localStorage.getItem('EveryDayRewardsArray')) {
  533. this.EveryDayRewardsArray = cc.sys.localStorage.getItem('EveryDayRewardsArray').split('_');
  534. }
  535. else {
  536. this.InitEveryDayRewardsArrayFirst();
  537. }
  538. },
  539. InitLastTimeEveryDayRewardsDateFirst: function () {
  540. cc.sys.localStorage.setItem('LastTimeEveryDayRewardsDate', this.LastTimeEveryDayRewardsDate);
  541. // cc.log('111111111111==='+cc.sys.localStorage.getItem('LastTimeEveryDayRewardsDate'));
  542. },
  543. InitLastTimeEveryDayRewardsDate: function () {
  544. if (cc.sys.localStorage.getItem('LastTimeEveryDayRewardsDate'))
  545. this.LastTimeEveryDayRewardsDate = cc.sys.localStorage.getItem('LastTimeEveryDayRewardsDate');
  546. else
  547. cc.warn('没有 LastTimeEveryDayRewardsDate 数据!');
  548. },
  549. InitFoodTradeStateFirst: function () {
  550. cc.sys.localStorage.setItem('FoodTradeState', this.FoodTradeState);
  551. },
  552. InitFoodTradeState: function () {
  553. if (cc.sys.localStorage.getItem('FoodTradeState')) {
  554. this.FoodTradeState = parseInt(cc.sys.localStorage.getItem('FoodTradeState'));
  555. }
  556. else {
  557. this.InitFoodTradeStateFirst();
  558. }
  559. },
  560. InitWoodTradeStateFirst: function () {
  561. cc.sys.localStorage.setItem('WoodTradeState', this.WoodTradeState);
  562. },
  563. InitWoodTradeState: function () {
  564. if (cc.sys.localStorage.getItem('WoodTradeState')) {
  565. this.WoodTradeState = parseInt(cc.sys.localStorage.getItem('WoodTradeState'));
  566. }
  567. else {
  568. this.InitWoodTradeStateFirst();
  569. }
  570. },
  571. InitMineralTradeStateFirst: function () {
  572. cc.sys.localStorage.setItem('MineralTradeState', this.MineralTradeState);
  573. },
  574. InitMineralTradeState: function () {
  575. if (cc.sys.localStorage.getItem('MineralTradeState')) {
  576. this.MineralTradeState = parseInt(cc.sys.localStorage.getItem('MineralTradeState'));
  577. }
  578. else {
  579. this.InitMineralTradeStateFirst();
  580. }
  581. },
  582. InitLotteryTimes: function () {
  583. if (cc.sys.localStorage.getItem('MineralTradeState')) {
  584. this.MineralTradeState = parseInt(cc.sys.localStorage.getItem('MineralTradeState'));
  585. }
  586. else {
  587. this.InitMineralTradeStateFirst();
  588. }
  589. },
  590. //GET / SET /Plus
  591. GetGameDate: function () {
  592. // if (!cc.sys.localStorage.getItem('GameDate')) {
  593. // this.InitGameDateFirst();
  594. // }
  595. return this.GameDate;
  596. },
  597. SetGameDate: function (num) {
  598. this.GameDate = num;
  599. // cc.sys.localStorage.setItem('GameDate', this.GameDate);
  600. // this.Goldenlabel.getComponent(cc.Label).string = this.Golden;
  601. },
  602. PlusGameDate: function (num) {
  603. this.GameDate += num;
  604. // cc.sys.localStorage.setItem('GameDate', this.GameDate);
  605. // this.Goldenlabel.getComponent(cc.Label).string = this.Golden;
  606. },
  607. GetGolden: function () {
  608. // if (!cc.sys.localStorage.getItem('Golden')) {
  609. // this.InitGoldenFirst();
  610. // }
  611. return parseInt(this.Golden);
  612. },
  613. GetGoldenCallBack(_CallBack) {
  614. // if (!cc.sys.localStorage.getItem('Golden')) {
  615. // this.InitGoldenFirst();
  616. // cc.log('GetGoldenCallBack1');
  617. // }
  618. if (_CallBack)
  619. _CallBack({ resGolden: parseInt(this.Golden) });
  620. },
  621. SetGolden: function (Num) {
  622. let LastMoney = this.Golden;
  623. this.Golden = Num;
  624. let CurrentMoney = Num;
  625. // var data1 = {
  626. // name: "Whoareyou",
  627. // openId : userData.openId,
  628. //
  629. // }
  630. // UtilsWX.postMessage(data1);
  631. // UtilsWX.setUserData("score", Num);
  632. // cc.sys.localStorage.setItem('Golden', this.Golden);
  633. // this.Goldenlabel.getComponent(cc.Label).string = this.Golden;
  634. this.ManageUI.getComponent('ManageUI').GoldenChangeCallBack(this.GetGolden(), LastMoney, CurrentMoney);
  635. },
  636. PlusGolden: function (Num) {
  637. if (this.Golden + Num < 0) {
  638. this.SetGolden(0);
  639. }
  640. else {
  641. this.SetGolden(this.Golden + Num);
  642. }
  643. // task.task50W();
  644. },
  645. GetDiamond: function () {
  646. // if (!cc.sys.localStorage.getItem('Diamond')) {
  647. // this.InitDiamondFirst();
  648. // }
  649. return parseInt(this.Diamond);
  650. },
  651. SetDiamond: function (num) {
  652. let LastMoney = this.Diamond;
  653. this.Diamond = num;
  654. let CurrentMoney = num;
  655. // cc.sys.localStorage.setItem('Diamond', this.Diamond);
  656. this.ManageUI.getComponent('ManageUI').DiamondChangeCallBack(this.GetDiamond(), LastMoney, CurrentMoney);
  657. },
  658. PlusDiamond: function (num) {
  659. if (this.Diamond + num < 0) {
  660. this.SetDiamond(0);
  661. }
  662. else {
  663. this.SetDiamond(this.Diamond + num);
  664. }
  665. },
  666. GetWorkerLV: function () {
  667. // if (!cc.sys.localStorage.getItem('WorkerLV')) {
  668. // this.InitWorkerLVFirst();
  669. // }
  670. return parseInt(this.WorkerLV);
  671. },
  672. SetWorkerLV: function (num) {
  673. this.WorkerLV = num;
  674. // cc.sys.localStorage.setItem('WorkerLV', this.WorkerLV);
  675. },
  676. PlusWorkerLV: function (num) {
  677. this.WorkerLV += num;
  678. // cc.sys.localStorage.setItem('WorkerLV', this.WorkerLV);
  679. },
  680. GetWorkerNum: function () {
  681. // if (!cc.sys.localStorage.getItem('WorkerNum')) {
  682. // this.InitWorkerNumFirst();
  683. // }
  684. // cc.log('get', this.WorkerNum);
  685. return parseInt(this.WorkerNum);
  686. },
  687. SetWorkerNum: function (num) {
  688. this.WorkerNum = num;
  689. // cc.sys.localStorage.setItem('WorkerNum', this.WorkerNum);
  690. },
  691. PlusWorkerNum: function (num) {
  692. this.WorkerNum += num;
  693. // cc.log('set', this.WorkerNum);
  694. // cc.sys.localStorage.setItem('WorkerNum', this.WorkerNum);
  695. },
  696. GetLastTimeEveryDayRewardsDate: function () {
  697. // if (!cc.sys.localStorage.getItem('LastTimeEveryDayRewardsDate')) {
  698. // this.InitLastTimeEveryDayRewardsDateFirst();
  699. // }
  700. // cc.log('get', this.WorkerNum);
  701. return this.LastTimeEveryDayRewardsDate;
  702. },
  703. //获取转盘 时间
  704. GetLastTimeLuckDate: function () {
  705. // if (!cc.sys.localStorage.getItem('LastTimeEveryDayRewardsDate')) {
  706. // this.InitLastTimeEveryDayRewardsDateFirst();
  707. // }
  708. // cc.log('get', this.WorkerNum);
  709. return this.LastTimeLuckDate;
  710. },
  711. //设置转盘时间
  712. SetLastTimeLuckDate: function (DateString) {
  713. this.LastTimeLuckDate = DateString;
  714. // cc.sys.localStorage.setItem('LastTimeEveryDayRewardsDate', this.LastTimeEveryDayRewardsDate);
  715. },
  716. SetLastTimeEveryDayRewardsDate: function (DateString) {
  717. this.LastTimeEveryDayRewardsDate = DateString;
  718. // cc.sys.localStorage.setItem('LastTimeEveryDayRewardsDate', this.LastTimeEveryDayRewardsDate);
  719. },
  720. //工人信息数组
  721. GetWorkerCharacterInfoArray: function () {
  722. return this.CharacterInfoArray;
  723. },
  724. SetWorkerCharacterInfoArray: function (item) {
  725. this.CharacterInfoArray = item;
  726. // cc.log('更新的数据:', this.CharacterInfoArray);
  727. //Init自动存储 todo
  728. },
  729. /*** */
  730. GetWorkerCapacity: function () {
  731. // if (!cc.sys.localStorage.getItem('WorkerCapacity')) {
  732. // this.InitWorkerCapacityFirst();
  733. // }
  734. return parseInt((this.WorkerCapacity));
  735. },
  736. SetWorkerCapacity: function (num) {
  737. this.WorkerCapacity = num;
  738. // cc.sys.localStorage.setItem('WorkerCapacity', this.WorkerCapacity);
  739. },
  740. PlusWorkerCapacity: function (num) {
  741. this.WorkerCapacity += num;
  742. // cc.sys.localStorage.setItem('WorkerCapacity', this.WorkerCapacity);
  743. },
  744. GetTerritoryStateArray: function () {
  745. // if (!cc.sys.localStorage.getItem('TerritoryStateArray')) {
  746. // this.InitTerritoryStateArrayFirst();
  747. // }
  748. return this.TerritoryStateArray;
  749. },
  750. SetTerritoryStateArray: function (aTerritoryStateArray) {
  751. this.TerritoryStateArray = aTerritoryStateArray;
  752. // cc.sys.localStorage.setItem('TerritoryStateArray', this.TerritoryStateArray.join('_'));
  753. },
  754. PlusTerritoryStateArray: function (Item) {
  755. this.TerritoryStateArray.push(Item);
  756. // cc.sys.localStorage.setItem('TerritoryStateArray', this.TerritoryStateArray.join('_'));
  757. },
  758. GetBuildingStateArray: function () {
  759. // if (!cc.sys.localStorage.getItem('BuildingStateArray')) {
  760. // this.InitBuildingStateArrayFirst();
  761. // }
  762. return this.BuildingStateArray;
  763. },
  764. SetBuildingStateArray: function (aBuildingStateArray) {
  765. this.BuildingStateArray = aBuildingStateArray;
  766. // cc.sys.localStorage.setItem('BuildingStateArray', this.BuildingStateArray.join('_'));
  767. },
  768. PlusBuildingStateArray: function (Item) {
  769. this.BuildingStateArray.push(Item);
  770. // cc.sys.localStorage.setItem('BuildingStateArray', this.BuildingStateArray.join('_'));
  771. },
  772. GetBuildingLockStateArray: function () {
  773. // if (!cc.sys.localStorage.getItem('BuildingLockStateArray')) {
  774. // this.InitBuildingLockStateArrayFirst();
  775. // }
  776. return this.BuildingLockStateArray;
  777. },
  778. SetBuildingLockStateArray: function (aArray) {
  779. this.BuildingLockStateArray = aArray;
  780. // cc.sys.localStorage.setItem('BuildingLockStateArray', this.BuildingLockStateArray.join('_'));
  781. },
  782. PlusBuildingLockStateArray: function (Item) {
  783. this.BuildingLockStateArray.push(Item);
  784. // cc.sys.localStorage.setItem('BuildingLockStateArray', this.BuildingLockStateArray.join('_'));
  785. },
  786. GetBuildingNumArray: function () {
  787. // if (!cc.sys.localStorage.getItem('BuildingNumArray')) {
  788. // this.InitBuildingNumArrayFirst();
  789. // }
  790. return this.BuildingNumArray;
  791. },
  792. SetBuildingNumArray: function (aBuildingNumArray) {
  793. this.BuildingNumArray = aBuildingNumArray;
  794. // cc.sys.localStorage.setItem('BuildingNumArray', this.BuildingNumArray.join('_'));
  795. },
  796. PlusBuildingNumArray: function (Item) {
  797. this.BuildingNumArray.push(Item);
  798. // cc.sys.localStorage.setItem('BuildingNumArray', this.BuildingNumArray.join('_'));
  799. },
  800. //操作钻石数据
  801. GetDiamondNumArray: function () {
  802. return this.DiamondNumArray;
  803. },
  804. SetDiamondNumArray: function (aDiamondNumArray) {
  805. this.DiamondNumArray = aDiamondNumArray;
  806. },
  807. GetEveryDayRewardsArray: function () {
  808. // if (!cc.sys.localStorage.getItem('EveryDayRewardsArray')) {
  809. // this.InitEveryDayRewardsArrayFirst();
  810. // }
  811. return this.EveryDayRewardsArray;
  812. },
  813. SetEveryDayRewardsArray: function (aArray) {
  814. this.EveryDayRewardsArray = aArray;
  815. // cc.sys.localStorage.setItem('EveryDayRewardsArray', this.EveryDayRewardsArray.join('_'));
  816. },
  817. PlusEveryDayRewardsArray: function (Item) {
  818. this.EveryDayRewardsArray.push(Item);
  819. // cc.sys.localStorage.setItem('EveryDayRewardsArray', this.EveryDayRewardsArray.join('_'));
  820. },
  821. GetFoodTradeState: function () {
  822. // if (!cc.sys.localStorage.getItem('FoodTradeState')) {
  823. // this.InitFoodTradeStateFirst();
  824. // }
  825. return parseInt((this.FoodTradeState));
  826. },
  827. SetFoodTradeState: function (num) {
  828. this.FoodTradeState = num;
  829. // cc.sys.localStorage.setItem('FoodTradeState', this.FoodTradeState);
  830. },
  831. PlusFoodTradeState: function (num) {
  832. this.FoodTradeState += num;
  833. // cc.sys.localStorage.setItem('FoodTradeState', this.FoodTradeState);
  834. },
  835. GetWoodTradeState: function () {
  836. // if (!cc.sys.localStorage.getItem('WoodTradeState')) {
  837. // this.InitWoodTradeStateFirst();
  838. // }
  839. return parseInt((this.WoodTradeState));
  840. },
  841. SetWoodTradeState: function (num) {
  842. this.WoodTradeState = num;
  843. // cc.sys.localStorage.setItem('WoodTradeState', this.WoodTradeState);
  844. },
  845. PlusWoodTradeState: function (num) {
  846. this.WoodTradeState += num;
  847. // cc.sys.localStorage.setItem('WoodTradeState', this.WoodTradeState);
  848. },
  849. GetMineralTradeState: function () {
  850. // if (!cc.sys.localStorage.getItem('MineralTradeState')) {
  851. // this.InitMineralTradeStateFirst();
  852. // }
  853. return parseInt((this.MineralTradeState));
  854. },
  855. SetMineralTradeState: function (num) {
  856. this.MineralTradeState = num;
  857. // cc.sys.localStorage.setItem('MineralTradeState', this.MineralTradeState);
  858. },
  859. PlusMineralTradeState: function (num) {
  860. this.MineralTradeState += num;
  861. // cc.sys.localStorage.setItem('MineralTradeState', this.MineralTradeState);
  862. },
  863. GetLotteryTimes: function () {
  864. return parseInt((this.LotteryTimes));
  865. },
  866. SetLotteryTimes: function (num) {
  867. this.LotteryTimes = num;
  868. },
  869. PlusLotteryTimes: function (num) {
  870. this.LotteryTimes += num;
  871. },
  872. //Reset
  873. ResetFirstLoadGame: function () {
  874. cc.sys.localStorage.removeItem('BFirstLoadGame');
  875. },
  876. ResetDate: function () {
  877. cc.sys.localStorage.removeItem('GameDay');
  878. cc.sys.localStorage.removeItem('GameMonth');
  879. cc.sys.localStorage.removeItem('GameDay');
  880. },
  881. ResetGameDate: function () {
  882. cc.sys.localStorage.removeItem('GameDate');
  883. },
  884. ResetGold: function () {
  885. cc.sys.localStorage.removeItem('Golden');
  886. },
  887. ResetDiamond: function () {
  888. cc.sys.localStorage.removeItem('Diamond');
  889. },
  890. ResetWorkerLV: function () {
  891. cc.sys.localStorage.removeItem('WorkerLV');
  892. },
  893. ResetWorkerNum: function () {
  894. cc.sys.localStorage.removeItem('WorkerNum');
  895. },
  896. ResetWorkerCapacity: function () {
  897. cc.sys.localStorage.removeItem('WorkerCapacity');
  898. },
  899. ResetTerritoryStateArray: function () {
  900. cc.sys.localStorage.removeItem('TerritoryStateArray');
  901. },
  902. ResetBuildingStateArray: function () {
  903. cc.sys.localStorage.removeItem('BuildingStateArray');
  904. },
  905. ResetBuildingLockStateArray: function () {
  906. cc.sys.localStorage.removeItem('BuildingLockStateArray');
  907. },
  908. ResetBuildingNumArray: function () {
  909. cc.sys.localStorage.removeItem('BuildingNumArray');
  910. },
  911. ResetEveryDayRewardsArray: function () {
  912. cc.sys.localStorage.removeItem('EveryDayRewardsArray');
  913. },
  914. ResetLastTimeEveryDayRewardsDate: function () {
  915. cc.sys.localStorage.removeItem('LastTimeEveryDayRewardsDate');
  916. },
  917. ResetFoodTradeState: function () {
  918. cc.sys.localStorage.removeItem('FoodTradeState');
  919. },
  920. ResetWoodTradeState: function () {
  921. cc.sys.localStorage.removeItem('WoodTradeState');
  922. },
  923. ResetMineralTradeState: function () {
  924. cc.sys.localStorage.removeItem('MineralTradeState');
  925. },
  926. ResetLotteryTimes: function () {
  927. cc.sys.localStorage.removeItem('LotteryTimes');
  928. },
  929. //RestAll
  930. ResetAll: function () {
  931. this.ResetFirstLoadGame();
  932. this.ResetDate();
  933. this.ResetGameDate()
  934. this.ResetGold();
  935. this.ResetDiamond();
  936. this.ResetWorkerLV();
  937. this.ResetWorkerNum();
  938. this.ResetWorkerCapacity();
  939. this.ResetTerritoryStateArray();
  940. this.ResetBuildingStateArray();
  941. this.ResetBuildingLockStateArray();
  942. this.ResetBuildingNumArray();
  943. this.ResetEveryDayRewardsArray();
  944. this.ResetLastTimeEveryDayRewardsDate();
  945. this.ResetFoodTradeState();
  946. this.ResetWoodTradeState();
  947. this.ResetMineralTradeState();
  948. this.ResetLotteryTimes();
  949. },
  950. ResetDate: function () {
  951. this.FullDate = [0, 0, 0];
  952. cc.sys.localStorage.setItem('Date', this.FullDate);
  953. },
  954. onSaveData() {
  955. this.onAutoSaveData();
  956. },
  957. //自动保存的数据,在init调用,这是保存到本地硬盘中
  958. onAutoSaveData() {
  959. //保存金币
  960. cc.sys.localStorage.setItem('Golden', this.Golden);
  961. //保存钻石
  962. cc.sys.localStorage.setItem('Diamond', this.Diamond);
  963. //工人等级
  964. cc.sys.localStorage.setItem('WorkerLV', this.WorkerLV);
  965. //工人数量
  966. cc.sys.localStorage.setItem('WorkerNum', this.WorkerNum);
  967. //工人最大容量
  968. cc.sys.localStorage.setItem('WorkerCapacity', this.WorkerCapacity);
  969. //游戏日期
  970. cc.sys.localStorage.setItem('GameDate', this.GameDate);
  971. //最后一次领奖日期
  972. cc.sys.localStorage.setItem('LastTimeEveryDayRewardsDate', this.LastTimeEveryDayRewardsDate);
  973. //每日奖励数组
  974. cc.sys.localStorage.setItem('EveryDayRewardsArray', this.EveryDayRewardsArray.join('_'));
  975. //区域状态数组
  976. cc.sys.localStorage.setItem('TerritoryStateArray', this.TerritoryStateArray.join('_'));
  977. //面板
  978. //建筑状态数组
  979. cc.sys.localStorage.setItem('BuildingStateArray', this.BuildingStateArray.join('_'));
  980. //可以建造的建筑数量数组
  981. cc.sys.localStorage.setItem('BuildingNumArray', this.BuildingNumArray.join('_'));
  982. //食物销售状态
  983. cc.sys.localStorage.setItem('FoodTradeState', this.FoodTradeState);
  984. //木材销售状态
  985. cc.sys.localStorage.setItem('WoodTradeState', this.WoodTradeState);
  986. //矿石销售状态
  987. cc.sys.localStorage.setItem('MineralTradeState', this.MineralTradeState);
  988. //抽奖次数
  989. cc.sys.localStorage.setItem('LotteryTimes', this.LotteryTimes);
  990. //工人工作的信息
  991. if (this.CharacterInfoArray) {
  992. // cc.log('自动保存数据:', this.CharacterInfoArray);
  993. cc.sys.localStorage.setItem('CharacterInfoArray', JSON.stringify(this.CharacterInfoArray));
  994. }
  995. //道路数据
  996. let hightway = {
  997. highwayIndex: this.GameData_highwayIndex,
  998. AllHighwayStylesAndIndex: GlobalD.game.AllHighwayStylesAndIndex,
  999. };
  1000. // cc.log('道路数据:', (hightway));
  1001. cc.sys.localStorage.setItem('highway', JSON.stringify(hightway));
  1002. //建筑物数据
  1003. cc.sys.localStorage.setItem('Buildings', JSON.stringify(this.GameData_buildings));
  1004. let getbuildingsData = cc.sys.localStorage.getItem('Buildings');
  1005. if (getbuildingsData)
  1006. this.GameData_buildings = JSON.parse(getbuildingsData);
  1007. // cc.log('getbuildingsData2222= '+getbuildingsData);
  1008. },
  1009. //清除所有的数据
  1010. onClearAllData(callback) {
  1011. this.pushCleaData(callback);
  1012. //清空首次登陆时间记录
  1013. //记录二次登陆视频奖励
  1014. cc.sys.localStorage.removeItem('loginRewardDate');
  1015. //公路数据
  1016. cc.sys.localStorage.removeItem('highway');
  1017. //建筑数据
  1018. cc.sys.localStorage.removeItem('Buildings');
  1019. //人物信息数据
  1020. cc.sys.localStorage.removeItem('CharacterInfoArray');
  1021. //任务索引
  1022. cc.sys.localStorage.removeItem('TaskIconCountClick');
  1023. this.ResetAll();
  1024. },
  1025. onClearAndGotoLogin() {
  1026. this.onClearAllData(() => {
  1027. this.unschedule(this.AutoSaveData);
  1028. cc.director.loadScene('Login', function () {
  1029. task.showPointerNode = null;
  1030. }.bind(this));
  1031. });
  1032. },
  1033. //初始化道路
  1034. onSpawnHighway() {
  1035. // 获取InitPoint层
  1036. let InitPos = this._tiledMap.getLayer('InitPoint');
  1037. InitPos.enabled = false;
  1038. // //道路数据
  1039. // highwayIndex: this.GameData_highwayIndex,
  1040. // allHighwayStylesAndIndex: GlobalD.game.AllHighwayStylesAndIndex,
  1041. // var highwayTemp = cc.sys.localStorage.getItem('highway');
  1042. //创建公路数据
  1043. if (this.readData) {
  1044. //保存到内存中
  1045. this.GameData_highwayIndex = this.readData.highwayIndex;
  1046. //先赋值道路的对象数组
  1047. let _AllHighwayAIndex = GlobalD.game.AllHighwayStylesAndIndex = this.readData.allHighwayStylesAndIndex;
  1048. //获取最后建造公路的层级
  1049. this.HighwayLayer = this._tiledMap.getLayer('Highway');
  1050. for (let i = 0; i < _AllHighwayAIndex.length; i++) {
  1051. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  1052. highwayTemp.parent = this.HighwayLayer.node;
  1053. let tiledTile = highwayTemp.addComponent('TiledTile');
  1054. let _tiledPos = GlobalD.TiledMap.analyticalIndexData(_AllHighwayAIndex[i].highwayInfoIndex);
  1055. tiledTile.x = _tiledPos.x;
  1056. tiledTile.y = _tiledPos.y;
  1057. //地图设置可行走区域公路设置
  1058. AStar.setMapSolid(_tiledPos.x, _tiledPos.y, 0);
  1059. // _buildId ==0 是公路
  1060. let _buildId = 0;
  1061. let occupyTemp = cc.v2(_buildId, _AllHighwayAIndex[i].highwayInfoIndex);
  1062. GlobalD.game.OccupyArray.push(occupyTemp);
  1063. highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(_AllHighwayAIndex[i].highwayInfoType);
  1064. }
  1065. } else {
  1066. //如果用户没有存储数据
  1067. //根据InitPoint 的数据,创建初始化的地图数据 的初始化数据
  1068. this.HighwayLayer = this._tiledMap.getLayer('Highway');
  1069. for (var i = 0; i < 29; i++) {
  1070. for (var j = 0; j < 32; j++) {
  1071. let tilesPos = cc.v2(i, j);
  1072. if (InitPos.getTileGIDAt(tilesPos)) {
  1073. let index = GlobalD.TiledMap.getIndex(tilesPos);
  1074. this.GameData_highwayIndex.push(index);
  1075. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  1076. highwayTemp.parent = this.HighwayLayer.node;
  1077. let tiledTile = highwayTemp.addComponent('TiledTile');
  1078. tiledTile.x = tilesPos.x;
  1079. tiledTile.y = tilesPos.y;
  1080. // cc.log('onSpawnHighway2');
  1081. //地图设置可行走区域公路设置
  1082. AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
  1083. // _buildId ==0 是公路
  1084. let _buildId = 0;
  1085. let occupyTemp = cc.v2(_buildId, index);
  1086. GlobalD.game.OccupyArray.push(occupyTemp);
  1087. let tile = InitPos.getTiledTileAt(tilesPos.x, tilesPos.y, true);
  1088. let _MoveType = reGameStates.HighwayType.moveX;
  1089. // if (tile.gid == 15) {
  1090. // _MoveType = reGameStates.HighwayType.moveX;
  1091. // } else
  1092. if (tile.gid == 16) {
  1093. _MoveType = reGameStates.HighwayType.moveY;
  1094. } else if (tile.gid == 11) {
  1095. _MoveType = reGameStates.HighwayType.ZebraCrossingX;
  1096. } else if (tile.gid == 12) {
  1097. _MoveType = reGameStates.HighwayType.ZebraCrossingY;
  1098. }
  1099. // return;
  1100. //更换公路样式
  1101. GlobalD.game.onCreateDifferentRoadStyles({
  1102. _buildId: _buildId,
  1103. _highwayType: _MoveType,
  1104. _roadIndex: index,
  1105. _hightwayNode: highwayTemp
  1106. });
  1107. }
  1108. }
  1109. }
  1110. }
  1111. //外面的两条路
  1112. let initRoad = this._tiledMap.getLayer('Road');
  1113. initRoad.enabled = false;
  1114. for (var i = 29; i < 31; i++) {
  1115. for (var j = 0; j < 32; j++) {
  1116. let tilesPos = cc.v2(i, j);
  1117. // cc.log('road tilesPos',tilesPos)
  1118. if (initRoad.getTileGIDAt(tilesPos)) {
  1119. let index = GlobalD.TiledMap.getIndex(tilesPos);
  1120. this.GameData_highwayIndex.push(index);
  1121. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  1122. highwayTemp.parent = this.HighwayLayer.node;
  1123. let tiledTile = highwayTemp.addComponent('TiledTile');
  1124. tiledTile.x = tilesPos.x;
  1125. tiledTile.y = tilesPos.y;
  1126. // cc.log('initRoad');
  1127. //地图设置可行走区域公路设置
  1128. AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
  1129. let _buildId = 0;
  1130. let occupyTemp = cc.v2(_buildId, index);
  1131. GlobalD.game.OccupyArray.push(occupyTemp);
  1132. //更换公路样式
  1133. if (j >= 25 && j <= 27 || j >= 19 && j <= 21 || j >= 9 && j <= 11)
  1134. highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.none);
  1135. else
  1136. highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.moveY);
  1137. }
  1138. }
  1139. }
  1140. },
  1141. //上传清空数据的请求
  1142. pushCleaData(callback) {
  1143. if ( userData.openId == "test") {
  1144. if (callback != null) {
  1145. callback();
  1146. }
  1147. return;
  1148. }
  1149. var data = {
  1150. openid : userData.openId,
  1151. userdata : ""
  1152. };
  1153. httpUtils.Post(httpUtils.setUserData, data, function (resData) {
  1154. // console.log("push清空成功", resData);
  1155. if (resData.code == 0) {
  1156. // this.getText.string = data.data.userdata;
  1157. }
  1158. if (callback != null) {
  1159. callback();
  1160. }
  1161. }.bind(this), function (resData) {
  1162. // console.log("失败", resData);
  1163. if (callback != null) {
  1164. callback();
  1165. }
  1166. }.bind(this));
  1167. },
  1168. //保存数据请求
  1169. pushData: function () {
  1170. if ( userData.openId == "test") {
  1171. return;
  1172. }
  1173. // cc.log(this.EveryDayRewardsArray);
  1174. var datas = {
  1175. version: this.GameVersion,
  1176. BFirstLoadGame: 1,//只要push数据,就证明已经开始第一次游戏了
  1177. //时间
  1178. GameYear: this.GameYear,
  1179. GameMonth: this.GameMonth,
  1180. GameDay: this.GameDay,
  1181. Golden: this.Golden,
  1182. Diamond: this.Diamond,
  1183. WorkerLV: this.WorkerLV,
  1184. WorkerNum: this.WorkerNum,
  1185. WorkerCapacity: this.WorkerCapacity,
  1186. GameDate: this.GameDate,
  1187. LastTimeEveryDayRewardsDate: this.LastTimeEveryDayRewardsDate,
  1188. LastTimeLuckDate: this.LastTimeLuckDate,
  1189. EveryDayRewardsArray: this.EveryDayRewardsArray.join('_'),
  1190. TerritoryStateArray: this.TerritoryStateArray.join('_'),
  1191. //面板状态
  1192. BuildingStateArray: this.BuildingStateArray.join('_'),
  1193. BuildingLockStateArray: this.BuildingLockStateArray.join('_'),
  1194. BuildingNumArray: this.BuildingNumArray.join('_'),
  1195. DiamondNumArray: this.DiamondNumArray.join('_'),
  1196. FoodTradeState: this.FoodTradeState,
  1197. WoodTradeState: this.WoodTradeState,
  1198. MineralTradeState: this.MineralTradeState,
  1199. LotteryTimes: this.LotteryTimes,
  1200. //工人工作信息
  1201. characterInfoArray: this.CharacterInfoArray,
  1202. //道路数据
  1203. highwayIndex: this.GameData_highwayIndex,
  1204. allHighwayStylesAndIndex: GlobalD.game.AllHighwayStylesAndIndex,
  1205. //建筑物数据
  1206. buildingsInfo: this.GameData_buildings,
  1207. //任务
  1208. TaskIconCountClick: task.TaskIconCountClick
  1209. }
  1210. var data = {
  1211. openid : userData.openId,
  1212. userdata : JSON.stringify(datas)
  1213. };
  1214. // console.log("提交的数据是", datas);
  1215. httpUtils.Post(httpUtils.setUserData, data, function (resData) {
  1216. // let _userData = resData.data.userdata;
  1217. // let _JsonData = JSON.parse(_userData);
  1218. // console.log("push成功", resData, _JsonData);
  1219. // if (resData.code == 0) {
  1220. // this.getText.string = data.data.userdata;
  1221. // }
  1222. }.bind(this), function (resData) {
  1223. // console.log("失败", resData);
  1224. }.bind(this));
  1225. },
  1226. getNetworkData: function (callback) {
  1227. // console.log("获取数据成功:", data);
  1228. // var datas = {
  1229. // money: 3254857,
  1230. // lv: 99
  1231. // }
  1232. var data = {
  1233. openid : userData.openId
  1234. };
  1235. // data["userdata"] = JSON.stringify(datas);
  1236. httpUtils.Post(httpUtils.getUserData, data, function (data) {
  1237. callback(data);
  1238. }.bind(this), function (data) {
  1239. // console.log("失败", data);
  1240. callback(data);
  1241. }.bind(this));
  1242. },
  1243. onSetTaskIconCountClick() {
  1244. task.TaskIconCountClick = 0;
  1245. }
  1246. });