UIObtainView.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. import AESUtil from "../../../AESUtil"
  13. import ATSDK from "../../../AnyThinkAds/ATJSSDK";
  14. import ATRewardedVideoSDK from "../../../AnyThinkAds/ATRewardedVideoJSSDK";
  15. import AAJS2 from "../../../ATAndroidJS2";
  16. import GlobalManager from '../../../GlobalManager';
  17. const {ccclass, menu, property} = cc._decorator;
  18. @ccclass
  19. @menu("UI/Interface/UIObtainView")
  20. export default class UIObtainView extends UIBase {
  21. ui: auto_obtainView = null;
  22. protected static prefabUrl = "Interface/obtainView";
  23. protected static className = "UIObtainView";
  24. @property(cc.Node)
  25. contentNode: cc.Node = null;
  26. @property(cc.Node)
  27. optionNode: cc.Node = null;
  28. @property(cc.Node)
  29. btn_doubleNode: cc.Node = null;
  30. @property(cc.Node)
  31. btnCollectNode: cc.Node = null;
  32. @property(cc.Prefab)
  33. itemPrefab: cc.Prefab = null;
  34. //是模块的子节点
  35. private isChild = false;
  36. onUILoad() {
  37. // this.ui = this.node.addComponent(auto_obtainView);
  38. this.initAdForPage();
  39. }
  40. initAdForPage() {
  41. if (cc.sys.os === cc.sys.OS_ANDROID) {
  42. let deviceId = AAJS2.getDeviceUserId();
  43. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  44. var setting = {};
  45. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  46. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  47. }
  48. }
  49. private isSign = false;
  50. private param: { ids: [], nums: [], isHero?, modelIds?, type? } = null;
  51. onShow() {
  52. }
  53. /**
  54. *
  55. * @param params ids item的id nums 数量 isHero 是否全部是英雄 modelIds英雄id
  56. */
  57. onInit(params: []) {
  58. // @ts-ignore
  59. let param: { ids: [], nums: [], isHero?, modelIds?, type? } = params[0];
  60. this.param = param;
  61. let isHero = false;
  62. let ids = param.ids;
  63. let nums = param.nums;
  64. let modelIds = [];
  65. if (nums.length != ids.length) {
  66. console.error("长度不一致!");
  67. return;
  68. }
  69. if (param.hasOwnProperty('isHero')) {
  70. isHero = param.isHero;
  71. }
  72. if (param.hasOwnProperty('modelIds')) {
  73. modelIds = param.modelIds;
  74. }
  75. if (param.type == 'sign') {
  76. console.log("zh: 签到过来的.");
  77. this.refreshSign();
  78. }
  79. ids.forEach((value, index) => {
  80. const node = cc.instantiate(this.itemPrefab);
  81. const item = node.getComponent(UIAirdropItem);
  82. this.contentNode.addChild(node);
  83. if (isHero) {
  84. const modelInfo = modelDtlManager.getDataByID(value);
  85. item.refreshRole({
  86. itemname: modelInfo.desc,
  87. nums: 1,
  88. roleRes: modelInfo.modelname
  89. });
  90. } else {
  91. const data = itemDtManager.getDataByID(value);
  92. let temp = {itemname: data.itemname, nums: nums[index], resPath1: data.resPath1}
  93. item.refresh(temp);
  94. }
  95. })
  96. if (modelIds.length == 0) {
  97. return;
  98. }
  99. modelIds.forEach((value, index) => {
  100. const node = cc.instantiate(this.itemPrefab);
  101. const item = node.getComponent(UIAirdropItem);
  102. this.contentNode.addChild(node);
  103. const modelInfo = modelDtlManager.getDataByID(value);
  104. item.refreshRole({
  105. itemname: modelInfo.desc,
  106. nums: 1,
  107. roleRes: modelInfo.modelname
  108. });
  109. })
  110. }
  111. refreshSign() {
  112. this.isSign = true;
  113. this.optionNode.active = true;
  114. this.btn_doubleNode.active = true;
  115. this.btnCollectNode.active = false;
  116. }
  117. showByWelfare(infos: any[]) {
  118. this.isChild = true;
  119. for (let viewInfo of infos) {
  120. if (!viewInfo) {
  121. continue;
  122. }
  123. const node = cc.instantiate(this.itemPrefab);
  124. const itemComponent = node.getComponent(UIAirdropItem);
  125. const data = itemDtManager.getDataByID(viewInfo.itemID);
  126. //英雄
  127. if (viewInfo.type == 5) {
  128. const modelInfo = modelDtlManager.getDataByID(viewInfo.modelID);
  129. itemComponent.refreshRole({
  130. itemname: viewInfo.name,
  131. nums: viewInfo.nums,
  132. roleRes: modelInfo.modelname
  133. });
  134. } else {
  135. itemComponent.refresh({itemname: data.itemname, nums: viewInfo.nums, resPath1: data.resPath1});
  136. }
  137. this.contentNode.addChild(node)
  138. }
  139. }
  140. onHide() {
  141. }
  142. onStart() {
  143. }
  144. clickOption() {
  145. }
  146. clickDouble() {
  147. console.log("zh:clickDouble");
  148. if (!this.isSign) {
  149. return;
  150. }
  151. this.doDouble();
  152. }
  153. clickClose() {
  154. if (this.isChild) {
  155. this.node.destroy();
  156. return;
  157. }
  158. this.onClose();
  159. }
  160. onClose() {
  161. EventManager.emit(EVENT_TYPE.closeObtain)
  162. UIHelp.CloseUI(UIObtainView);
  163. }
  164. private doDouble() {
  165. let self = this
  166. if(2>1){//zh:diy
  167. if (cc.sys.os === cc.sys.OS_ANDROID) {
  168. GlobalManager.getInstance().registerMethod('doubleRewardForAdEventQd', this.doubleRewardForAdEventQd.bind(this));
  169. let adKey = "zh_ad_type"
  170. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  171. cc.sys.localStorage.setItem(adKey, 'doubleRewardForAdEventQd');
  172. console.log('zh:AD ready for idx2')
  173. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  174. } else {
  175. console.log('zh:AD not ready for idx2')
  176. self.doubleRewardForAdEventQd();
  177. }
  178. }else{
  179. self.doubleRewardForAdEventQd();
  180. }
  181. return;
  182. }
  183. const params = {
  184. payType: zjSdk?.TYPE.VIDEO,
  185. success() {
  186. self.doubleReward();
  187. },
  188. fail() {
  189. // self.doSearch();
  190. }
  191. };
  192. zjSdk?.doPay(params);
  193. this.clickClose();
  194. }
  195. private doubleReward() {
  196. const itemArr = this.param.ids;
  197. const numArr = this.param.nums;
  198. const modelIds = this.param.modelIds;
  199. itemArr.forEach((value, index) => {
  200. const data = itemDtManager.getDataByID(value);
  201. let damage: number = 0;
  202. // (食物1,药品2,子弹3,近战武器4, 远程武器5)
  203. switch (data.type) {
  204. case 1:
  205. gameData.curPowerNum += numArr[index];
  206. break;
  207. case 2:
  208. break;
  209. case 3:
  210. gameData.curBulletNum += numArr[index];
  211. break;
  212. case 4:
  213. for (let i = 0; i < numArr[index]; i++) {
  214. damage = itemDtManager.getDataByID(data.id).value;
  215. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  216. }
  217. break;
  218. case 5:
  219. for (let i = 0; i < numArr[index]; i++) {
  220. damage = itemDtManager.getDataByID(data.id).value;
  221. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  222. }
  223. break;
  224. }
  225. })
  226. if (modelIds.length !== 0 && modelIds[0] != 52) {
  227. const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids;
  228. fixedRoleIds.push(modelIds[0])
  229. AccountModel.singleInstance.fixed_role_ids = fixedRoleIds;
  230. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, modelIds[0]);
  231. }
  232. }
  233. //zh: diy ad 签到
  234. public doubleRewardForAdEventQd() {
  235. console.log("zh:doubleRewardForAdEventQd 被触发" );
  236. const itemArr = this.param.ids;
  237. const numArr = this.param.nums;
  238. const modelIds = this.param.modelIds;
  239. itemArr.forEach((value, index) => {
  240. const data = itemDtManager.getDataByID(value);
  241. let damage: number = 0;
  242. // (食物1,药品2,子弹3,近战武器4, 远程武器5)
  243. switch (data.type) {
  244. case 1:
  245. gameData.curPowerNum += numArr[index];
  246. break;
  247. case 2:
  248. break;
  249. case 3:
  250. gameData.curBulletNum += numArr[index];
  251. break;
  252. case 4:
  253. for (let i = 0; i < numArr[index]; i++) {
  254. damage = itemDtManager.getDataByID(data.id).value;
  255. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  256. }
  257. break;
  258. case 5:
  259. for (let i = 0; i < numArr[index]; i++) {
  260. damage = itemDtManager.getDataByID(data.id).value;
  261. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  262. }
  263. break;
  264. }
  265. })
  266. if (modelIds.length !== 0 && modelIds[0] != 52) {
  267. const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids;
  268. fixedRoleIds.push(modelIds[0])
  269. AccountModel.singleInstance.fixed_role_ids = fixedRoleIds;
  270. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, modelIds[0]);
  271. }
  272. console.log('zh:开始关闭签到界面1')
  273. this.clickClose();
  274. }
  275. }