mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 22:12:03 -08:00
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:
parent
5070f8bef7
commit
fb71ce8c85
124 changed files with 435 additions and 624 deletions
|
|
@ -1,60 +0,0 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* @author Loki
|
||||
*/
|
||||
public class SourcePermanentPowerCount implements DynamicValue {
|
||||
|
||||
private final boolean allowNegativeValues;
|
||||
|
||||
public SourcePermanentPowerCount() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public SourcePermanentPowerCount(boolean allowNegativeValues) {
|
||||
super();
|
||||
this.allowNegativeValues = allowNegativeValues;
|
||||
}
|
||||
|
||||
protected SourcePermanentPowerCount(final SourcePermanentPowerCount dynamicValue) {
|
||||
super();
|
||||
this.allowNegativeValues = dynamicValue.allowNegativeValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
Permanent sourcePermanent = game.getPermanent(sourceAbility.getSourceId());
|
||||
if (sourcePermanent == null
|
||||
|| (sourceAbility.getSourceObjectZoneChangeCounter() > 0
|
||||
&& sourcePermanent.getZoneChangeCounter(game) > sourceAbility.getSourceObjectZoneChangeCounter())) {
|
||||
sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD);
|
||||
}
|
||||
if (sourcePermanent != null
|
||||
&& (allowNegativeValues || sourcePermanent.getPower().getValue() >= 0)) {
|
||||
return sourcePermanent.getPower().getValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourcePermanentPowerCount copy() {
|
||||
return new SourcePermanentPowerCount(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "X";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "{this}'s power";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author xenohedron
|
||||
*/
|
||||
public enum SourcePermanentPowerValue implements DynamicValue {
|
||||
ALLOW_NEGATIVE(true), // 107.1b, only for setting power/toughness/life to a specific value or doubling
|
||||
NOT_NEGATIVE(false); // all other usages
|
||||
|
||||
private final boolean allowNegativeValues;
|
||||
|
||||
SourcePermanentPowerValue(boolean allowNegativeValues) {
|
||||
this.allowNegativeValues = allowNegativeValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
Permanent sourcePermanent = sourceAbility.getSourcePermanentOrLKI(game);
|
||||
if (sourcePermanent == null) {
|
||||
return 0;
|
||||
}
|
||||
int value = sourcePermanent.getPower().getValue();
|
||||
if (allowNegativeValues || value > 0) {
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourcePermanentPowerValue copy() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "X";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "{this}'s power";
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import mage.abilities.Ability;
|
|||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.costs.common.TapSourceCost;
|
||||
import mage.abilities.dynamicvalue.common.SourcePermanentPowerCount;
|
||||
import mage.abilities.dynamicvalue.common.SourcePermanentPowerValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.DamageTargetEffect;
|
||||
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
|
||||
|
|
@ -28,7 +28,7 @@ public final class ArlinnEmbracedByTheMoonEmblem extends Emblem {
|
|||
GainAbilityControlledEffect effect = new GainAbilityControlledEffect(HasteAbility.getInstance(), Duration.EndOfGame, filter);
|
||||
effect.setText("Creatures you control have haste");
|
||||
Ability ability = new SimpleStaticAbility(Zone.COMMAND, effect);
|
||||
Effect effect2 = new DamageTargetEffect(new SourcePermanentPowerCount());
|
||||
Effect effect2 = new DamageTargetEffect(SourcePermanentPowerValue.NOT_NEGATIVE);
|
||||
effect2.setText("This creature deals damage equal to its power to any target");
|
||||
Ability ability2 = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect2, new TapSourceCost());
|
||||
ability2.addTarget(new TargetAnyTarget());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue