GameData.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. var reGameStates = require('GameStates');
  2. var AConfig = require('../Config');
  3. import utils from "../Network/netUtils";
  4. import GameNet from "../Network/GameNet"
  5. //全局数据类
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. //记录全部道路的index
  10. GameData_highwayIndex: {
  11. default: [],
  12. type: [cc.Integer],
  13. visible: false,
  14. serializable: false,
  15. },
  16. //记录建筑物存储的信息
  17. GameData_buildings: {
  18. default: [],
  19. visible: false,
  20. serializable: false,
  21. },
  22. HighWayPrefabs: cc.Prefab,
  23. //MyMapNode
  24. //建筑物的节点
  25. BuildingsParent: {
  26. default: null,
  27. type: cc.Node,
  28. },
  29. ManageUI: {
  30. default: null,
  31. type: cc.Node,
  32. },
  33. GameVersion: {
  34. default: -1,
  35. type: cc.Integer,
  36. },
  37. //读取数据
  38. readData: {
  39. default: null,
  40. visible: false,
  41. },
  42. /**
  43. * 接口
  44. * todo cnt和snb 由钱包读取
  45. */
  46. CNT: {
  47. default: 0,
  48. visible: false,
  49. },
  50. SNB: {
  51. default: 0,
  52. visible: false,
  53. },
  54. },
  55. onLoad() {
  56. //初始化GameData全局变量
  57. GlobalD.GameData = this;
  58. this.GameConfig();
  59. },
  60. GameConfig() {
  61. this.AddBuildingCost = 5;
  62. this.RemoveBuildingCost = 5;
  63. //
  64. this.Dapp = {
  65. UserInfo: null
  66. }
  67. },
  68. start() {
  69. this._tiledMap = GlobalD.TiledMap._tiledMap;
  70. //调用初始化dapp
  71. this.isDebugMode(GlobalD.dapp);
  72. },
  73. /**
  74. * 根据 不存在dapp 的话,使用本地测试
  75. * @param {*} bInit
  76. */
  77. isDebugMode: function (bInit) {
  78. if (bInit) {
  79. //读取网络数据
  80. try {
  81. GlobalD.dapp.cntBalance().then((cntBalance) => {
  82. //会延迟返回
  83. console.log("获取cnt:" + cntBalance) // string, 精度18,需要自行处理省略几位小数
  84. GlobalD.GameData.SetCNT(cntBalance);
  85. });
  86. } catch (err) {
  87. console.error(err) // 初始化失败,运行环境不是钱包环境
  88. }
  89. //登录时候已经初始化好snb了
  90. this.SNB = GlobalD.UserInfo.snb;
  91. this.readData = userData.readData;
  92. // cc.log('playerPullInfo 读取到数据?:', this.readData)
  93. this.InitNextworkData();
  94. this.InitSceneInfo();
  95. // 自动存储数据
  96. /**
  97. * todo 如果退出游戏,触发一次存储。
  98. */
  99. this.AutoSaveData = function () {
  100. this.pushData(true);
  101. };
  102. this.schedule(this.AutoSaveData, 20);
  103. } else {
  104. // 清除
  105. cc.log("本地数据重新开始,并且不初始化");
  106. // this.onClearAllData();
  107. this.Init();
  108. this.InitSceneInfo();
  109. this.AutoSaveData = function () {
  110. this.pushData(false);
  111. };
  112. this.schedule(this.AutoSaveData, 20);
  113. }
  114. },
  115. getData: function () {
  116. //如果开局没有读取到网络数据,就这里初始化
  117. if (userData.readData == null) {
  118. cc.log("本地数据:", cc.sys.localStorage.getItem('userdata'));
  119. let userdata = cc.sys.localStorage.getItem('userdata');
  120. if (userdata) {
  121. this.readData = JSON.parse(userdata);
  122. }
  123. this.Init();
  124. this.InitSceneInfo();
  125. } else {
  126. this.readData = userData.readData;
  127. cc.log('读取到数据?:', this.readData)
  128. this.Init();
  129. this.InitSceneInfo();
  130. }
  131. },
  132. InitSceneInfo() {
  133. //根据顺序生成
  134. //初始化道路
  135. this.onSpawnHighway();
  136. //初始化时间ui
  137. cc.find("GameNode/ManageTimer").getComponent('ManageTimer').Init();
  138. //初始化金钱ui,gold,diamond, cnt,snb,
  139. cc.find("GameNode/ManageGolden").getComponent('ManageGolden').InitManageGlodenUI();
  140. // //初始化地图物件
  141. // cc.find("GameNode/ManageMap").getComponent('ManageMap').InitManageMap();
  142. GlobalD.TiledMap.onInitSolid();
  143. //tudo 初始化DApp固定土地
  144. //初始化生成房屋
  145. this.ManageUI.getComponent('ManageBuildings').InitBuildings();
  146. //初始化生成人物
  147. cc.find('GameNode/ManageWorker').getComponent('ManageWorker').InitWorkerAI();
  148. let _BFirstLoadGame = this.readData ? this.readData.BFirstLoadGame : 0;
  149. //初始化新手教学
  150. GlobalD.ManageTask.InitTask(_BFirstLoadGame);
  151. this.ManageUI.getComponent('ManageUI').Init();
  152. },
  153. InitNextworkData() {
  154. console.log("this.readData", this.readData);
  155. this.Golden = this.readData.Golden;
  156. this.Diamond = this.readData.Diamond;
  157. this.shareGive = this.readData.shareGive;
  158. //签到分享给钻石金币
  159. this.signInGive = this.readData.signInGive;
  160. //每个月 给的 低保
  161. this.EveryGive = this.readData.EveryGive;
  162. //公共分享
  163. this.publicGive = this.readData.publicGive;
  164. // cc.log('初始化网络数据');
  165. //读取日期数据
  166. this.GameYear = this.readData.GameYear;
  167. this.GameMonth = this.readData.GameMonth;
  168. this.GameDay = this.readData.GameDay;
  169. //读取金币
  170. this.Golden = this.readData.Golden;
  171. //读取钻石
  172. this.Diamond = this.readData.Diamond;
  173. // cc.log('this.readData.Diamond', this.readData.Diamond);
  174. //读取工人等级
  175. this.WorkerLV = this.readData.WorkerLV;
  176. //工人数量
  177. this.WorkerNum = this.readData.WorkerNum;
  178. //工人容量
  179. this.WorkerCapacity = this.readData.WorkerCapacity;
  180. this.GameDate = this.readData.GameDate;
  181. this.LastTimeEveryDayRewardsDate = this.readData.LastTimeEveryDayRewardsDate;
  182. this.LastTimeLuckDate = this.readData.LastTimeLuckDate;
  183. this.EveryDayRewardsArray = this.readData.EveryDayRewardsArray;//.split('_');
  184. this.TerritoryStateArray = this.readData.TerritoryStateArray;//.split('_');
  185. //面板状态
  186. this.BuildingStateArray = this.readData.BuildingStateArray;//.split('_');
  187. //解锁设置为 不用解锁
  188. // this.BuildingLockStateArray.forEach((value, index, array) => {
  189. // array[index] = 1;
  190. // })
  191. this.BuildingLockStateArray = this.readData.BuildingLockStateArray;//.split('_');
  192. this.BuildingNumArray = this.readData.BuildingNumArray;//.split('_');
  193. this.DiamondNumArray = this.readData.DiamondNumArray;//.split('_');
  194. this.FoodTradeState = this.readData.FoodTradeState;
  195. this.WoodTradeState = this.readData.WoodTradeState;
  196. this.MineralTradeState = this.readData.MineralTradeState;
  197. //工人工作信息
  198. if (this.readData.characterInfoArray) {
  199. this.CharacterInfoArray = this.readData.characterInfoArray;
  200. } else {
  201. this.CharacterInfoArray = [];
  202. }
  203. //道路数据
  204. if (this.readData.highwayIndex)
  205. this.GameData_highwayIndex = this.readData.highwayIndex;
  206. //建筑物数据
  207. if (this.readData.buildingsInfo)
  208. this.GameData_buildings = this.readData.buildingsInfo;
  209. this.LotteryTimes = this.readData.LotteryTimes;
  210. //任务
  211. if (this.readData.TaskIconCountClick)
  212. task.TaskIconCountClick = this.readData.TaskIconCountClick;
  213. },
  214. /**
  215. * 初始化
  216. */
  217. Init: function () {
  218. let _BFirstLoadGame = false;// this.readData ? this.readData.BFirstLoadGame : 0;
  219. //date
  220. this.GameYear = 0;
  221. this.GameMonth = 0;
  222. this.GameDay = 0;
  223. this.GameDate = '0000/00/01';
  224. /**
  225. * 新增 CNT 和 SNB
  226. */
  227. this.CNT = 0;
  228. this.SNB = 0;
  229. this.Golden = 2000;
  230. this.Diamond = 100;
  231. this.WorkerLV = 0;
  232. this.WorkerNum = 0;
  233. this.CharacterInfoArray = [];
  234. this.WorkerCapacity = 5;
  235. this.TerritoryStateArray = [1, 1, 1, 1, 1, 1, 1, 1];//测试,全开地图
  236. /**
  237. * 添加建筑往后添加,到时候ManageBuildings 脚本 会初始化根据顺序
  238. * BuildingStateArray---相关 GetBuildingStateArray 获取建筑状态
  239. * BuildingNumArray ---相关 GetBuildingNumArray 获取建筑数量
  240. * BuildingFrameArray ---相关 ManageUI 添加面板是否解锁之类的相关预制
  241. */
  242. this.BuildingStateArray = [
  243. 1, //公路
  244. 1, //路铲
  245. 1, //拆迁
  246. 1, //农舍
  247. 1, //单元楼
  248. 1, //别墅
  249. 1, //农田
  250. 1,//伐木场
  251. 1, //矿坑
  252. 1, //加工厂
  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. 1, //粉色城堡
  274. 1, //Holy Farmland
  275. 1 //Holy Farmland seed
  276. ];
  277. this.BuildingLockStateArray = [
  278. 1, //公路
  279. 1, //路铲
  280. 1, //拆迁
  281. 1, //农舍
  282. 0, //单元楼
  283. 0, //别墅
  284. 1, //农田
  285. 0,//伐木场
  286. 0, //矿坑
  287. 1, //加工厂
  288. 0,//冷饮摊
  289. 0,//贩卖机
  290. 0,//面包房
  291. 0,//早餐车
  292. 0, //饮茶店
  293. 0,//点心店
  294. 0, //美食店
  295. 0,//西餐厅
  296. 0, //花店
  297. 0, //美发店
  298. 0,//洋装店
  299. 0, //珠宝店
  300. 0, //电影院
  301. 1,//路灯
  302. 1, //绿化带
  303. 1, //花坛
  304. 0,//喷泉
  305. 0, //警察局
  306. 0,//游乐场
  307. 0, //蓝色城堡
  308. 0, //粉色城堡
  309. 1, //Holy Farmland
  310. 1, //Holy Farmland seed
  311. ];
  312. //建筑物数量
  313. this.BuildingNumArray = [
  314. 0, //公路
  315. 0, //路铲
  316. 0, //拆迁
  317. 4, //农舍
  318. 1, //单元楼
  319. 1, //别墅
  320. 4, //农田
  321. 1,//伐木场
  322. 1, //矿坑
  323. 2, //加工厂
  324. 2,//冷饮摊
  325. 1,//贩卖机
  326. 1,//面包房
  327. 1,//早餐车
  328. 1, //饮茶店
  329. 1,//点心店
  330. 1, //美食店
  331. 1,//西餐厅
  332. 1, //花店
  333. 1, //美发店
  334. 1,//洋装店
  335. 1, //珠宝店
  336. 1, //电影院
  337. 1,//路灯
  338. 1, //绿化带
  339. 1, //花坛
  340. 1,//喷泉
  341. 1, //警察局
  342. 1,//游乐场
  343. 1, //蓝色城堡
  344. 1, //粉色城堡
  345. 1, //Holy Farmland
  346. 1, //Holy Farmland seed
  347. ];
  348. this.DiamondNumArray = AConfig.DiamondArray;
  349. //todo 钻石消耗默认值
  350. this.DiamondNumArray.forEach((value, index, array) => {
  351. array[index] = 0;
  352. })
  353. cc.log('钻石消耗默认值', this.DiamondNumArray);
  354. this.EveryDayRewardsArray = [0, 0, 0, 0, 0, 0, 0];
  355. this.LastTimeEveryDayRewardsDate = '0000/00/00';
  356. this.LastTimeLuckDate = '0000/00/00';
  357. this.FoodTradeState = 1;
  358. this.WoodTradeState = 1;
  359. this.MineralTradeState = 1;
  360. //转盘分享给钻石金币
  361. this.shareGive = [200, 5];
  362. //签到分享给钻石金币
  363. this.signInGive = [200, 5];
  364. //每个月 给的 低保
  365. this.EveryGive = [500, 10];
  366. //公共分享
  367. this.publicGive = [200, 50];
  368. //每天抽奖次数
  369. this.LotteryTimes = 10;
  370. // 1 === _BFirstLoadGame
  371. if (_BFirstLoadGame) {
  372. console.log("this.readData", this.readData);
  373. // cc.log('初始化网络数据');
  374. //读取日期数据
  375. this.GameYear = this.readData.GameYear;
  376. this.GameMonth = this.readData.GameMonth;
  377. this.GameDay = this.readData.GameDay;
  378. /**
  379. * 接口
  380. * todo cnt和snb 由钱包读取
  381. */
  382. this.CNT = 0;
  383. this.SNB = 0;
  384. //读取金币
  385. this.Golden = this.readData.Golden;
  386. //读取钻石
  387. this.Diamond = this.readData.Diamond;
  388. // cc.log('this.readData.Diamond', this.readData.Diamond);
  389. //读取工人等级
  390. this.WorkerLV = this.readData.WorkerLV;
  391. //工人数量
  392. this.WorkerNum = this.readData.WorkerNum;
  393. //工人容量
  394. this.WorkerCapacity = this.readData.WorkerCapacity;
  395. this.GameDate = this.readData.GameDate;
  396. this.LastTimeEveryDayRewardsDate = this.readData.LastTimeEveryDayRewardsDate;
  397. this.LastTimeLuckDate = this.readData.LastTimeLuckDate;
  398. this.EveryDayRewardsArray = this.readData.EveryDayRewardsArray;//.split('_');
  399. this.TerritoryStateArray = this.readData.TerritoryStateArray;//.split('_');
  400. //面板状态
  401. this.BuildingStateArray = this.readData.BuildingStateArray;//.split('_');
  402. //解锁设置为 不用解锁
  403. this.BuildingLockStateArray.forEach((value, index, array) => {
  404. array[index] = 1;
  405. })
  406. // this.BuildingLockStateArray = this.readData.BuildingLockStateArray.split('_');
  407. this.BuildingNumArray = this.readData.BuildingNumArray;//.split('_');
  408. this.DiamondNumArray = this.readData.DiamondNumArray;//.split('_');
  409. this.FoodTradeState = this.readData.FoodTradeState;
  410. this.WoodTradeState = this.readData.WoodTradeState;
  411. this.MineralTradeState = this.readData.MineralTradeState;
  412. //工人工作信息
  413. if (this.readData.characterInfoArray)
  414. this.CharacterInfoArray = this.readData.characterInfoArray;
  415. //道路数据
  416. if (this.readData.highwayIndex)
  417. this.GameData_highwayIndex = this.readData.highwayIndex;
  418. //建筑物数据
  419. if (this.readData.buildingsInfo)
  420. this.GameData_buildings = this.readData.buildingsInfo;
  421. this.LotteryTimes = this.readData.LotteryTimes;
  422. //任务
  423. if (this.readData.TaskIconCountClick)
  424. task.TaskIconCountClick = this.readData.TaskIconCountClick;
  425. //测试5W
  426. // this.PlusDiamond(50000);
  427. }
  428. },
  429. //GET / SET /Plus
  430. GetGameDate: function () {
  431. return this.GameDate;
  432. },
  433. SetGameDate: function (num) {
  434. this.GameDate = num;
  435. },
  436. PlusGameDate: function (num) {
  437. this.GameDate += num;
  438. },
  439. GetGolden: function () {
  440. return parseInt(this.Golden);
  441. },
  442. GetGoldenCallBack(_CallBack) {
  443. if (_CallBack)
  444. _CallBack({ resGolden: parseInt(this.Golden) });
  445. },
  446. SetGolden: function (Num) {
  447. let LastMoney = this.Golden;
  448. this.Golden = Num;
  449. let CurrentMoney = Num;
  450. this.ManageUI.getComponent('ManageUI').GoldenChangeCallBack(this.GetGolden(), LastMoney, CurrentMoney);
  451. },
  452. PlusGolden: function (Num) {
  453. if (this.Golden + Num < 0) {
  454. this.SetGolden(0);
  455. }
  456. else {
  457. this.SetGolden(this.Golden + Num);
  458. }
  459. // task.task50W();
  460. },
  461. GetDiamond: function () {
  462. return parseInt(this.Diamond);
  463. },
  464. SetDiamond: function (num) {
  465. let LastMoney = this.Diamond;
  466. this.Diamond = num;
  467. let CurrentMoney = num;
  468. this.ManageUI.getComponent('ManageUI').DiamondChangeCallBack(this.GetDiamond(), LastMoney, CurrentMoney);
  469. },
  470. PlusDiamond: function (num) {
  471. if (this.Diamond + num < 0) {
  472. this.SetDiamond(0);
  473. }
  474. else {
  475. this.SetDiamond(this.Diamond + num);
  476. }
  477. },
  478. /**
  479. * 游戏里面的cnt 和神农呗
  480. */
  481. GetCNT: function () {
  482. return parseFloat(this.CNT);
  483. },
  484. SetCNT: function (Num) {
  485. this.CNT = Num;
  486. this.ManageUI.getComponent('ManageUI').CNTChangeCallBack(this.CNT);
  487. },
  488. GetSNB: function () {
  489. return parseFloat(this.SNB);
  490. },
  491. SetSNB: function (Num) {
  492. this.SNB = Num;
  493. this.ManageUI.getComponent('ManageUI').SNBChangeCallBack(this.SNB);
  494. },
  495. GetWorkerLV: function () {
  496. return parseInt(this.WorkerLV);
  497. },
  498. SetWorkerLV: function (num) {
  499. this.WorkerLV = num;
  500. },
  501. PlusWorkerLV: function (num) {
  502. this.WorkerLV += num;
  503. },
  504. GetWorkerNum: function () {
  505. return parseInt(this.WorkerNum);
  506. },
  507. SetWorkerNum: function (num) {
  508. this.WorkerNum = num;
  509. },
  510. PlusWorkerNum: function (num) {
  511. this.WorkerNum += num;
  512. },
  513. GetLastTimeEveryDayRewardsDate: function () {
  514. return this.LastTimeEveryDayRewardsDate;
  515. },
  516. //获取转盘 时间
  517. GetLastTimeLuckDate: function () {
  518. return this.LastTimeLuckDate;
  519. },
  520. //设置转盘时间
  521. SetLastTimeLuckDate: function (DateString) {
  522. this.LastTimeLuckDate = DateString;
  523. },
  524. SetLastTimeEveryDayRewardsDate: function (DateString) {
  525. this.LastTimeEveryDayRewardsDate = DateString;
  526. },
  527. //工人信息数组
  528. GetWorkerCharacterInfoArray: function () {
  529. return this.CharacterInfoArray;
  530. },
  531. SetWorkerCharacterInfoArray: function (item) {
  532. this.CharacterInfoArray = item;
  533. },
  534. /*** */
  535. GetWorkerCapacity: function () {
  536. return parseInt((this.WorkerCapacity));
  537. },
  538. SetWorkerCapacity: function (num) {
  539. this.WorkerCapacity = num;
  540. },
  541. PlusWorkerCapacity: function (num) {
  542. this.WorkerCapacity += num;
  543. },
  544. GetTerritoryStateArray: function () {
  545. return this.TerritoryStateArray;
  546. },
  547. SetTerritoryStateArray: function (aTerritoryStateArray) {
  548. this.TerritoryStateArray = aTerritoryStateArray;
  549. },
  550. PlusTerritoryStateArray: function (Item) {
  551. this.TerritoryStateArray.push(Item);
  552. },
  553. GetBuildingStateArray: function () {
  554. return this.BuildingStateArray;
  555. },
  556. SetBuildingStateArray: function (aBuildingStateArray) {
  557. this.BuildingStateArray = aBuildingStateArray;
  558. },
  559. PlusBuildingStateArray: function (Item) {
  560. this.BuildingStateArray.push(Item);
  561. },
  562. GetBuildingLockStateArray: function () {
  563. return this.BuildingLockStateArray;
  564. },
  565. SetBuildingLockStateArray: function (aArray) {
  566. this.BuildingLockStateArray = aArray;
  567. },
  568. PlusBuildingLockStateArray: function (Item) {
  569. this.BuildingLockStateArray.push(Item);
  570. },
  571. GetBuildingNumArray: function () {
  572. return this.BuildingNumArray;
  573. },
  574. SetBuildingNumArray: function (aBuildingNumArray) {
  575. this.BuildingNumArray = aBuildingNumArray;
  576. },
  577. PlusBuildingNumArray: function (Item) {
  578. this.BuildingNumArray.push(Item);
  579. },
  580. //操作钻石数据
  581. GetDiamondNumArray: function () {
  582. return this.DiamondNumArray;
  583. },
  584. SetDiamondNumArray: function (aDiamondNumArray) {
  585. this.DiamondNumArray = aDiamondNumArray;
  586. },
  587. GetEveryDayRewardsArray: function () {
  588. return this.EveryDayRewardsArray;
  589. },
  590. SetEveryDayRewardsArray: function (aArray) {
  591. this.EveryDayRewardsArray = aArray;
  592. },
  593. PlusEveryDayRewardsArray: function (Item) {
  594. this.EveryDayRewardsArray.push(Item);
  595. },
  596. GetFoodTradeState: function () {
  597. return parseInt((this.FoodTradeState));
  598. },
  599. SetFoodTradeState: function (num) {
  600. this.FoodTradeState = num;
  601. },
  602. PlusFoodTradeState: function (num) {
  603. this.FoodTradeState += num;
  604. },
  605. GetWoodTradeState: function () {
  606. return parseInt((this.WoodTradeState));
  607. },
  608. SetWoodTradeState: function (num) {
  609. this.WoodTradeState = num;
  610. },
  611. PlusWoodTradeState: function (num) {
  612. this.WoodTradeState += num;
  613. },
  614. GetMineralTradeState: function () {
  615. return parseInt((this.MineralTradeState));
  616. },
  617. SetMineralTradeState: function (num) {
  618. this.MineralTradeState = num;
  619. },
  620. PlusMineralTradeState: function (num) {
  621. this.MineralTradeState += num;
  622. },
  623. GetLotteryTimes: function () {
  624. return parseInt((this.LotteryTimes));
  625. },
  626. SetLotteryTimes: function (num) {
  627. this.LotteryTimes = num;
  628. },
  629. PlusLotteryTimes: function (num) {
  630. this.LotteryTimes += num;
  631. },
  632. //初始化道路
  633. onSpawnHighway() {
  634. // 获取InitPoint层
  635. let InitPos = this._tiledMap.getLayer('InitPoint');
  636. InitPos.enabled = false;
  637. //创建公路数据
  638. if (this.readData && this.readData.allHighwayStylesAndIndex) {
  639. //保存到内存中
  640. this.GameData_highwayIndex = this.readData.highwayIndex;
  641. //先赋值道路的对象数组
  642. let _AllHighwayAIndex = GlobalD.game.AllHighwayStylesAndIndex = this.readData.allHighwayStylesAndIndex;
  643. //获取最后建造公路的层级
  644. this.HighwayLayer = this._tiledMap.getLayer('Highway');
  645. for (let i = 0; i < _AllHighwayAIndex.length; i++) {
  646. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  647. highwayTemp.parent = this.HighwayLayer.node;
  648. let tiledTile = highwayTemp.addComponent('TiledTile');
  649. let _tiledPos = GlobalD.TiledMap.analyticalIndexData(_AllHighwayAIndex[i].highwayInfoIndex);
  650. tiledTile.x = _tiledPos.x;
  651. tiledTile.y = _tiledPos.y;
  652. //地图设置可行走区域公路设置
  653. AStar.setMapSolid(_tiledPos.x, _tiledPos.y, 0);
  654. // _buildId ==0 是公路
  655. let _buildId = 0;
  656. let occupyTemp = cc.v2(_buildId, _AllHighwayAIndex[i].highwayInfoIndex);
  657. GlobalD.game.OccupyArray.push(occupyTemp);
  658. highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(_AllHighwayAIndex[i].highwayInfoType);
  659. }
  660. } else {
  661. //如果用户没有存储数据
  662. //根据InitPoint 的数据,创建初始化的地图数据 的初始化数据
  663. this.HighwayLayer = this._tiledMap.getLayer('Highway');
  664. for (var i = 0; i < 32; i++) {
  665. //去除中间两条路
  666. if (i == 16 || i == 17) continue;
  667. for (var j = 0; j < 32; j++) {
  668. let tilesPos = cc.v2(i, j);
  669. if (InitPos.getTileGIDAt(tilesPos)) {
  670. let index = GlobalD.TiledMap.getIndex(tilesPos);
  671. this.GameData_highwayIndex.push(index);
  672. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  673. highwayTemp.parent = this.HighwayLayer.node;
  674. let tiledTile = highwayTemp.addComponent('TiledTile');
  675. tiledTile.x = tilesPos.x;
  676. tiledTile.y = tilesPos.y;
  677. // cc.log('onSpawnHighway2');
  678. //地图设置可行走区域公路设置
  679. AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
  680. // _buildId ==0 是公路
  681. let _buildId = 0;
  682. let occupyTemp = cc.v2(_buildId, index);
  683. GlobalD.game.OccupyArray.push(occupyTemp);
  684. let tile = InitPos.getTiledTileAt(tilesPos.x, tilesPos.y, true);
  685. let _MoveType = reGameStates.HighwayType.moveX;
  686. // if (tile.gid == 15) {
  687. // _MoveType = reGameStates.HighwayType.moveX;
  688. // } else
  689. if (tile.gid == 16) {
  690. _MoveType = reGameStates.HighwayType.moveY;
  691. } else if (tile.gid == 11) {
  692. _MoveType = reGameStates.HighwayType.ZebraCrossingX;
  693. } else if (tile.gid == 12) {
  694. _MoveType = reGameStates.HighwayType.ZebraCrossingY;
  695. }
  696. // return;
  697. //更换公路样式
  698. GlobalD.game.onCreateDifferentRoadStyles({
  699. _buildId: _buildId,
  700. _highwayType: _MoveType,
  701. _roadIndex: index,
  702. _hightwayNode: highwayTemp
  703. });
  704. }
  705. }
  706. }
  707. }
  708. //外面的两条路
  709. let initRoad = this._tiledMap.getLayer('Road');
  710. initRoad.enabled = false;
  711. for (var i = 16; i < 18; i++) {
  712. for (var j = 0; j < 32; j++) {
  713. let tilesPos = cc.v2(i, j);
  714. // cc.log('road tilesPos',tilesPos)
  715. if (initRoad.getTileGIDAt(tilesPos)) {
  716. let index = GlobalD.TiledMap.getIndex(tilesPos);
  717. this.GameData_highwayIndex.push(index);
  718. let highwayTemp = cc.instantiate(this.HighWayPrefabs);
  719. highwayTemp.parent = this.HighwayLayer.node;
  720. let tiledTile = highwayTemp.addComponent('TiledTile');
  721. tiledTile.x = tilesPos.x;
  722. tiledTile.y = tilesPos.y;
  723. // cc.log('initRoad');
  724. //地图设置可行走区域公路设置
  725. AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
  726. let _buildId = 0;
  727. let occupyTemp = cc.v2(_buildId, index);
  728. GlobalD.game.OccupyArray.push(occupyTemp);
  729. //更换公路样式
  730. // if (j >= 25 && j <= 27 || j >= 19 && j <= 21 || j >= 9 && j <= 11)
  731. // highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.none);
  732. // else
  733. // highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.moveY);
  734. }
  735. }
  736. }
  737. },
  738. //清除所有的数据
  739. onClearAllData() {
  740. this.unschedule(this.AutoSaveData);
  741. //任务索引
  742. cc.sys.localStorage.removeItem('userdata');
  743. //跳回登录场景
  744. // cc.director.loadScene('Login');
  745. },
  746. //保存数据请求
  747. /**
  748. *
  749. * 现在转服务器存储,原本所有相关操作通过服务器计算。
  750. * 一、目前涉及到的是 SNT 和 SNB 两个货币相关,和买田地操作 (可以理解为租聘,三种类型)
  751. *
  752. * isNetwork:true,上传到网络
  753. *
  754. */
  755. pushData: function (isNetwork) {
  756. // cc.log(this.EveryDayRewardsArray);
  757. // console.log(this.readData.BFirstLoadGame);
  758. var datas = {
  759. version: this.GameVersion,
  760. // 转后台处理
  761. BFirstLoadGame: 1,//只要push数据,就证明已经开始第一次游戏了
  762. /**游戏不修改,默认值 start */
  763. shareGive: this.shareGive,
  764. //签到分享给钻石金币
  765. signInGive: this.signInGive,
  766. //每个月 给的 低保
  767. EveryGive: this.EveryGive,
  768. //公共分享
  769. publicGive: this.publicGive,
  770. /**游戏不修改,默认值 end */
  771. //时间
  772. GameYear: this.GameYear,
  773. GameMonth: this.GameMonth,
  774. GameDay: this.GameDay,
  775. //这里只是单纯的存储起来
  776. CNT: this.CNT,
  777. SNB: this.SNB,
  778. Golden: this.Golden,
  779. Diamond: this.Diamond,
  780. WorkerLV: this.WorkerLV,
  781. WorkerNum: this.WorkerNum,
  782. WorkerCapacity: this.WorkerCapacity,
  783. GameDate: this.GameDate,
  784. LastTimeEveryDayRewardsDate: this.LastTimeEveryDayRewardsDate,
  785. LastTimeLuckDate: this.LastTimeLuckDate,
  786. EveryDayRewardsArray: this.EveryDayRewardsArray,//.join('_'),
  787. TerritoryStateArray: this.TerritoryStateArray,//.join('_'),
  788. //面板状态
  789. BuildingStateArray: this.BuildingStateArray,//.join('_'),
  790. BuildingLockStateArray: this.BuildingLockStateArray,//.join('_'),
  791. /**
  792. * SNB和CNT相关,需要后台筛选 田地 和 种子。单独处理
  793. */
  794. BuildingNumArray: this.BuildingNumArray,//.join('_'),
  795. DiamondNumArray: this.DiamondNumArray,//.join('_'),
  796. FoodTradeState: this.FoodTradeState,
  797. WoodTradeState: this.WoodTradeState,
  798. MineralTradeState: this.MineralTradeState,
  799. LotteryTimes: this.LotteryTimes,
  800. /**
  801. * 这些数据不用服务器初始化
  802. */
  803. //工人工作信息
  804. characterInfoArray: this.CharacterInfoArray,
  805. //道路数据
  806. highwayIndex: this.GameData_highwayIndex,
  807. allHighwayStylesAndIndex: GlobalD.game.AllHighwayStylesAndIndex,
  808. //建筑物数据
  809. buildingsInfo: this.GameData_buildings,
  810. //任务
  811. TaskIconCountClick: task.TaskIconCountClick
  812. }
  813. if (isNetwork) {
  814. var data = [];
  815. // data["openid"] = userData.openId;
  816. // data["userdata"] = JSON.stringify(datas);
  817. data["playerData"] = JSON.stringify(datas);
  818. /** 推送信息 */
  819. utils.post(utils.api.playerPushInfo, data, (res, playerPushInfoTemp) => {
  820. // console.log('playerPushInfoTemp', playerPushInfoTemp);
  821. })
  822. } else {
  823. console.log("存储本地:" + isNetwork);
  824. //保存用户数据到本地
  825. cc.sys.localStorage.setItem('userdata', JSON.stringify(datas));
  826. }
  827. },
  828. getLandConfig() {
  829. // "data": [
  830. // {
  831. // "id": 1,
  832. // "configLandId": 1,
  833. // "userId": "4",
  834. // "name": "1",
  835. // "isLease": 1,
  836. // "leaseTime": "2022-01-10 21:25:17",
  837. // "leaseMultiple": null,
  838. // "isPlant": 1,
  839. // "plantStart": "2022-01-10 21:25:22",
  840. // "plantMature": 1,
  841. // "landDescribe": "1",
  842. // "createTime": "2022-01-10 21:25:30",
  843. // "updateTime": "2022-01-10 21:25:33"
  844. // }
  845. // ],
  846. utils.get(utils.api.landConfig, {}, (res, vaule) => {
  847. })
  848. },
  849. //获取用户全部租赁土地
  850. getUserLandList() {
  851. // "data": [
  852. // {
  853. // "id": 1,
  854. // "configLandId": 1,
  855. // "userId": "4",
  856. // "name": "1",
  857. // "isLease": 1,
  858. // "leaseTime": "2022-01-10 21:25:17",
  859. // "leaseMultiple": null,
  860. // "isPlant": 1,
  861. // "plantStart": "2022-01-10 21:25:22",
  862. // "plantMature": 1,
  863. // "landDescribe": "1",
  864. // "createTime": "2022-01-10 21:25:30",
  865. // "updateTime": "2022-01-10 21:25:33"
  866. // }
  867. // ],
  868. utils.get(utils.api.userLandList, {}, (res, vaule) => {
  869. })
  870. },
  871. //获取用户已租赁土地的状态
  872. getLandState() {
  873. // {
  874. // "id": 1,
  875. // "configLandId": 1,
  876. // "userId": "4",
  877. // "name": "1",
  878. // "isLease": 1,
  879. // "leaseTime": "2022-01-10 21:25:17",
  880. // "leaseMultiple": null,
  881. // "isPlant": 1,
  882. // "plantStart": "2022-01-10 21:25:22",
  883. // "plantMature": 1,
  884. // "landDescribe": "1",
  885. // "createTime": "2022-01-10 21:25:30",
  886. // "updateTime": "2022-01-10 21:25:33"
  887. // }
  888. utils.get(utils.api.landState, { landId: 1 }, (res, vaule) => {
  889. })
  890. },
  891. //获取商城种子
  892. getMallSeed() {
  893. // "data": [
  894. // {
  895. // "id": 1,
  896. // "mallType": "0",
  897. // "picture": null,
  898. // "name": "白菜种子",
  899. // "maturity": 100,
  900. // "planting": 100,
  901. // "harvestQuantity": 2500,
  902. // "harvestCount": 2500,
  903. // "harvestName": "大白菜",
  904. // "price": 99,
  905. // "amount": 0,
  906. // "withered": 200,
  907. // "createTime": "2022-01-10 16:45:18",
  908. // "updateTime": "2022-01-10 16:45:26"
  909. // },
  910. // {
  911. // "id": 2,
  912. // "mallType": "0",
  913. // "picture": null,
  914. // "name": "辣椒种子",
  915. // "maturity": 100,
  916. // "planting": 100,
  917. // "harvestQuantity": 2500,
  918. // "harvestCount": 2500,
  919. // "harvestName": "辣椒",
  920. // "price": 99,
  921. // "amount": 0,
  922. // "withered": 200,
  923. // "createTime": "2022-01-10 16:45:23",
  924. // "updateTime": "2022-01-10 16:45:28"
  925. // }
  926. // ],
  927. utils.get(utils.api.mallSeed, {}, (res, vaule) => {
  928. })
  929. },
  930. getWarehouseSeedAndFruit(){
  931. // "data": {
  932. // "seed": [
  933. // {
  934. // "id": 1,
  935. // "mallType": "0",
  936. // "picture": null,
  937. // "name": "白菜种子",
  938. // "maturity": 100,
  939. // "planting": 100,
  940. // "harvestQuantity": 2500,
  941. // "harvestCount": 2500,
  942. // "harvestName": "大白菜",
  943. // "price": 99,
  944. // "amount": 0,
  945. // "withered": 200,
  946. // "createTime": "2022-01-10 16:45:18",
  947. // "updateTime": "2022-01-10 16:45:26"
  948. // }
  949. // ],
  950. // "fruit": [
  951. // {
  952. // "id": 1,
  953. // "picture": null,
  954. // "name": "白菜",
  955. // "priceSnb": 99,
  956. // "priceCnt": 9.9,
  957. // "createTime": "2022-01-10 16:45:18",
  958. // "updateTime": "2022-01-10 16:45:26"
  959. // }
  960. // ]
  961. // },
  962. utils.get(utils.api.getSeedAndFruit, {}, (res, vaule) => {
  963. })
  964. }
  965. });