UIObtainView.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import auto_obtainView from "../../../ui/uidata/Interface/auto_obtainView";
  2. import UIBase from "../../../framework/ui/UIBase";
  3. import UIHelp from "../../../framework/ui/UIHelp";
  4. import UIAirdropItem from "./UIAirdropItem";
  5. import itemDtManager from "../../../dataManager/itemDtManager";
  6. import modelDtlManager from "../../../dataManager/modelDtlManager";
  7. import gameData from "../../../gameLogic/utrl/gameData";
  8. import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
  9. import {EVENT_TYPE} from "../../../gameLogic/utrl/gameEnum";
  10. import AccountModel from "../../../data/Account/AccountModel";
  11. import EventManager from "../../../framework/event/EventManager";
  12. const {ccclass, menu, property} = cc._decorator;
  13. @ccclass
  14. @menu("UI/Interface/UIObtainView")
  15. export default class UIObtainView extends UIBase {
  16. ui: auto_obtainView = null;
  17. protected static prefabUrl = "Interface/obtainView";
  18. protected static className = "UIObtainView";
  19. @property(cc.Node)
  20. contentNode: cc.Node = null;
  21. @property(cc.Node)
  22. optionNode: cc.Node = null;
  23. @property(cc.Node)
  24. btn_doubleNode: cc.Node = null;
  25. @property(cc.Node)
  26. btnCollectNode: cc.Node = null;
  27. @property(cc.Prefab)
  28. itemPrefab: cc.Prefab = null;
  29. //是模块的子节点
  30. private isChild = false;
  31. onUILoad() {
  32. // this.ui = this.node.addComponent(auto_obtainView);
  33. }
  34. private isSign = false;
  35. private param: { ids: [], nums: [], isHero?, modelIds?, type? } = null;
  36. onShow() {
  37. }
  38. /**
  39. *
  40. * @param params ids item的id nums 数量 isHero 是否全部是英雄 modelIds英雄id
  41. */
  42. onInit(params: []) {
  43. // @ts-ignore
  44. let param: { ids: [], nums: [], isHero?, modelIds?, type? } = params[0];
  45. this.param = param;
  46. let isHero = false;
  47. let ids = param.ids;
  48. let nums = param.nums;
  49. let modelIds = [];
  50. if (nums.length != ids.length) {
  51. console.error("长度不一致!");
  52. return;
  53. }
  54. if (param.hasOwnProperty('isHero')) {
  55. isHero = param.isHero;
  56. }
  57. if (param.hasOwnProperty('modelIds')) {
  58. modelIds = param.modelIds;
  59. }
  60. if (param.type == 'sign') {
  61. this.refreshSign();
  62. }
  63. ids.forEach((value, index) => {
  64. const node = cc.instantiate(this.itemPrefab);
  65. const item = node.getComponent(UIAirdropItem);
  66. this.contentNode.addChild(node);
  67. if (isHero) {
  68. const modelInfo = modelDtlManager.getDataByID(value);
  69. item.refreshRole({
  70. itemname: modelInfo.desc,
  71. nums: 1,
  72. roleRes: modelInfo.modelname
  73. });
  74. } else {
  75. const data = itemDtManager.getDataByID(value);
  76. let temp = {itemname: data.itemname, nums: nums[index], resPath1: data.resPath1}
  77. item.refresh(temp);
  78. }
  79. })
  80. if (modelIds.length == 0) {
  81. return;
  82. }
  83. modelIds.forEach((value, index) => {
  84. const node = cc.instantiate(this.itemPrefab);
  85. const item = node.getComponent(UIAirdropItem);
  86. this.contentNode.addChild(node);
  87. const modelInfo = modelDtlManager.getDataByID(value);
  88. item.refreshRole({
  89. itemname: modelInfo.desc,
  90. nums: 1,
  91. roleRes: modelInfo.modelname
  92. });
  93. })
  94. }
  95. refreshSign() {
  96. this.isSign = true;
  97. this.optionNode.active = true;
  98. this.btn_doubleNode.active = true;
  99. this.btnCollectNode.active = false;
  100. }
  101. showByWelfare(infos: any[]) {
  102. this.isChild = true;
  103. for (let viewInfo of infos) {
  104. if (!viewInfo) {
  105. continue;
  106. }
  107. const node = cc.instantiate(this.itemPrefab);
  108. const itemComponent = node.getComponent(UIAirdropItem);
  109. const data = itemDtManager.getDataByID(viewInfo.itemID);
  110. //英雄
  111. if (viewInfo.type == 5) {
  112. const modelInfo = modelDtlManager.getDataByID(viewInfo.modelID);
  113. itemComponent.refreshRole({
  114. itemname: viewInfo.name,
  115. nums: viewInfo.nums,
  116. roleRes: modelInfo.modelname
  117. });
  118. } else {
  119. itemComponent.refresh({itemname: data.itemname, nums: viewInfo.nums, resPath1: data.resPath1});
  120. }
  121. this.contentNode.addChild(node)
  122. }
  123. }
  124. onHide() {
  125. }
  126. onStart() {
  127. }
  128. clickOption() {
  129. }
  130. clickDouble() {
  131. if (!this.isSign) {
  132. return;
  133. }
  134. this.doDouble();
  135. }
  136. clickClose() {
  137. if (this.isChild) {
  138. this.node.destroy();
  139. return;
  140. }
  141. this.onClose();
  142. }
  143. onClose() {
  144. EventManager.emit(EVENT_TYPE.closeObtain)
  145. UIHelp.CloseUI(UIObtainView);
  146. }
  147. private doDouble() {
  148. let self = this
  149. const params = {
  150. payType: zjSdk?.TYPE.VIDEO,
  151. success() {
  152. self.doubleReward();
  153. },
  154. fail() {
  155. // self.doSearch();
  156. }
  157. };
  158. zjSdk?.doPay(params);
  159. this.clickClose();
  160. }
  161. private doubleReward() {
  162. const itemArr = this.param.ids;
  163. const numArr = this.param.nums;
  164. const modelIds = this.param.modelIds;
  165. itemArr.forEach((value, index) => {
  166. const data = itemDtManager.getDataByID(value);
  167. let damage: number = 0;
  168. // (食物1,药品2,子弹3,近战武器4, 远程武器5)
  169. switch (data.type) {
  170. case 1:
  171. gameData.curPowerNum += numArr[index];
  172. break;
  173. case 2:
  174. break;
  175. case 3:
  176. gameData.curBulletNum += numArr[index];
  177. break;
  178. case 4:
  179. for (let i = 0; i < numArr[index]; i++) {
  180. damage = itemDtManager.getDataByID(data.id).value;
  181. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  182. }
  183. break;
  184. case 5:
  185. for (let i = 0; i < numArr[index]; i++) {
  186. damage = itemDtManager.getDataByID(data.id).value;
  187. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  188. }
  189. break;
  190. }
  191. })
  192. if (modelIds.length !== 0 && modelIds[0] != 52) {
  193. const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids;
  194. fixedRoleIds.push(modelIds[0])
  195. AccountModel.singleInstance.fixed_role_ids = fixedRoleIds;
  196. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, modelIds[0]);
  197. }
  198. }
  199. }