Search in sources :

Example 1 with SynergyTrait

use of net.silentchaos512.gear.gear.trait.SynergyTrait in project Silent-Gear by SilentChaos512.

the class SynergyUtils method getSynergy.

public static float getSynergy(PartType partType, List<? extends IMaterialInstance> materials, Collection<TraitInstance> traits) {
    if (materials.isEmpty()) {
        return 1;
    }
    // First, we add a bonus for the number of unique materials
    double synergy = getBaseSynergy(materials);
    // Second, reduce synergy for differences in certain properties
    IMaterialInstance primary = materials.get(0);
    final double primaryRarity = primary.getStat(partType, ItemStats.RARITY);
    final double maxRarity = materials.stream().mapToDouble(m -> m.getStat(partType, ItemStats.RARITY)).max().orElse(0);
    final int maxTier = materials.stream().mapToInt(m -> m.getTier(partType)).max().orElse(0);
    for (IMaterialInstance material : getUniques(materials)) {
        if (maxRarity > 0) {
            float rarity = material.getStat(partType, ItemStats.RARITY);
            synergy -= 0.005 * Math.abs(primaryRarity - rarity);
        }
        if (maxTier > 0) {
            int tier = material.getTier(partType);
            synergy -= 0.08 * Math.abs(maxTier - tier);
        }
    }
    // Synergy traits
    for (TraitInstance trait : traits) {
        if (trait.getTrait() instanceof SynergyTrait) {
            synergy = ((SynergyTrait) trait.getTrait()).apply(synergy, trait.getLevel());
        }
    }
    return (float) Mth.clamp(synergy, MIN_VALUE, MAX_VALUE);
}
Also used : SynergyTrait(net.silentchaos512.gear.gear.trait.SynergyTrait) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Aggregations

IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)1 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)1 SynergyTrait (net.silentchaos512.gear.gear.trait.SynergyTrait)1