import { _decorator, Component, Node, tween } from "cc";
import { PropBtn } from "../Components/PropBtn";
import { MainGame } from "../MainGame";
import gameStore from "../../../store/gameStore";
import { showToast } from "db://assets/Module/UIFast";
import { _asyncThrottle } from "../../../Utils/Utils";
const { ccclass, property } = _decorator;

@ccclass('GrowPropBtn')
export class GrowPropBtn extends PropBtn {

    start() {
        super.start();
        this.propNum = gameStore.startInfo.spCardList.filter(item => item.spId == 'sp_add_length')[0]?.num || 0;
    }


    doUse = _asyncThrottle(async () => {
        if (!MainGame.ins.player.isLife) {
            return
        }
        if (this.propNum <= 0) {
            showToast('请在首页【游戏道具】中购买')
            return
        }

        if (gameStore.gameInfo.useSpCount >= gameStore.startInfo.eachUseLimitTimes) {
            showToast("本局使用道具达到上限")
            return
        }

        if (await gameStore.useProps('sp_add_length')) {
            gameStore.gameInfo.useSpCount += 1
            super.doUse();
            this.propNum -= 1;
            MainGame.ins.player.useGrow()
            this.startCd();
        }
    })

}


