GameData.js 44 KB

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