LeaseAnimalInfo.js 26 KB

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