123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- import { _decorator, Component, Node } from "cc";
- import BaseUI from "../../scripts/base/BaseUI";
- import { IPayListener, PayItems, PayType } from "../common/PayItems";
- import { Tips } from "../../scripts/mgr/Tips";
- import ShopM, { ShopDto } from "../../scripts/api/ShopM";
- import ConfigM, { ConfigShopItem } from "../../scripts/api/ConfigM";
- import { Event } from "cc";
- import UserM from "../../scripts/api/UserM";
- import PushMsgM from "../../scripts/mgr/PushMsgM";
- import { RewardLayer } from "../layer/RewardLayer";
- import ItemsM from "../../scripts/mgr/ItemsM";
- import { Sprite } from "cc";
- import PogAd from "../../scripts/mgr/PogAd";
- const { ccclass, property } = _decorator;
- @ccclass("PogBoosterItem")
- export class PogBoosterItem extends BaseUI implements IPayListener {
- public static readonly TYPE_GAME_PASS = 1;
- public static readonly TYPE_POG_BOOSTER = 2;
- public static readonly TYPE_ITEM_BOX = 3;
- public static readonly TYPE_POG_BOX = 4;
- public type: number;
- onPay(type: PayType, price: number) {
- switch (type) {
- case PayType.Gem:
- this.buyUseGem();
- break;
- }
- }
- async buyUseGem() {
- let shopItemId = this._configItem.id;
- let num = this._configItem.num;
- let gem = this._configItem.diamondPrice;
- // UserM.ins.subtractGoods(GoodsId.GEM, gem);
- let result = await ShopM.ins.buyUseGem(shopItemId, num, gem);
- if (result) {
- result.changeList.forEach(async (item) => {
- if (item.count > 0 && ConfigM.ins.GoodIsBox(item.id)) {
- let newResult = await ShopM.ins.openBox(item.id, item.count);
- if (newResult) {
- ItemsM.ins.itemChange(newResult.changeList, newResult.goodList);
- }
- } else {
- ItemsM.ins.itemChange(result.changeList, result.goodList);
- }
- });
- }
- }
- private _data: ShopDto;
- private _configItem: ConfigShopItem;
- private _payItems: PayItems;
- init(type: number, item: ShopDto) {
- this.type = type;
- this._data = item;
- this._configItem = ConfigM.ins.getConfigShopIteByShopId(type, item.id);
-
- this.setText("lbl_times", "x" + this._configItem.num);
- this.setText("lbl_title", ""+ConfigM.ins.getGoodName(this._configItem.goodId));
- this.setIcon();
- this._payItems = this.getComponentInChildren(PayItems);
- let btnAD = this.FindNode("btn_ad");
- this._payItems.node.active = true;
- let showAd = this._configItem.adPrice > 0;
- this._payItems.node.active = !showAd;
- btnAD.active = showAd;
- if (showAd) {
- //
- if (this._data.dailyUserAdSell >= this._configItem.dailyUserAdLimit) {
- this.FindAs("btn_ad", Sprite).grayscale = true;
- }
- } else {
- this._payItems.init(
- [
- {
- type: PayType.Gem,
- price: this._configItem.diamondPrice,
- },
- ],
- this
- );
- }
- }
-
- setIcon() {
- let icons = this.FindNode("icons");
- icons.children.forEach((child) => {
- child.active = false;
- });
- switch (this.type) {
- case PogBoosterItem.TYPE_GAME_PASS:
- break;
- case PogBoosterItem.TYPE_POG_BOOSTER:
- icons.getChildByName("icon_crit").active = true;
- break;
- case PogBoosterItem.TYPE_ITEM_BOX:
- icons.getChildByName("icon_item_box").active = true;
- break;
- case PogBoosterItem.TYPE_POG_BOX:
- icons.getChildByName("icon_pog_box").active = true;
- }
- }
- getName(): string {
-
- switch (this.type) {
- case PogBoosterItem.TYPE_GAME_PASS:
- return "Game Pass";
- case PogBoosterItem.TYPE_POG_BOOSTER:
- return "POG Crit Tickets";
- case PogBoosterItem.TYPE_ITEM_BOX:
- return "Item Box";
- case PogBoosterItem.TYPE_POG_BOX:
- return "Pog Box";
- }
- return "Unknown";
- }
- private _requestingAD: boolean = false;
- private async buyUseAD() {
- let self = this;
- // Tips.show("AD Coming soon");
- if (this._data.dailyUserAdSell >= this._configItem.dailyUserAdLimit) {
- this.FindAs("btn_ad", Sprite).grayscale = true;
- Tips.show("AD Limit");
- return;
- }
- if (this._requestingAD) {
- return;
- }
- self._requestingAD = true;
- setTimeout(() => {
- self._requestingAD = false;
- }, 3000);
-
- let showAdResult = await PogAd.ins.showAd();
- if (!showAdResult) {
- return;
- }
- Tips.show("AD Success");
- let result = await ShopM.ins.buyUseAD(
- this._configItem.id,
- this._configItem.num,
- this._configItem.adPrice
- );
- if (result) {
- ItemsM.ins.itemChange(result.changeList, result.goodList);
- this._data.dailyUserAdSell += 1;
- this.init(this.type, this._data);
- }
- }
- protected onBtnClick(name: string, event: Event, customEventData: any): void {
- if (name == "btn_ad") {
- this.buyUseAD();
- }
- }
- }
|