// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import GamePlay from "../../GamePlay";
import PoolMgr, { NODEPOOLPREFABTYPE } from "../../mgr/PoolMgr";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ScoreEnergy extends cc.Component {

    public score: number = 0;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {

    }

    update() {
        //如果过关 则回收
        if (GamePlay.Inst.ifGetPass) {
            mk.console.log("[到达位置]过关啦11111", this.node.x, this.node.y);
            // LogUtil.log("过关啦?????????????????", this.node.x, this.node.y);
            PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.ScoreEnergy, this.node);

            let nextScore = GamePlay.Inst.curGetScore + this.score;
            GamePlay.Inst.curGetScore = nextScore;
        }
    }

    init(x: number, y: number, score: number) {

        this.node.getComponent(cc.ParticleSystem).resetSystem();

        this.node.x = x;
        this.node.y = y;

        let pos_x = GamePlay.Inst.node_progressUI.x;
        let pos_y = GamePlay.Inst.node_progressUI.y + GamePlay.Inst.node_redPacketIcon.y;

        GamePlay.Inst.finalGetScore += score;

        cc.tween(this.node)
            .to(1, { x: pos_x, y: pos_y }, { easing: "smooth" })
            .call(() => {
                // mk.console.log("[到达位置]过关啦222222", this.node.x, this.node.y);
                PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.ScoreEnergy, this.node);

                //如果结算 过关 分数就不加
                if (!GamePlay.Inst.ifGetPass) {
                    let nextScore = GamePlay.Inst.curGetScore + score;
                    GamePlay.Inst.curGetScore = nextScore;
                }

                //Game.Inst.initScore();
            })
            .start();
    }
    // update (dt) {}
}
