GameData.js 39 KB

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