mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 17:05:20 +01:00
Refactor WeaponType and MonsterType into enums
This commit is contained in:
44
src/main/java/emu/grasscutter/game/props/MonsterType.java
Normal file
44
src/main/java/emu/grasscutter/game/props/MonsterType.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package emu.grasscutter.game.props;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public enum MonsterType {
|
||||
MONSTER_NONE (0),
|
||||
MONSTER_ORDINARY (1),
|
||||
MONSTER_BOSS (2),
|
||||
MONSTER_ENV_ANIMAL (3),
|
||||
MONSTER_LITTLE_MONSTER (4),
|
||||
MONSTER_FISH (5);
|
||||
|
||||
private final int value;
|
||||
private static final Int2ObjectMap<MonsterType> map = new Int2ObjectOpenHashMap<>();
|
||||
private static final Map<String, MonsterType> stringMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
Stream.of(values()).forEach(e -> {
|
||||
map.put(e.getValue(), e);
|
||||
stringMap.put(e.name(), e);
|
||||
});
|
||||
}
|
||||
|
||||
private MonsterType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static MonsterType getTypeByValue(int value) {
|
||||
return map.getOrDefault(value, MONSTER_NONE);
|
||||
}
|
||||
|
||||
public static MonsterType getTypeByName(String name) {
|
||||
return stringMap.getOrDefault(name, MONSTER_NONE);
|
||||
}
|
||||
}
|
||||
69
src/main/java/emu/grasscutter/game/props/WeaponType.java
Normal file
69
src/main/java/emu/grasscutter/game/props/WeaponType.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package emu.grasscutter.game.props;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public enum WeaponType {
|
||||
WEAPON_NONE (0),
|
||||
WEAPON_SWORD_ONE_HAND (1),
|
||||
WEAPON_CROSSBOW (2),
|
||||
WEAPON_STAFF (3),
|
||||
WEAPON_DOUBLE_DAGGER (4),
|
||||
WEAPON_KATANA (5),
|
||||
WEAPON_SHURIKEN (6),
|
||||
WEAPON_STICK (7),
|
||||
WEAPON_SPEAR (8),
|
||||
WEAPON_SHIELD_SMALL (9),
|
||||
WEAPON_CATALYST (10),
|
||||
WEAPON_CLAYMORE (11),
|
||||
WEAPON_BOW (12),
|
||||
WEAPON_POLE (13);
|
||||
|
||||
private final int value;
|
||||
private int energyGainInitialProbability;
|
||||
private int energyGainIncreaseProbability;
|
||||
|
||||
private static final Int2ObjectMap<WeaponType> map = new Int2ObjectOpenHashMap<>();
|
||||
private static final Map<String, WeaponType> stringMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
Stream.of(values()).forEach(e -> {
|
||||
map.put(e.getValue(), e);
|
||||
stringMap.put(e.name(), e);
|
||||
});
|
||||
}
|
||||
|
||||
private WeaponType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private WeaponType(int value, int energyGainInitialProbability, int energyGainIncreaseProbability) {
|
||||
this.value = value;
|
||||
this.energyGainInitialProbability = energyGainInitialProbability;
|
||||
this.energyGainIncreaseProbability = energyGainIncreaseProbability;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getEnergyGainInitialProbability() {
|
||||
return energyGainInitialProbability;
|
||||
}
|
||||
|
||||
public int getEnergyGainIncreaseProbability() {
|
||||
return energyGainIncreaseProbability;
|
||||
}
|
||||
|
||||
public static WeaponType getTypeByValue(int value) {
|
||||
return map.getOrDefault(value, WEAPON_NONE);
|
||||
}
|
||||
|
||||
public static WeaponType getTypeByName(String name) {
|
||||
return stringMap.getOrDefault(name, WEAPON_NONE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user