import { Vec2 } from "cc";
import GRoleBase from "../base/role/GRoleBase";

//模式工具类
export default class GModeTools{

    //通过距离获取最近的敌人
    static getNearbyEnumy(player:GRoleBase<{}>,roles:GRoleBase<{}>[]){
        //通过距离获取最近的敌人
        if(roles[0]){
            let len = Math.abs(Vec2.distance(player.v2World,roles[0].v2World));
            let enumy = roles[0];
            for (let index = 0; index < roles.length; index++) {
                const role = roles[index];
                let tLen;
                if(tLen = Math.abs(Vec2.distance(player.v2World,role.v2World)) < len){
                    enumy = role;
                    len = tLen;
                }
                
            }
            return enumy;
        }else{
            return null;
        }
    }

}

