| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import { _decorator, Node } from 'cc';
- import { aa, UIController, UIElement } from 'db://assets/scripts/aa';
- import { UI_Dialog } from '../UI_Dialog';
- import { rootMgr } from '../../../scene/RootMgr';
- import { Player } from '../../../data/player/Player';
- import { Notify } from '../../../scene/GameConfing';
- import { ItemKey, ItemService } from '../../../data/Item/ItemService';
- const { ccclass, property } = _decorator;
- @UIController({ bundleName: 'dialog', path: 'lifeOver/lifeOver' })
- export class UI_NeedLife extends UI_Dialog {
- @UIElement(Node)
- adBtn: Node
- @UIElement(Node)
- useCoinBtn: Node
- start(): void {
- this.adBtn.on(Node.EventType.TOUCH_END, this.useAd, this)
- this.useCoinBtn.on(Node.EventType.TOUCH_END, this.useCoin, this)
- }
- async useAd() {
- // debugger
- let player = rootMgr.dataControl.getCompent(Player)
- if (player.getLifeControl().isMax()) {
- Notify("无需领取")
- return
- }
- let boolean = await aa.sdk.playRewardAd('体力耗尽')
- if (boolean) {
- // 体力回满
- let player = rootMgr.dataControl.getCompent(Player)
- player.life = player.getLifeControl().max
- Notify("领取成功")
- this.onClose()
- }
- }
- useCoin() {
- let player = rootMgr.dataControl.getCompent(Player)
- if (player.getLifeControl().isMax()) {
- Notify("无需领取")
- return
- }
- let item = rootMgr.dataControl.getCompent(ItemService)
- let bool = item.consume(ItemKey.coin, 900)
- if (bool) {
- player.life = player.getLifeControl().max
- Notify("领取成功")
- this.onClose()
- } else {
- Notify("金币不足")
- }
- }
- }
|