LeaseFarmlandInfo.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. import date from "../Unit/date.js"
  2. import gameToast from "../Network/gameToast"
  3. /**
  4. * 操作租赁土地的相关业务
  5. */
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. leasePanelPrefabs: {
  10. default: null,
  11. type: cc.Prefab,
  12. serializable: true,
  13. },
  14. //主信息面板
  15. infoBox: cc.Node,
  16. //时间计算对象
  17. showTimeOut: null,
  18. /**
  19. * 显示天数部分
  20. */
  21. upSliderNode: {
  22. default: null,
  23. type: cc.Node,
  24. serializable: true,
  25. },
  26. multipleLabel: {
  27. default: null,
  28. type: cc.Label,
  29. serializable: true,
  30. toolTip: "显示的倍数"
  31. },
  32. leaseDate: {
  33. default: null,
  34. type: cc.Label,
  35. serializable: true,
  36. toolTip: "剩余天数/总天数"
  37. },
  38. /**
  39. * 成熟期部分
  40. */
  41. midSliderNode: {
  42. default: null,
  43. type: cc.Node,
  44. serializable: true,
  45. },
  46. midDate: {
  47. default: null,
  48. type: cc.Label,
  49. serializable: true,
  50. toolTip: "剩余天数/总天数"
  51. },
  52. midSliderProgressNode: {
  53. default: null,
  54. type: cc.Node,
  55. serializable: true,
  56. toolTip: "进度条"
  57. },
  58. notLeased: {
  59. default: null,
  60. type: cc.Node,
  61. serializable: true,
  62. },
  63. //初始化时候对应的土地的id
  64. initConfigLandId: -1,
  65. // configLandId: 1
  66. // createTime: "2022-01-10 21:25:30"
  67. // id: 1
  68. // isLease: 1
  69. // isPlant: 0
  70. // landDescribe: "土地1xxx"
  71. // leaseMultiple: 1
  72. // leaseTime: "2022-01-10 21:25:17"
  73. // name: "土地1"
  74. // plantMature: 0
  75. // plantStart: "2022-01-10 21:25:22"
  76. // updateTime: "2022-01-10 21:25:33"
  77. // userId: "4"
  78. // 已经租赁的土地信息
  79. leaseLandInfo: {
  80. default: null,
  81. visible: false
  82. },
  83. // createTime: "2022-01-10 21:25:30"
  84. // id: 4
  85. // initMultiple: 1
  86. // isInit: 1
  87. // isLease: 0
  88. // isPlant: 0
  89. // landDescribe: "一倍土地"
  90. // leaseMultiple: 1
  91. // leaseTime: "2022-01-10 21:25:17"
  92. // name: "土地4"
  93. // plantMature: 0
  94. // plantStart: "2022-01-10 21:25:22"
  95. // posX: 19
  96. // posY: 10
  97. // sizeX: 2
  98. // sizeY: 2
  99. // updateTime: "2022-01-10 21:25:33"
  100. // 未初始化时候的土地信息
  101. configLandInfo: {
  102. default: null,
  103. visible: false
  104. },
  105. showLandInfo: {
  106. default: null,
  107. type: cc.Node,
  108. serializable: true,
  109. toolTip: "显示土地信息"
  110. },
  111. landInfoPrefabs: {
  112. default: null,
  113. type: cc.Prefab,
  114. serializable: true,
  115. },
  116. // 已经种植的作物信息
  117. plantInfo: {
  118. default: null,
  119. visible: false
  120. },
  121. showPlantInfo: {
  122. default: null,
  123. type: cc.Node,
  124. serializable: true,
  125. toolTip: "显示种植信息"
  126. },
  127. plantInfoPrefabs: {
  128. default: null,
  129. type: cc.Prefab,
  130. serializable: true,
  131. },
  132. //收获阶段
  133. harvestNode: {
  134. default: null,
  135. type: cc.Node,
  136. serializable: true,
  137. },
  138. stealHarvestNode: {
  139. default: null,
  140. type: cc.Node,
  141. serializable: true,
  142. },
  143. isHarvest: false,
  144. /**
  145. * 成熟时候显示的图片
  146. */
  147. harvestSprite: {
  148. default: null,
  149. type: cc.SpriteFrame,
  150. },
  151. _workingBuilding: null,
  152. //时间计算对象
  153. timeInterval: null,
  154. //是否显示showHarvest
  155. isShowHarvest: false,
  156. isShowIndex: 0,
  157. //检查土地是否到期
  158. isCheckLandState: false,
  159. _buildingView: null,
  160. //是否是自己的土地,记录一下
  161. bSelfLand: true,
  162. //
  163. giveOutLightNode: {
  164. default: null,
  165. type: cc.Node,
  166. serializable: true,
  167. },
  168. envBg: {
  169. default: null,
  170. type: cc.Node,
  171. serializable: true,
  172. },
  173. envBgSpriteFrameList: {
  174. default: [],
  175. type: cc.SpriteFrame,
  176. },
  177. },
  178. // LIFE-CYCLE CALLBACKS:
  179. onLoad() {
  180. this._workingBuilding = this.node.getComponent("WorkingBuilding");
  181. this._buildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView").getComponent("BuildingView");
  182. },
  183. start() {
  184. this.harvestNode.on(cc.Node.EventType.TOUCH_START, () => {
  185. if (GlobalD.GameData.isOnAddFruit) return;
  186. console.log("点击收获");
  187. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "收获中..", 5);
  188. let data = { landId: this.leaseLandInfo.configLandId };
  189. //果实收入仓库,重置土地种植信息
  190. GlobalD.GameData.onAddFruit(data, (value) => {
  191. // console.log(value);
  192. if (0 === value.code) {
  193. //收成后处理相关状态
  194. this.harvestNode.active = false;
  195. this.midSliderNode.active = false
  196. this._workingBuilding.onSetGrow(0, null);
  197. //更新仓库列表
  198. this._buildingView.onUpdateList();
  199. // "收获成功!"
  200. if (value.data.lossAmount > 0) {
  201. console.log("loss amount:" + value.data.lossAmount);
  202. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "收获成功!损失了" + value.data.lossAmount + "个果实", 2);
  203. } else {
  204. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "收获成功!", 2);
  205. }
  206. this.isShowHarvest = false;
  207. this.isShowIndex = 0;
  208. if (this.timeInterval) {
  209. clearInterval(this.timeInterval);
  210. this.timeInterval = null;
  211. }
  212. } else if (706 === value.code) {
  213. //土地到期,没有更新刷新的处理刷新
  214. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
  215. //重置锁定状态显示
  216. this.onLockLand();
  217. } else {
  218. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
  219. }
  220. });
  221. })
  222. this.stealHarvestNode.on(cc.Node.EventType.TOUCH_START, () => {
  223. // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请点击偷菜按钮收取!", 1);
  224. // return;
  225. //改成单个收取果实
  226. if (GlobalD.GameData.isOnAddFruit) return;
  227. console.log("点击收获");
  228. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "偷取果实中..", 5);
  229. let data = { otherUserId: GlobalD.OtherUserInfo.userId, otherLandId: this.leaseLandInfo.configLandId };
  230. //偷取果实收入仓库,重置土地种植信息
  231. GlobalD.GameData.onStealFruit(data, (value) => {
  232. console.log(value);
  233. if (0 === value.code) {
  234. //收成后处理相关状态
  235. this.onHideStealHarvest();
  236. let _manageUI = cc.find("GameNode/ManageUI");
  237. _manageUI.getComponent("ManageUI").onInitStealViewSuccessPrefab(value.data);
  238. //更新仓库列表
  239. this._buildingView.onUpdateList();
  240. //更新snb
  241. GlobalD.GameData.SetSNB(value.data.snb + value.data.snbPart);
  242. } else {
  243. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
  244. }
  245. });
  246. })
  247. //如果是村长或者镇长,换地皮
  248. this.onSwitchEnvBgFromLevel(GlobalD.Dapp.UserInfo.agent_level);
  249. },
  250. onSwitchEnvBgFromLevel(agent_level) {
  251. this.envBg.getComponent(cc.Sprite).spriteFrame = this.envBgSpriteFrameList[agent_level];
  252. },
  253. onSpawnLeasePanel() {
  254. let leasePanel = cc.instantiate(this.leasePanelPrefabs);
  255. let parent = cc.find('Canvas/UICamera/DAPPContainer');
  256. leasePanel.parent = parent;
  257. leasePanel.setPosition(0, 0);
  258. // leasePanel.zIndex = 999;
  259. //把操作对象传入
  260. let leasePanelScript = leasePanel.getComponent("LeaseInfo");
  261. leasePanelScript.leaseFarmlandInfoNode = this;
  262. /**
  263. * 初始化两个操作。一个是续约,续约的话,不给操作,只有续约按钮可点,相当于原来配置再购买一次
  264. *
  265. * this.leaseLandInfo 如果购买了土地,这个参数不为空
  266. */
  267. if (this.leaseLandInfo) {
  268. //续约时候拦截输入,固定倍数
  269. leasePanelScript.blockInput.active = true;
  270. //传入当前计算倍数
  271. leasePanelScript.onInitLeaseInfo(this.leaseLandInfo.leaseMultiple);
  272. } else if (0 === this.configLandInfo.initMultiple) {
  273. // 固定土地开启,限制输入,设置默认值是1
  274. leasePanelScript.blockInput.active = true;
  275. leasePanelScript.onInitLeaseInfo(1);
  276. } else {
  277. //多倍土地,可以自己输入
  278. let limitValue = this.configLandInfo.initMultiple;
  279. if (GlobalD.GameSetting && GlobalD.GameSetting.maxLeaseMulti) {
  280. limitValue = GlobalD.GameSetting.maxLeaseMulti;
  281. console.log("LeaseFarmland:如果配置 maxLeaseMulti:", limitValue);
  282. }
  283. leasePanelScript.onInitLeaseInfo(limitValue);
  284. }
  285. },
  286. /**
  287. * 解锁土地操作
  288. */
  289. onUnlockLand() {
  290. //直接删除此节点
  291. if (this.notLeased) {
  292. this.notLeased.active = false;
  293. // this.notLeased.destroy();
  294. // this.notLeased = null;
  295. }
  296. },
  297. /**
  298. * 获取锁定状态
  299. */
  300. onGetUnlockLandState() {
  301. return this.notLeased.active;
  302. },
  303. /**
  304. * 重新锁定
  305. */
  306. onLockLand() {
  307. //显示按钮
  308. if (this.notLeased) {
  309. this.notLeased.active = true;
  310. }
  311. //清除当前租赁数据
  312. this.leaseLandInfo = null;
  313. this.isShowHarvest = false;
  314. this.isShowIndex = 0;
  315. if (this.timeInterval) {
  316. clearInterval(this.timeInterval);
  317. this.timeInterval = null;
  318. }
  319. //去除提示框
  320. this.upSliderNode.parent.active = false;
  321. this.midSliderNode.active = false;
  322. this.harvestNode.active = false;
  323. this.stealHarvestNode.active = false;
  324. //重置土地图片
  325. this._workingBuilding.onSetGrow(0, null);
  326. this.onSetInfoBoxActive(false);
  327. },
  328. //设置config的土地信息
  329. setConfigLandInfo(value) {
  330. this.configLandInfo = value;
  331. },
  332. /**
  333. * 设置其他用户租赁的土地信息
  334. * 比如去其他用户家里偷取物品,目前统一在这处理
  335. */
  336. setLeaseLandInfo(value, bSelf) {
  337. console.log("土地信息是,bSelf:", bSelf);
  338. if (!value) {
  339. console.log("已租赁土地状态为空:", value);
  340. return;
  341. }
  342. this.onSetInfoBoxActive(false);
  343. //设置意思显示相关
  344. this.isShowHarvest = false;
  345. this.isShowIndex = 0;
  346. //重新设置租赁检测状态
  347. this.isCheckLandState = false;
  348. this.leaseLandInfo = value;
  349. //先解绑一下信息
  350. this.showLandInfo.off(cc.Node.EventType.TOUCH_START, this._showLandInfo, this);
  351. this.showPlantInfo.off(cc.Node.EventType.TOUCH_START, this._showPlantInfo, this);
  352. //每个作物直接实时计算时间
  353. if (this.timeInterval) {
  354. clearInterval(this.timeInterval);
  355. this.timeInterval = null;
  356. }
  357. //删除解锁图标
  358. this.onUnlockLand();
  359. this.bSelfLand = bSelf;
  360. //更新一下土地信息
  361. this.updateLandState(bSelf);
  362. },
  363. updateLandState(bSelf) {
  364. //如果是种植状态并且有返回种植信息
  365. if (1 === this.leaseLandInfo.isPlant && this.leaseLandInfo.seedInfo) {
  366. //种植信息
  367. //如果土地是租赁转态并且同时种植了 ,这里处理土地状态,显示种植信息
  368. let _spriteFrame;
  369. switch (this.leaseLandInfo.seedInfo.picture) {
  370. case "Cabbage":
  371. _spriteFrame = this._buildingView.fruitSpriteFrame[0];
  372. break;
  373. case "Potato":
  374. _spriteFrame = this._buildingView.fruitSpriteFrame[1];
  375. break;
  376. case "Carrot":
  377. _spriteFrame = this._buildingView.fruitSpriteFrame[2];
  378. break;
  379. case "Broccoli":
  380. _spriteFrame = this._buildingView.fruitSpriteFrame[3];
  381. break;
  382. case "Tomato":
  383. _spriteFrame = this._buildingView.fruitSpriteFrame[4];
  384. break;
  385. case "Squash":
  386. _spriteFrame = this._buildingView.fruitSpriteFrame[5];
  387. break;
  388. case "Eggplant":
  389. _spriteFrame = this._buildingView.fruitSpriteFrame[6];
  390. break;
  391. case "Pepper":
  392. _spriteFrame = this._buildingView.fruitSpriteFrame[7];
  393. break;
  394. case "Lentil":
  395. _spriteFrame = this._buildingView.fruitSpriteFrame[8];
  396. break;
  397. default:
  398. break;
  399. }
  400. //设置一个收获时候的图片
  401. this.harvestSprite = _spriteFrame;
  402. this.midSliderNode.active = bSelf;
  403. // 进度条按小时计算
  404. let _maturityAllHour = this.leaseLandInfo.seedInfo.maturity * 24
  405. let _remainAllHour = this.leaseLandInfo.plantDaysRemaining * 24 + this.leaseLandInfo.plantHoursRemaining;
  406. //计算剩余时间显示(进度条)
  407. let _midProccess = _maturityAllHour === 0 ? 0 : _remainAllHour / _maturityAllHour;
  408. this.midSliderProgressNode.getComponent(cc.ProgressBar).progress = _midProccess;
  409. /**
  410. * 绑定生成显示信息面板,种植信息
  411. */
  412. this.showPlantInfo.on(cc.Node.EventType.TOUCH_START, this._showPlantInfo, this);
  413. }
  414. //显示剩余天数
  415. this.upSliderNode.parent.active = bSelf;
  416. this.multipleLabel.string = this.leaseLandInfo.leaseMultiple;
  417. // 进去条按天算
  418. let sliderProgressScript = this.upSliderNode.getComponent("slider_progress");
  419. let _proccess = this.leaseLandInfo.leaseDays === 0 ? 0 : this.leaseLandInfo.leaseDaysRemaining / this.leaseLandInfo.leaseDays;
  420. sliderProgressScript.onSetProcgress(_proccess);
  421. /**
  422. * 绑定生成显示信息面板,现在土地信息
  423. */
  424. this.showLandInfo.on(cc.Node.EventType.TOUCH_START, this._showLandInfo, this);
  425. let lastUpdateTime = Date.now();
  426. let elapsedTime = 0;
  427. let updateFrequency = 1; //ms
  428. this.timeInterval = setInterval(() => {
  429. let currentTime = Date.now();
  430. let deltaTime = currentTime - lastUpdateTime;
  431. elapsedTime += deltaTime;
  432. if (elapsedTime >= updateFrequency) {
  433. elapsedTime -= updateFrequency;
  434. let _leaseDaysMill = this.leaseLandInfo.leaseDaysMill - elapsedTime;
  435. let _plantDaysMill = this.leaseLandInfo.plantDaysMill - elapsedTime;
  436. lastUpdateTime = currentTime;
  437. // 更新计时显示
  438. let [_lDay, _lHour, _lMinutes, _lSeconds] = date.remainFromMillisecond(_leaseDaysMill);
  439. //todo 处理了 this.leaseLandInfo.leaseDaysRemaining
  440. if (0 !== _lDay) {
  441. this.leaseDate.string = "剩" + _lDay + "天/" + this.leaseLandInfo.leaseDays + "天";
  442. } else if (0 !== _lHour) {
  443. this.leaseDate.string = "剩" + _lHour + "时/" + this.leaseLandInfo.leaseDays + "天";
  444. } else if (0 !== _lMinutes) {
  445. this.leaseDate.string = "剩" + _lMinutes + "分/" + this.leaseLandInfo.leaseDays + "天";
  446. } else {
  447. this.leaseDate.string = "剩" + _lSeconds + "秒/" + this.leaseLandInfo.leaseDays + "天";
  448. }
  449. //todo 如果租赁时间到了,重新锁定
  450. //重置锁定状态显示
  451. if (!this.isCheckLandState) {
  452. if (_leaseDaysMill <= 0) {
  453. this.isCheckLandState = true;
  454. //检查一次土地
  455. this.onCheckLand(this.leaseLandInfo.configLandId);
  456. }
  457. }
  458. if (1 === this.leaseLandInfo.isPlant && this.leaseLandInfo.seedInfo) {
  459. //获得服务器种植日期毫秒
  460. let [_pDay, _pHour, _pMinutes, _pSeconds] = date.remainFromMillisecond(_plantDaysMill);
  461. //todo 处理了 this.leaseLandInfo.plantDaysRemaining
  462. if (0 !== _pDay) {
  463. //否则显示天和小时
  464. this.midDate.string = "剩" + _pDay + "天" + _pHour + "时";
  465. } else if (0 !== _pHour) {
  466. this.midDate.string = "剩" + _pHour + "时" + _pMinutes + "分";
  467. } else {
  468. this.midDate.string = "剩" + _pMinutes + "分" + _pSeconds + "秒";
  469. }
  470. if (!this.isShowHarvest) {
  471. if (_plantDaysMill <= 0) {
  472. this.isShowHarvest = true;
  473. this.isShowIndex = 3;
  474. //如果传回的毫秒是小于零,说明成熟了
  475. //成熟阶段
  476. this._workingBuilding.onSetGrow(3, this.harvestSprite);
  477. // console.log("土地:", _userLeaseLand[j].configLandId, "已经成熟,可以操作收取果实了!!");
  478. //如果是自己的,显示收成
  479. if (bSelf) {
  480. this.onShowHarvest();
  481. } else {
  482. //存在可偷的状态才设置这个图标
  483. if (1 === this.leaseLandInfo.canSteal) {
  484. this.onShowStealHarvest();
  485. }
  486. }
  487. } else {
  488. let _maturityHour = this.leaseLandInfo.seedInfo.maturity * 24
  489. let _ratio = (_pDay * 24 + _pHour) / _maturityHour;
  490. if (_ratio > 0.5 && 1 !== this.isShowIndex) {
  491. this.isShowIndex = 1;
  492. this._workingBuilding.onSetGrow(1, this.harvestSprite);
  493. console.log("_ratio:" + _ratio + "=" + this.leaseLandInfo.configLandId + ",状态:" + this.isShowIndex);
  494. } else if (_ratio <= 0.5 && _ratio >= 0 && 2 !== this.isShowIndex) {
  495. this.isShowIndex = 2;
  496. this._workingBuilding.onSetGrow(2, this.harvestSprite);
  497. console.log("_ratio:" + _ratio + "=" + this.leaseLandInfo.configLandId + ",状态:" + this.isShowIndex);
  498. }
  499. }
  500. }
  501. }
  502. }
  503. });
  504. },
  505. _showLandInfo() {
  506. let leasePanel = cc.instantiate(this.landInfoPrefabs);
  507. let parent = cc.find('Canvas/UICamera/DAPPContainer');
  508. leasePanel.parent = parent;
  509. leasePanel.setPosition(0, 0);
  510. let leasePanelScript = leasePanel.getComponent("LandInfo");
  511. let _date = date.datedifference(this.leaseLandInfo.createTime, this.leaseLandInfo.leaseTime);
  512. let { configLandId, rentalExpenses, createTime, leaseTime, leaseMultiple, landDescribe } = this.leaseLandInfo;
  513. leasePanelScript.setInfo(configLandId, rentalExpenses, _date + "天", createTime, leaseTime, leaseMultiple + "倍", landDescribe);
  514. },
  515. _showPlantInfo() {
  516. let leasePanel = cc.instantiate(this.plantInfoPrefabs);
  517. let parent = cc.find('Canvas/UICamera/DAPPContainer');
  518. leasePanel.parent = parent;
  519. leasePanel.setPosition(0, 0);
  520. // leasePanel.zIndex = 999;
  521. let leasePanelScript = leasePanel.getComponent("PlantInfo");
  522. let _harvest = 0;
  523. if (this.leaseLandInfo.leaseDate === 1) {
  524. _harvest = this.leaseLandInfo.seedInfo.harvest1;
  525. } else if (this.leaseLandInfo.leaseDate === 2) {
  526. _harvest = this.leaseLandInfo.seedInfo.harvest2;
  527. } else if (this.leaseLandInfo.leaseDate === 3) {
  528. _harvest = this.leaseLandInfo.seedInfo.harvest3;
  529. }
  530. //price,maturity,plantStart,harvestQuantity,describe
  531. let { name, priceCnt, maturity, seedDescribe } = this.leaseLandInfo.seedInfo;
  532. leasePanelScript.setInfo(name, priceCnt, maturity + "天", this.leaseLandInfo.plantStart, _harvest, seedDescribe);
  533. },
  534. //更新收获的状态
  535. updateHarvest() {
  536. //todo 后续看看如何刷新,现在走的是开始刷新一次
  537. // let _workingBuilding = housingTemp_farmland.getComponent("WorkingBuilding");
  538. // //获得服务器种植日期毫秒
  539. // let [_day, _hour, _minutes, _seconds] = date.remainFromMillisecond(_leaseLandInfo.plantDaysMill);
  540. // let _maturityHour = _leaseLandInfo.seedInfo.maturity * 24
  541. // let _ratio = _hour / _maturityHour;
  542. // // console.log("生成的:" + _ratio);
  543. // if (_ratio > 0.5) {
  544. // _workingBuilding.onSetGrow(1, _spriteFrame);
  545. // } else if (_ratio >= 0) {
  546. // _workingBuilding.onSetGrow(2, _spriteFrame);
  547. // }else if (_leaseLandInfo.plantDaysMill <= 0) {
  548. // //如果传回的毫秒是小于零,说明成熟了
  549. // //成熟阶段
  550. // _workingBuilding.onSetGrow(3, _spriteFrame);
  551. // //todo,如果时间小的,走收获,收获成果实
  552. // // console.log("土地:", _userLeaseLand[j].configLandId, "已经成熟,可以操作收取果实了!!");
  553. // //todo 土地可收获状态
  554. // leaseFarmlandInfoScript.onShowHarvest();
  555. // }
  556. },
  557. //检查土地状态
  558. onCheckLand(configLandId) {
  559. GlobalD.GameData.getLandState({
  560. landId: configLandId,
  561. callback: (value) => {
  562. console.log("检查土地数据:" + JSON.stringify(value.msg));
  563. //这里只判断土地是否过期
  564. if (706 === value.code) {
  565. //土地到期,没有更新刷新的处理刷新
  566. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), configLandId + "号," + value.msg, 2);
  567. //重置锁定状态显示
  568. this.onLockLand();
  569. }
  570. }
  571. });
  572. },
  573. /**
  574. * 场景有多个收获预制时候,用GameData限制
  575. * 点击之后,重置土地信息, 并且收入进仓库果实列表中去
  576. * 需要防多次触发
  577. */
  578. onShowHarvest() {
  579. this.harvestNode.active = true;
  580. },
  581. /**
  582. * 场景有多个收获预制时候,用GameData限制
  583. * 点击之后,偷取果实
  584. * 需要防多次触发
  585. */
  586. onShowStealHarvest() {
  587. this.stealHarvestNode.active = true;
  588. },
  589. onHideStealHarvest() {
  590. this.stealHarvestNode.active = false;
  591. },
  592. /**
  593. * 设置总体信息面板显示
  594. * @param {boolean} bActive
  595. */
  596. onSetInfoBoxActive(bActive) {
  597. this.giveOutLightNode.active = bActive;
  598. if (!this.bSelfLand) {
  599. // console.log("其他用户的不用显示面板");
  600. return;
  601. }
  602. if (this.leaseLandInfo) {
  603. this.infoBox.active = bActive;
  604. if (bActive) {
  605. if (this.showTimeOut) {
  606. clearTimeout(this.showTimeOut);
  607. this.showTimeOut = null;
  608. }
  609. //自动隐藏面板
  610. this.showTimeOut = setTimeout(() => {
  611. this.infoBox.active = false;
  612. }, 5000)
  613. }
  614. }
  615. },
  616. onDestroy() {
  617. if (this.timeInterval) {
  618. clearInterval(this.timeInterval);
  619. this.timeInterval = null;
  620. }
  621. if (this.showTimeOut) {
  622. clearTimeout(this.showTimeOut);
  623. this.showTimeOut = null;
  624. }
  625. }
  626. });