import BaseEvent from "../../base/BaseEvent";
import WOneByone from "../../map1/WOneByone";

const { ccclass, property } = cc._decorator;
/**
 * 1_4取火
 */
@ccclass
export default class FFire1_4 extends BaseEvent {

    @property({
        displayName: '动画',
        type: sp.Skeleton
    })
    spine: sp.Skeleton = null;

    @property(cc.Prefab)
    mMapDialog: cc.Prefab = null;

    @property({
        displayName: '靠近的提示',
        type: cc.SpriteFrame
    })
    icon: cc.SpriteFrame = null;

    @property({
        displayName: '提示图标',
        type: cc.SpriteFrame
    })
    mTipsIcon: cc.SpriteFrame = null;

    @property({
        displayName: '对话内容',
        type: [cc.String]
    })
    text: Array<string> = [];

    @property({
        displayName: "火把列表",
        type: [cc.Node]
    })
    fireList: cc.Node[] = [];

    @property({
        displayName: '需要的物品id'
    })
    public goodId = 2004;

    @property({
        displayName: '存储ID'
    })
    public saveId: string = "";

    count: number = 0;
    state: boolean = false;

    start() {

    }

    public onBegin(tag: number) {
        if (!this.ff.mFFheader.getTmpCount(this.goodId)) {
            this.showOpt(this.icon, () => {
                let my = this.ff.mainSprite.node;
                this.showDialog(my, this.text, () => {
                    this.closeOpt()
                });
            })
            return
        }
        if (tag == 1) {
            this.showOpt(this.mTipsIcon, () => {
                if (this.state) return
                this.playAnima();
            })
        }
    }

    public onEnd(tag: number) {
        if (tag == 1) {
            this.closeOpt()
        }
    }

    playAnima() {
        this.state = true;
        this.spineAction(this.spine, "zuan", () => {
            this.state = false;
            this.spineAction(this.spine, "idle", () => { });
            this.count++;
            this.fireList[this.count - 1].active = true;
            this.getFire();
        })
    }

    public getFire() {
        let head = this.ff.mFFheader;
        if (this.count == this.fireList.length) {
            head.removeTmpGood(this.goodId, 1);
            this.node.active = false;
            this.closeOpt();
        }
    }

}
