LeaseAnimalInfo.js 26 KB

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