import { ObjectValueType } from "./BattleEnum";

export namespace BattleUtil {
//战斗辅助工具类
    export const FrameRate = 30; //帧率
    export const FrameTime = 1 / FrameRate; //帧间隔
    export const PI = 3.1415926; //圆周率
    export const TurnMax = 10*60*FrameRate; //回合数
    //特殊的类型id
    export const TypeID_Init = -1; //初始化id
    export const TypeID_Player = -2; //玩家操作生成的id
    export const PosID_Init = -1; //初始化id
    export const IndexID_Init = -1; //初始化id

    //二维向量
    export class Vector2{
        x: number;
        y: number;

        constructor(x:number,y:number){
            this.x = x;
            this.y = y;
        }
        static Sub(vec:Vector2,vec2:Vector2){
            return new Vector2(vec.x - vec2.x,vec.y - vec2.y);
        }
        static Add(vec:Vector2,vec2:Vector2){
            return new Vector2(vec.x + vec2.x,vec.y + vec2.y);
        }
        static Multiply(vec:Vector2,number:number){
            return new Vector2(vec.x * number,vec.y * number);
        }
        static Divide(vec:Vector2,number:number){
            return new Vector2(vec.x / number,vec.y / number);
        }

        sub(vec:Vector2){
            this.x -= vec.x;
            this.y -= vec.y;
        }
        add(vec:Vector2){
            this.x += vec.x;
            this.y += vec.y;
        }
        multiply(number:number){
            this.x *= number;
            this.y *= number;
        }
        divide(number:number){
            this.x /= number;
            this.y /= number;
        }

        normalize(){
            let len = this.length();
            this.x /= len;
            this.y /= len;
        }
        length(){
            return Math.sqrt(this.x * this.x + this.y * this.y);
        }
        clone(){
            return new Vector2(this.x,this.y);
        }
    }

    // 在服务器端或客户端
    // import { Random } from './random';
    // const seed = 12345;
    // const random = new Random(seed);
    // const randomNum = random.nextInt(1, 100);
    // console.log(randomNum);
    export class Random {
        private seed: number;
        private a: number;
        private c: number;
        private m: number;

        constructor(seed: number) {
            this.seed = seed;
            this.a = 1664525;
            this.c = 1013904223;
            this.m = Math.pow(2, 32);
        }

        next(): number {
            this.seed = (this.a * this.seed + this.c) % this.m;
            return this.seed / this.m;
        }

        nextInt(min: number, max: number): number {
            return min + Math.floor(this.next() * (max - min + 1));
        }
    }


    //特殊数值
    export interface SpecialValue{
        attackType: ObjectValueType;
        value: number;
    }
    //英雄参数变化  
    export interface HeroDataChange{
        //英雄id  交换位置和主将技能时无hero
        heroID?: number;
        changeType: ObjectValueType;
        changeValueLlist: number[];
    };


    //敌人出生结构
    export class EnemyBornData{
        //出生时间
        bornTime:number;
        //出生点id
        positionID:number;
        //敌人类型id
        typeID:number;
        //等级
        level:number;
        //路线
        roldID:number;
    }
    
}