

import Vector3 = Laya.Vector3;
export  class GameTool {

    

    public static getM_Vector(v1: Laya.Vector3, v2: Laya.Vector3): Laya.Vector3 {
        let temp = new Laya.Vector3();
        Laya.Vector3.add(v1, v2, temp);
        return new Laya.Vector3(temp.x * 0.5, temp.y * 0.5, temp.z * 0.5);
    }

    public static SpliteString(s: string, sp?): Array<any> {
        var _sp = sp ? sp : ";"
        let s_s = s.split(_sp)
        let result = [];
        for (let i = 0; i < s_s.length; i++) {
            result.push(s_s[i]);
        }
        return result;
    }

    public static random_1to1(): number {
        var iszheng = Math.random() > 0.5 ? -1 : 1;
        return Math.random() * iszheng;
    }

    public static get64Encode(str): string {
        var c1, c2, c3;
        var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        var i = 0, len = str.length, string = '';
        while (i < len) {
            c1 = str.charCodeAt(i++) & 0xff;
            if (i == len) {
                string += base64EncodeChars.charAt(c1 >> 2);
                string += base64EncodeChars.charAt((c1 & 0x3) << 4);
                string += "==";
                break;
            }
            c2 = str.charCodeAt(i++);
            if (i == len) {
                string += base64EncodeChars.charAt(c1 >> 2);
                string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
                string += base64EncodeChars.charAt((c2 & 0xF) << 2);
                string += "=";
                break;
            }
            c3 = str.charCodeAt(i++);
            string += base64EncodeChars.charAt(c1 >> 2);
            string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            string += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
            string += base64EncodeChars.charAt(c3 & 0x3F)
        }
        return string;
    }

    //返回一个随机整数[min,max]
    public static randomInt(min: any, max: any): number {
        if (max < min) return parseInt(min);
        return parseInt(Math.random() * (max - min + 1) + min);
    }

    /**
     * 随机函数( 不取整 )
     */
    public static randRangefloat(min: number, max: number): number  {
        var value:number = Math.random() * (max - min + 1) + min;
        if(value>max){
            value = max;
        }
        return value;
    }
}