2018-09-12 01:29:49 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.google.common.base.Strings;
|
|
|
|
|
|
|
|
public enum Race {
|
2019-01-29 13:13:06 +01:00
|
|
|
/**
|
|
|
|
* The default, unset race.
|
|
|
|
* This is used if there are no other races.
|
|
|
|
*/
|
2018-09-12 01:29:49 +02:00
|
|
|
HUMAN(false, false, false),
|
|
|
|
EARTH(false, false, true),
|
|
|
|
UNICORN(true, false, false),
|
|
|
|
PEGASUS(false, true, false),
|
|
|
|
ALICORN(true, true, true),
|
|
|
|
CHANGELING(false, true, false);
|
|
|
|
|
|
|
|
private final boolean magic;
|
|
|
|
private final boolean flight;
|
|
|
|
private final boolean earth;
|
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
private final static Map<Integer, Race> raceIdMap = new HashMap<>();
|
|
|
|
static {
|
|
|
|
for (Race race : values()) {
|
|
|
|
raceIdMap.put(race.ordinal(), race);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
Race(boolean magic, boolean flight, boolean earth) {
|
|
|
|
this.magic = magic;
|
|
|
|
this.flight = flight;
|
|
|
|
this.earth = earth;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDefault() {
|
|
|
|
return this == HUMAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canFly() {
|
|
|
|
return flight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canCast() {
|
|
|
|
return magic;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseEarth() {
|
|
|
|
return earth;
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
public boolean canInteractWithClouds() {
|
|
|
|
return canFly() && this != CHANGELING;
|
|
|
|
}
|
|
|
|
|
2019-01-31 16:21:14 +01:00
|
|
|
public String getTranslationKey() {
|
2018-09-12 22:37:06 +02:00
|
|
|
return String.format("unicopia.race.%s", name().toLowerCase());
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSameAs(String s) {
|
|
|
|
return name().equalsIgnoreCase(s)
|
2019-01-31 16:21:14 +01:00
|
|
|
|| getTranslationKey().equalsIgnoreCase(s);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
public static Race fromName(String s, Race def) {
|
2018-09-12 01:29:49 +02:00
|
|
|
if (!Strings.isNullOrEmpty(s)) {
|
|
|
|
for (Race i : values()) {
|
|
|
|
if (i.isSameAs(s)) return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-09-12 22:37:06 +02:00
|
|
|
return fromId(Integer.parseInt(s));
|
2018-09-12 01:29:49 +02:00
|
|
|
} catch (NumberFormatException e) { }
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
return def;
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 13:13:06 +01:00
|
|
|
public static Race fromName(String name) {
|
|
|
|
return fromName(name, EARTH);
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
public static Race fromId(int id) {
|
2019-01-29 13:13:06 +01:00
|
|
|
return raceIdMap.getOrDefault(id, EARTH);
|
2018-09-12 22:37:06 +02:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|