const GameStatesStatic = require('GameStates');
cc.Class({
    extends: cc.Component,

    properties: {
    },
    onLoad: function () {
        this.arrSkin = [
            "Sayaren",
            "Baozhatou",
            "Mensaonan",
            "Yuanban"
        ];

        this.myRandomc = [];
    },
    //返回两个 随机数
    setRandom: function () {
        var temp1 = this.arrSkin[Math.floor(Math.random() * this.arrSkin.length)];
        var temp2 = this.arrSkin[Math.floor(Math.random() * this.arrSkin.length)];
        if (temp1 != temp2) {
            return [temp1, temp2];
        } else {
            this.setRandom();
        }
    },
    setSkinss: function (arr) {
        var Rivel = cc.find("Rivel");
        var Hero = cc.find("Hero");
        console.log("调用了 有没有", arr);
        if (arr.length == 0 || arr == null) {
            var tag = true;
            while (tag) {
                this.myRandom = this.setRandom();
                if (this.myRandom != null) {
                    tag = false;
                    this.myRandomc = this.myRandom;
                    GameStatesStatic.myRandomc = this.myRandomc;
                }
            }
            console.log("调用了 设置了", GameStatesStatic.myRandomc);
            Rivel.getChildByName("Player").getComponent("Charactor").setSkins(this.myRandom[0]);
            Hero.getChildByName("Player").getComponent("Charactor").setSkins(this.myRandom[1]);
            var Hero = cc.find("Hero");
            var NetworkSocket = Hero.getComponent('NetworkSocket');
            var data = { FunctionName: 'myRandomSetSkins', arr: GameStatesStatic.myRandomc };
            NetworkSocket.sendSyncData(JSON.stringify(data));
        }
    },

    setRandomSkinss: function () {
        var Rivel = cc.find("Rivel");
        var Hero = cc.find("Hero");
        var tag = true;
        var RivelPlayer =  Rivel.getChildByName("Player");
        // RivelPlayer.active = true;
        var HeroPlayer =  Hero.getChildByName("Player");
        // HeroPlayer.active = true;
        while (tag) {
            this.myRandom = this.setRandom();
            if (this.myRandom != null) {
                tag = false;
                this.myRandomc = this.myRandom;
            }
        }
        RivelPlayer.getComponent("Charactor").setSkins(this.myRandom[0]);
        HeroPlayer.getComponent("Charactor").setSkins(this.myRandom[1]);
        var NetworkSocket = Hero.getComponent('NetworkSocket');
        var data = { FunctionName: 'myRandomSetSkins', arr: this.myRandomc };
        NetworkSocket.sendSyncData(JSON.stringify(data));

    }
});
