GameData.js 43 KB

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