import { AudioMgr } from "../../../../main/ViewManage";
import ViewObject from "../../../../main/ViewObject";
import FFCalAttr from "../../../data/FFCalAttr";
import FSprite, { SpriteActionType } from "../../../fight/object/FSprite";

import Equip from "../../equip/Equip";
const { ccclass, property } = cc._decorator;

@ccclass
export default class StageFail extends ViewObject {


    @property(cc.Node)
    mSite: cc.Node = null;

    public callback: () => void;


    onLoad() {
        let ff: FSprite
        let sManage = this.main.sManage;
        let player = this.main.player
        let pet = sManage.getRoleById(player.role.leader);
        let petAttr = player.getPet(player.role.leader + '')
        this.mSite.destroyAllChildren();
        let ffAttr = FFCalAttr.getAttr(this.main, petAttr);
        cc.resources.load('prefab/role/' + pet.act, cc.Prefab, (err, prefab: cc.Prefab) => {
            if (err) {
                cc.error(err);
            } else {
                let node = cc.instantiate(prefab);
                node.parent = this.mSite;
                let spriteNode = node.getChildByName('juese01');
                let spineNode0 = spriteNode.getChildByName('spineRight');
                let spine = spineNode0.getComponent(sp.Skeleton);
                let mWeapon1: sp.spine.Bone = spine.findBone('control');
                if (mWeapon1) {
                    mWeapon1.data.rotation = 0;
                    mWeapon1.rotation = 0;
                }
                let smoke = spriteNode.children[0]
                smoke.active = false
                // spine.setSkin(ffAttr.skin)
                // Equip.chaneWeapon(spine, ffAttr.weapon)

                spine.setAnimation(0, SpriteActionType.dead, false);

            }
        });


    }

    public setCallback(callback: () => void) {
        this.callback = callback;
    }

    public onclickOK() {
        this.main.topNode.active = true;
        if (!cc.sys.localStorage.getItem("showRevenge" + this.main.player.role.id)) {
            cc.sys.localStorage.setItem("showRevenge" + this.main.player.role.id, 1);
        }
        this.main.playMusicByPath(AudioMgr.homeMusic);
        this.exitDistroy();
        if (this.callback) {
            this.callback();
        }
    }
}
