refactor: SourcePermanentPowerValue to enum (#13040)

* refactor: standard enum style for SourcePermanentToughnessValue

* refactor SourcePermanentPowerCount to enum SourcePermanentPowerValue

add comments on usage of NOT_NEGATIVE vs ALLOW_NEGATIVE
This commit is contained in:
xenohedron 2024-10-27 00:19:38 -04:00 committed by GitHub
parent 5070f8bef7
commit fb71ce8c85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
124 changed files with 435 additions and 624 deletions

View file

@ -3,46 +3,24 @@ package mage.abilities.dynamicvalue.common;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.io.ObjectStreamException;
/**
* @author LevelX2
* @author xenohedron
*/
public class SourcePermanentToughnessValue implements DynamicValue {
private static final SourcePermanentToughnessValue instance = new SourcePermanentToughnessValue();
private Object readResolve() throws ObjectStreamException {
return instance;
}
public static SourcePermanentToughnessValue getInstance() {
return instance;
}
private SourcePermanentToughnessValue() {
}
public enum SourcePermanentToughnessValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Permanent sourcePermanent = game.getPermanent(sourceAbility.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD);
}
if (sourcePermanent != null) {
return sourcePermanent.getToughness().getValue();
}
return 0;
Permanent sourcePermanent = sourceAbility.getSourcePermanentOrLKI(game);
return sourcePermanent == null ? 0 : sourcePermanent.getToughness().getValue();
}
@Override
public SourcePermanentToughnessValue copy() {
return new SourcePermanentToughnessValue();
return instance;
}
@Override