Apply trait-specific corruption when using a spell

This commit is contained in:
Sollace 2022-09-02 21:52:33 +02:00
parent ceac5bb649
commit 3e848e86ed
4 changed files with 11 additions and 1 deletions

View file

@ -25,6 +25,11 @@ public interface Spell extends NbtSerialisable, Affine {
*/
SpellType<?> getType();
/**
* Gets the traits of this spell.
*/
SpellTraits getTraits();
/**
* The unique id of this particular spell instance.
*/

View file

@ -35,7 +35,7 @@ public abstract class AbstractSpell implements Spell {
return type;
}
protected SpellTraits getTraits() {
public final SpellTraits getTraits() {
return traits == null ? SpellTraits.EMPTY : traits;
}

View file

@ -48,6 +48,10 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
this(new EnumMap<>(from.traits));
}
public float getCorruption() {
return (float)stream().filter(e -> e.getValue() != 0).mapToDouble(e -> e.getKey().getGroup().getCorruption()).sum();
}
public SpellTraits multiply(float factor) {
return factor == 0 ? EMPTY : map(v -> v * factor);
}

View file

@ -606,6 +606,7 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
if (spell.getAffinity() == Affinity.BAD && entity.getWorld().random.nextInt(120) == 0) {
getCorruption().add(1);
}
getCorruption().add((int)spell.getTraits().getCorruption());
}
setDirty();
}