use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class MaterialBuilder method stat.
public MaterialBuilder stat(PartType partType, IItemStat stat, GearType gearType, float value, StatInstance.Operation operation) {
StatGearKey key = StatGearKey.of(stat, gearType);
StatInstance mod = StatInstance.of(value, operation, key);
StatModifierMap map = stats.computeIfAbsent(partType, pt -> new StatModifierMap());
map.put(stat, gearType, mod);
return this;
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class ItemStat method computeForDisplay.
public StatInstance computeForDisplay(float baseValue, GearType gearType, Collection<StatInstance> modifiers) {
if (modifiers.isEmpty()) {
return StatInstance.of(baseValue, Operation.AVG, StatInstance.DEFAULT_KEY);
}
int add = 1;
for (StatInstance inst : modifiers) {
Operation op = inst.getOp();
if (op == Operation.AVG || op == Operation.ADD || op == Operation.MAX) {
add = 0;
break;
}
}
float value = compute(baseValue + add, false, gearType, modifiers) - add;
Operation op = modifiers.iterator().next().getOp();
return StatInstance.of(value, op, StatInstance.DEFAULT_KEY);
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class StatInstance method getWeightedAverageMod.
public static StatInstance getWeightedAverageMod(Collection<StatInstance> modifiers, Operation op) {
float value = ItemStat.getWeightedAverage(modifiers, op);
StatGearKey key = getMostSpecificKey(modifiers);
return new StatInstance(value, op, key);
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class StatInstance method getMostSpecificKey.
private static StatGearKey getMostSpecificKey(Collection<StatInstance> modifiers) {
// Gets the key furthest down the gear type hierarchy (key with most parents)
Set<StatGearKey> found = new HashSet<>();
for (StatInstance mod : modifiers) {
found.add(mod.key);
}
StatGearKey ret = null;
int best = 0;
for (StatGearKey key : found) {
int parents = 0;
StatGearKey parent = key.getParent();
while (parent != null) {
parent = parent.getParent();
++parents;
}
if (parents > best || ret == null) {
best = parents;
ret = key;
}
}
return ret != null ? ret : DEFAULT_KEY;
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class StatModifierMap method deserialize.
public static StatModifierMap deserialize(JsonElement json) {
StatModifierMap map = new StatModifierMap();
if (json.isJsonObject()) {
for (Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
StatGearKey key = StatGearKey.read(entry.getKey());
if (key != null) {
JsonElement value = entry.getValue();
if (value.isJsonArray()) {
for (JsonElement je : value.getAsJsonArray()) {
StatInstance mod = StatInstance.read(key, je);
map.put(key, mod);
}
} else {
map.put(key, StatInstance.read(key, value));
}
}
}
} else if (json.isJsonArray()) {
for (JsonElement element : json.getAsJsonArray()) {
JsonObject jsonObj = element.getAsJsonObject();
StatGearKey key = StatGearKey.read(GsonHelper.getAsString(jsonObj, "name"));
if (key != null) {
map.put(key, StatInstance.read(key, element));
}
}
} else {
throw new JsonParseException("Expected object or array");
}
return map;
}
Aggregations