GameData.js 45 KB

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