Search in sources :

Example 1 with Transport

use of enums.Transport in project KaellyBot by Kaysoro.

the class DistanceCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        m.find();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Position position = new Position(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
        StringBuilder st = new StringBuilder();
        Transport zaap = null;
        Transport transportLimited = null;
        if (!position.isNull()) {
            double minDist = Double.MAX_VALUE;
            double minDistLimited = Double.MAX_VALUE;
            for (Transport transport : Transport.values()) {
                double tmp = transport.getPosition().getDistance(position);
                if (transport.isFreeAccess() && (zaap == null || minDist > tmp)) {
                    zaap = transport;
                    minDist = tmp;
                }
                if (!transport.isFreeAccess() && (transportLimited == null || minDistLimited > tmp)) {
                    transportLimited = transport;
                    minDistLimited = tmp;
                }
            }
            st.append(Translator.getLabel(lg, "distance.request.1")).append(" ").append(zaap.toDiscordString(lg));
            if (minDist > minDistLimited)
                st.append("\n").append(Translator.getLabel(lg, "distance.request.2")).append(" ").append(transportLimited.toDiscordString(lg));
        } else
            st.append(Translator.getLabel(lg, "distance.request.3"));
        Message.sendText(message.getChannel(), st.toString());
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) Position(data.Position) Transport(enums.Transport)

Example 2 with Transport

use of enums.Transport in project KaellyBot by Kaysoro.

the class Portal method determineTransports.

private void determineTransports() {
    if (isValid()) {
        double minDist = Double.MAX_VALUE;
        double minDistLimited = Double.MAX_VALUE;
        for (Transport transport : Transport.values()) {
            double tmp = transport.getPosition().getDistance(coordonate);
            if (transport.isFreeAccess() && (zaap == null || minDist > tmp)) {
                zaap = transport;
                minDist = tmp;
            }
            if (!transport.isFreeAccess() && (transportLimited == null || minDistLimited > tmp)) {
                transportLimited = transport;
                minDistLimited = tmp;
            }
        }
        if (minDist < minDistLimited)
            transportLimited = null;
    } else {
        zaap = null;
        transportLimited = null;
    }
}
Also used : Transport(enums.Transport)

Aggregations

Transport (enums.Transport)2 Position (data.Position)1 Language (enums.Language)1 Matcher (java.util.regex.Matcher)1