PlantItem.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /** 可生产物品item */
  2. import { BitmapFontC } from "../../../game/component/BitmapFontC";
  3. import { GameProp, ProductType } from "../../../game/data/GameData";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class PlantItem extends cc.Component {
  7. @property({ type: cc.Node, tooltip: "布局" }) mainNode: cc.Node = null;
  8. @property({ type: cc.Node, tooltip: "未解锁" }) lockNode: cc.Node = null;
  9. @property({ type: cc.Sprite, tooltip: "作物图标" }) plantIcon: cc.Sprite = null;
  10. @property({ type: cc.Sprite, tooltip: "名字图标" }) nameIcon: cc.Sprite = null;
  11. @property({ type: BitmapFontC, tooltip: "获得数量文本" }) awardLabel: BitmapFontC = null;
  12. @property({ type: BitmapFontC, tooltip: "成熟时间文本" }) timeLabel: BitmapFontC = null;
  13. @property({ type: cc.Label, tooltip: "未开条件" }) labUnlock: cc.Label = null;
  14. @property({ type: cc.Label, tooltip: '进度文本' }) lbl_progress: cc.Label = null;
  15. @property({ type: cc.Node, tooltip: '订单' }) node_dingdan: cc.Node = null;
  16. @property({ type: cc.Node }) node_plant: cc.Node = null;
  17. @property({ type: cc.Node }) node_product: cc.Node = null;
  18. private data = null;
  19. /**
  20. * list_data
  21. * @param list_data 数据列表
  22. */
  23. public async setItemData(list_data) {
  24. await this.initItem(list_data);
  25. }
  26. update() {
  27. if (gData.plantData.init_itemIndex == this.data.picture) {
  28. this.initItem(this.data);
  29. gData.plantData.init_itemIndex = -1;
  30. }
  31. if (gData.plantData.init_lock == this.data.picture) {
  32. this.initItem(this.data);
  33. gData.plantData.init_lock = -1;
  34. }
  35. }
  36. /**
  37. * 数据分发
  38. * @param list_data 数据列表
  39. */
  40. private async initItem(list_data) {
  41. this.data = list_data;
  42. let plantPath = '';
  43. let namePath = '';
  44. if (this.data.tab == ProductType.nzw) {
  45. plantPath = 'game/coregame/texture/plant_icons/plantIcon_';
  46. namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_';
  47. this.node_plant.active = true;
  48. this.node_product.active = false;
  49. }
  50. else {
  51. plantPath = 'game/coregame/texture/factory_icons/factory_';
  52. namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  53. this.node_plant.active = false;
  54. this.node_product.active = true;
  55. }
  56. this.plantIcon.spriteFrame = await mk.loader.load(plantPath + list_data.picture, cc.SpriteFrame);
  57. this.nameIcon.spriteFrame = await mk.loader.load(namePath + list_data.picture, cc.SpriteFrame);
  58. this.awardLabel.string = (list_data.menuRedBagCoin / 100).toString();
  59. this.timeLabel.string = list_data.time;
  60. let unlock = false;
  61. let times = 0;
  62. //根据上个商品种植次数
  63. if (list_data.unlock == 1) {
  64. unlock = gData.gameData.getProductUnlockById(this.data.tab, this.data.picture);
  65. if (!unlock) {
  66. times = gData.gameData.getProductMakeTimesById(list_data.picture - 1);
  67. if (times >= list_data.value) {
  68. unlock = true;
  69. }
  70. }
  71. }
  72. //根据农场等级
  73. else if (list_data.unlock == 2) {
  74. if (gData.gameData.playerProp.orderData && gData.gameData.playerProp.orderData.overTimes >= list_data.value) {
  75. unlock = true;
  76. }
  77. }
  78. if (unlock) {
  79. this.checkOrder();
  80. }
  81. else {
  82. this.node_dingdan.active = false;
  83. }
  84. this.mainNode.active = unlock;
  85. this.lockNode.active = !unlock;
  86. if (!unlock) {
  87. let des = this.getDesByType();
  88. let plantName = gData.gameData.getProductMap(this.data.picture - 1).name;
  89. if (list_data.picture - 1 == gData.gameData.getMaxProductExtra(this.data.tab)) {
  90. this.labUnlock.string = `${des}${this.data.value}次\n${plantName}`;
  91. this.lbl_progress.string = `${times}/${this.data.value}`;
  92. this.labUnlock.node.active = true;
  93. }
  94. else {
  95. this.labUnlock.node.active = false;
  96. }
  97. }
  98. }
  99. checkOrder() {
  100. let data = gData.gameData.playerProp.orderData;
  101. let isDingdan = false;
  102. if (data) {
  103. let len = data.orderTaskList.length;
  104. let orderPlantTimes = gData.gameData.getProp(GameProp.orderPlantTimes);
  105. if (!orderPlantTimes) {
  106. orderPlantTimes = {};
  107. }
  108. gData.gameData.setProp(GameProp.orderPlantTimes, orderPlantTimes);
  109. if (orderPlantTimes[this.data.id] == undefined) {
  110. orderPlantTimes[this.data.id] = 0;
  111. }
  112. for (var i = 0; i < len; i++) {
  113. // if (data.orderTaskList[i].Id == this.data.id && orderPlantTimes[data.orderTaskList[i].Id] < data.orderTaskList[i].taskCount) {
  114. // isDingdan = true;
  115. // break;
  116. // }
  117. if (data.orderTaskList[i].Id == this.data.id) {
  118. console.log("===[订单id",data.orderTaskList[i].Id,this.data.id)
  119. console.log("===[订单id 种植次数",orderPlantTimes[data.orderTaskList[i].Id],data.orderTaskList[i].taskCount)
  120. if (orderPlantTimes[data.orderTaskList[i].Id] < data.orderTaskList[i].taskCount) {
  121. isDingdan = true;
  122. break;
  123. }
  124. }
  125. }
  126. }
  127. this.node_dingdan.active = isDingdan;
  128. }
  129. showTips() {
  130. mk.tip.pop("生产次数+5");
  131. }
  132. async clickMake() {
  133. mk.audio.playEffect('button');
  134. mk.guide.next();
  135. // if (gData.gameData.leftTimes <= 0) {
  136. // gData.gameData.popTipCallBack = this.showTips;
  137. // mk.ui.openPanel('module/speedUpUI/productReward');
  138. // return;
  139. // }
  140. if (gData.gameData.isProducting) {
  141. //mk.tip.pop('点击太快了');
  142. return;
  143. }
  144. let flyRed;
  145. if (this.data.tab == ProductType.nzw) {
  146. flyRed = await gData.farmSystem.plant(this.data.picture, this.nameIcon.node);
  147. // gData.gameData.nextMake = null;
  148. // gData.gameData.setNextProduct(false);
  149. // if (gData.gameData.playerProp.gradeLevel < 2) {
  150. // mk.tip.pop('生产次数+1');
  151. // }
  152. }
  153. else {
  154. flyRed = await gData.factorySystem.make(this.data.picture, this.nameIcon.node);
  155. }
  156. console.log("===[种植订单 flyRed",flyRed);
  157. if (flyRed) {
  158. let orderPlantTimes = gData.gameData.getProp(GameProp.orderPlantTimes);
  159. if (orderPlantTimes[this.data.id] == undefined) {
  160. orderPlantTimes[this.data.id] = 1;
  161. }
  162. else {
  163. orderPlantTimes[this.data.id]++;
  164. }
  165. gData.gameData.setProp(GameProp.orderPlantTimes, orderPlantTimes);
  166. this.checkOrder();
  167. mk.data.sendDataEvent('Plant', this.data.name);
  168. let plantTimes = gData.gameData.getProp(GameProp.plantTimes);
  169. if (plantTimes == undefined) {
  170. plantTimes = 0;
  171. }
  172. plantTimes++;
  173. gData.gameData.setProp(GameProp.plantTimes, plantTimes);
  174. if (gData.gameData.showRichBankIconLimit == plantTimes && gData.gameData.funOpenData[13] == "1") {
  175. mk.event.emit("showRichBankIcon");
  176. }
  177. //飞红包开关
  178. if (gData.gameData.funOpenData[4] == "0") {
  179. return;
  180. }
  181. gData.plantData.init_ani = true;
  182. let pos = this.nameIcon.node.parent.convertToWorldSpaceAR(this.nameIcon.node.getPosition());
  183. gData.gameData.gameStyle.dpFlyRedAni(pos);
  184. }
  185. }
  186. getDesByType() {
  187. let des = ''
  188. switch (this.data.tab) {
  189. case '农作物':
  190. des = '种植';
  191. break;
  192. case '动物':
  193. des = '养殖';
  194. break;
  195. case '爆米花厂':
  196. case '糕点铺':
  197. case '制糖厂':
  198. case '炼乳厂':
  199. case '功夫面馆':
  200. case '快餐店':
  201. des = '制作';
  202. break;
  203. }
  204. return des;
  205. }
  206. }