cleanup access to fields in AbilityImpl

where trivially possible, make private and use getters
This commit is contained in:
xenohedron 2024-03-29 01:53:03 -04:00
parent 4bef01901d
commit a768a4dd8a
23 changed files with 53 additions and 53 deletions

View file

@ -94,7 +94,7 @@ class AgrusKosEternalSoldierTriggeredAbility extends TriggeredAbilityImpl {
if (targetingObject == null || targetingObject instanceof Spell) { if (targetingObject == null || targetingObject instanceof Spell) {
return false; return false;
} }
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) { if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false; return false;
} }
Set<UUID> targets = targetingObject Set<UUID> targets = targetingObject

View file

@ -75,7 +75,7 @@ class CarpetOfFlowersTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkInterveningIfClause(Game game) { public boolean checkInterveningIfClause(Game game) {
return !Boolean.TRUE.equals(game.getState().getValue(this.originalId.toString() return !Boolean.TRUE.equals(game.getState().getValue(this.getOriginalId().toString()
+ "addMana" + "addMana"
+ game.getState().getZoneChangeCounter(sourceId))); + game.getState().getZoneChangeCounter(sourceId)));
} }
@ -84,7 +84,7 @@ class CarpetOfFlowersTriggeredAbility extends TriggeredAbilityImpl {
public boolean resolve(Game game) { public boolean resolve(Game game) {
boolean value = super.resolve(game); boolean value = super.resolve(game);
if (value == true) { if (value == true) {
game.getState().setValue(this.originalId.toString() game.getState().setValue(this.getOriginalId().toString()
+ "addMana" + "addMana"
+ game.getState().getZoneChangeCounter(sourceId), + game.getState().getZoneChangeCounter(sourceId),
Boolean.TRUE); Boolean.TRUE);
@ -94,7 +94,7 @@ class CarpetOfFlowersTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public void reset(Game game) { public void reset(Game game) {
game.getState().setValue(this.originalId.toString() game.getState().setValue(this.getOriginalId().toString()
+ "addMana" + "addMana"
+ game.getState().getZoneChangeCounter(sourceId), + game.getState().getZoneChangeCounter(sourceId),
Boolean.FALSE); Boolean.FALSE);

View file

@ -97,7 +97,7 @@ class KarplusanMinotaurFlipLoseTriggeredAbility extends TriggeredAbilityImpl {
public KarplusanMinotaurFlipLoseTriggeredAbility() { public KarplusanMinotaurFlipLoseTriggeredAbility() {
super(Zone.BATTLEFIELD, new DamageTargetEffect(1), false); super(Zone.BATTLEFIELD, new DamageTargetEffect(1), false);
this.addTarget(new TargetAnyTarget()); this.addTarget(new TargetAnyTarget());
targetAdjuster = KarplusanMinotaurAdjuster.instance; this.setTargetAdjuster(KarplusanMinotaurAdjuster.instance);
} }
private KarplusanMinotaurFlipLoseTriggeredAbility(final KarplusanMinotaurFlipLoseTriggeredAbility ability) { private KarplusanMinotaurFlipLoseTriggeredAbility(final KarplusanMinotaurFlipLoseTriggeredAbility ability) {

View file

@ -83,14 +83,14 @@ class LeylineOfCombustionTriggeredAbility extends TriggeredAbilityImpl {
// If a spell targets you and/or a permanent you control multiple times, // If a spell targets you and/or a permanent you control multiple times,
// or if a spell targets you and one or more permanents you control, // or if a spell targets you and one or more permanents you control,
// Leyline of Combustions triggered ability triggers once. // Leyline of Combustions triggered ability triggers once.
Set<UUID> sourceObjects = (Set<UUID>) game.getState().getValue("sourceObjects" + this.id); Set<UUID> sourceObjects = (Set<UUID>) game.getState().getValue("sourceObjects" + this.getId());
if (sourceObjects == null) { if (sourceObjects == null) {
sourceObjects = new HashSet<>(); sourceObjects = new HashSet<>();
} }
if (!sourceObjects.add(sourceObject.getId())) { if (!sourceObjects.add(sourceObject.getId())) {
return false; return false;
} }
game.getState().setValue("sourceObjects" + this.id, sourceObjects); game.getState().setValue("sourceObjects" + this.getId(), sourceObjects);
this.getEffects().clear(); this.getEffects().clear();
Effect effect = new DamageTargetEffect(2); Effect effect = new DamageTargetEffect(2);
effect.setTargetPointer(new FixedTarget(event.getPlayerId(), game)); effect.setTargetPointer(new FixedTarget(event.getPlayerId(), game));

View file

@ -51,9 +51,9 @@ public final class SatyrFiredancer extends CardImpl {
class SatyrFiredancerTriggeredAbility extends TriggeredAbilityImpl { class SatyrFiredancerTriggeredAbility extends TriggeredAbilityImpl {
public SatyrFiredancerTriggeredAbility() { SatyrFiredancerTriggeredAbility() {
super(Zone.BATTLEFIELD, new SatyrFiredancerDamageEffect(), false); super(Zone.BATTLEFIELD, new SatyrFiredancerDamageEffect(), false);
targetAdjuster = SatyrFiredancerAdjuster.instance; this.setTargetAdjuster(SatyrFiredancerAdjuster.instance);
setTriggerPhrase("Whenever an instant or sorcery spell you control deals damage to an opponent, "); setTriggerPhrase("Whenever an instant or sorcery spell you control deals damage to an opponent, ");
} }

View file

@ -52,37 +52,37 @@ public abstract class AbilityImpl implements Ability {
private static final List<Ability> emptyAbilities = new ArrayList<>(); private static final List<Ability> emptyAbilities = new ArrayList<>();
protected UUID id; protected UUID id;
protected UUID originalId; // TODO: delete originalId??? private UUID originalId; // TODO: delete originalId???
protected AbilityType abilityType; protected AbilityType abilityType;
protected UUID controllerId; protected UUID controllerId;
protected UUID sourceId; protected UUID sourceId;
private final ManaCosts<ManaCost> manaCosts; private final ManaCosts<ManaCost> manaCosts;
private final ManaCosts<ManaCost> manaCostsToPay; private final ManaCosts<ManaCost> manaCostsToPay;
private final Costs<Cost> costs; private final Costs<Cost> costs;
protected Modes modes; // access to it by GetModes only (it can be overridden by some abilities) private final Modes modes; // access to it by GetModes only (it can be overridden by some abilities)
protected Zone zone; protected Zone zone;
protected String name; protected String name;
protected AbilityWord abilityWord; protected AbilityWord abilityWord;
protected String flavorWord; protected String flavorWord;
protected boolean usesStack = true; protected boolean usesStack = true;
protected boolean ruleAtTheTop = false; private boolean ruleAtTheTop = false;
protected boolean ruleVisible = true; private boolean ruleVisible = true;
protected boolean ruleAdditionalCostsVisible = true; private boolean ruleAdditionalCostsVisible = true;
protected boolean activated = false; protected boolean activated = false;
protected boolean worksFaceDown = false; private boolean worksFaceDown = false;
protected boolean worksPhasedOut = false; private boolean worksPhasedOut = false;
protected int sourceObjectZoneChangeCounter; private int sourceObjectZoneChangeCounter;
protected List<Watcher> watchers = new ArrayList<>(); // access to it by GetWatchers only (it can be overridden by some abilities) private List<Watcher> watchers = new ArrayList<>(); // access to it by GetWatchers only (it can be overridden by some abilities)
protected List<Ability> subAbilities = null; private List<Ability> subAbilities = null;
protected boolean canFizzle = true; private boolean canFizzle = true; // for Gilded Drake
protected TargetAdjuster targetAdjuster = null; private TargetAdjuster targetAdjuster = null;
protected CostAdjuster costAdjuster = null; private CostAdjuster costAdjuster = null;
protected List<Hint> hints = new ArrayList<>(); private List<Hint> hints = new ArrayList<>();
protected List<CardIcon> icons = new ArrayList<>(); protected List<CardIcon> icons = new ArrayList<>();
protected Outcome customOutcome = null; // uses for AI decisions instead effects private Outcome customOutcome = null; // uses for AI decisions instead effects
protected MageIdentifier identifier = MageIdentifier.Default; // used to identify specific ability (e.g. to match with corresponding watcher) private MageIdentifier identifier = MageIdentifier.Default; // used to identify specific ability (e.g. to match with corresponding watcher)
protected String appendToRule = null; private String appendToRule = null;
protected int sourcePermanentTransformCount = 0; private int sourcePermanentTransformCount = 0;
private Map<String, Object> costsTagMap = null; private Map<String, Object> costsTagMap = null;
protected AbilityImpl(AbilityType abilityType, Zone zone) { protected AbilityImpl(AbilityType abilityType, Zone zone) {
@ -719,7 +719,7 @@ public abstract class AbilityImpl implements Ability {
return costsTagMap; return costsTagMap;
} }
public void setCostsTag(String tag, Object value){ public void setCostsTag(String tag, Object value){
if (costsTagMap == null){ if (costsTagMap == null) {
costsTagMap = new HashMap<>(); costsTagMap = new HashMap<>();
} }
costsTagMap.put(tag, value); costsTagMap.put(tag, value);

View file

@ -238,11 +238,11 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
protected ActivationInfo getActivationInfo(Game game) { protected ActivationInfo getActivationInfo(Game game) {
Integer turnNum = (Integer) game.getState() Integer turnNum = (Integer) game.getState()
.getValue(CardUtil.getCardZoneString("activationsTurn" + originalId, sourceId, game)); .getValue(CardUtil.getCardZoneString("activationsTurn" + getOriginalId(), sourceId, game));
Integer activationCount = (Integer) game.getState() Integer activationCount = (Integer) game.getState()
.getValue(CardUtil.getCardZoneString("activationsCount" + originalId, sourceId, game)); .getValue(CardUtil.getCardZoneString("activationsCount" + getOriginalId(), sourceId, game));
Integer totalActivations = (Integer) game.getState() Integer totalActivations = (Integer) game.getState()
.getValue(CardUtil.getCardZoneString("totalActivations" + originalId, sourceId, game)); .getValue(CardUtil.getCardZoneString("totalActivations" + getOriginalId(), sourceId, game));
if (turnNum == null || activationCount == null || totalActivations == null) { if (turnNum == null || activationCount == null || totalActivations == null) {
return null; return null;
} }
@ -251,11 +251,11 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
protected void setActivationInfo(ActivationInfo activationInfo, Game game) { protected void setActivationInfo(ActivationInfo activationInfo, Game game) {
game.getState().setValue(CardUtil game.getState().setValue(CardUtil
.getCardZoneString("activationsTurn" + originalId, sourceId, game), activationInfo.turnNum); .getCardZoneString("activationsTurn" + getOriginalId(), sourceId, game), activationInfo.turnNum);
game.getState().setValue(CardUtil game.getState().setValue(CardUtil
.getCardZoneString("activationsCount" + originalId, sourceId, game), activationInfo.activationCounter); .getCardZoneString("activationsCount" + getOriginalId(), sourceId, game), activationInfo.activationCounter);
game.getState().setValue(CardUtil game.getState().setValue(CardUtil
.getCardZoneString("totalActivations" + originalId, sourceId, game), activationInfo.totalActivations); .getCardZoneString("totalActivations" + getOriginalId(), sourceId, game), activationInfo.totalActivations);
} }
@Override @Override

View file

@ -32,7 +32,7 @@ public class SpecialActions extends AbilitiesImpl<SpecialAction> {
LinkedHashMap<UUID, SpecialAction> controlledBy = new LinkedHashMap<>(); LinkedHashMap<UUID, SpecialAction> controlledBy = new LinkedHashMap<>();
for (SpecialAction action : this) { for (SpecialAction action : this) {
if (action.isControlledBy(controllerId) && action.isManaAction() == manaAction) { if (action.isControlledBy(controllerId) && action.isManaAction() == manaAction) {
controlledBy.put(action.id, action); controlledBy.put(action.getId(), action);
} }
} }
return controlledBy; return controlledBy;

View file

@ -358,6 +358,6 @@ public class SpellAbility extends ActivatedAbilityImpl {
} }
public void setId(UUID idToUse) { public void setId(UUID idToUse) {
this.id = idToUse; this.id = idToUse; // TODO: research, why is it needed
} }
} }

View file

@ -75,7 +75,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return; return;
} }
game.getState().setValue(CardUtil.getCardZoneString( game.getState().setValue(CardUtil.getCardZoneString(
"lastTurnTriggered" + originalId, sourceId, game "lastTurnTriggered" + getOriginalId(), sourceId, game
), game.getTurnNum()); ), game.getTurnNum());
} }
@ -101,7 +101,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return true; return true;
} }
Integer lastTurnTriggered = (Integer) game.getState().getValue( Integer lastTurnTriggered = (Integer) game.getState().getValue(
CardUtil.getCardZoneString("lastTurnTriggered" + originalId, sourceId, game) CardUtil.getCardZoneString("lastTurnTriggered" + getOriginalId(), sourceId, game)
); );
return lastTurnTriggered == null || lastTurnTriggered != game.getTurnNum(); return lastTurnTriggered == null || lastTurnTriggered != game.getTurnNum();
} }
@ -112,7 +112,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return false; return false;
} }
Integer lastTurnUsed = (Integer) game.getState().getValue( Integer lastTurnUsed = (Integer) game.getState().getValue(
CardUtil.getCardZoneString("lastTurnUsed" + originalId, sourceId, game) CardUtil.getCardZoneString("lastTurnUsed" + getOriginalId(), sourceId, game)
); );
return lastTurnUsed != null && lastTurnUsed == game.getTurnNum(); return lastTurnUsed != null && lastTurnUsed == game.getTurnNum();
} }
@ -165,7 +165,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
} }
if (doOnlyOnceEachTurn) { if (doOnlyOnceEachTurn) {
game.getState().setValue(CardUtil.getCardZoneString( game.getState().setValue(CardUtil.getCardZoneString(
"lastTurnUsed" + originalId, sourceId, game "lastTurnUsed" + getOriginalId(), sourceId, game
), game.getTurnNum()); ), game.getTurnNum());
} }
//20091005 - 603.4 //20091005 - 603.4

View file

@ -74,7 +74,7 @@ public class BecomesTargetAnyTriggeredAbility extends TriggeredAbilityImpl {
if (targetingObject == null || !filterStack.match(targetingObject, getControllerId(), this, game)) { if (targetingObject == null || !filterStack.match(targetingObject, getControllerId(), this, game)) {
return false; return false;
} }
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) { if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false; return false;
} }
switch (setTargetPointer) { switch (setTargetPointer) {

View file

@ -58,7 +58,7 @@ public class BecomesTargetAttachedTriggeredAbility extends TriggeredAbilityImpl
if (targetingObject == null || !filter.match(targetingObject, getControllerId(), this, game)) { if (targetingObject == null || !filter.match(targetingObject, getControllerId(), this, game)) {
return false; return false;
} }
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) { if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false; return false;
} }
switch (setTargetPointer) { switch (setTargetPointer) {

View file

@ -67,7 +67,7 @@ public class BecomesTargetControllerTriggeredAbility extends TriggeredAbilityImp
if (targetingObject == null || !filterStack.match(targetingObject, getControllerId(), this, game)) { if (targetingObject == null || !filterStack.match(targetingObject, getControllerId(), this, game)) {
return false; return false;
} }
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) { if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false; return false;
} }
switch (setTargetPointer) { switch (setTargetPointer) {

View file

@ -61,7 +61,7 @@ public class BecomesTargetSourceTriggeredAbility extends TriggeredAbilityImpl {
if (targetingObject == null || !filter.match(targetingObject, getControllerId(), this, game)) { if (targetingObject == null || !filter.match(targetingObject, getControllerId(), this, game)) {
return false; return false;
} }
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) { if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false; return false;
} }
switch (setTargetPointer) { switch (setTargetPointer) {

View file

@ -20,7 +20,7 @@ public class PayMoreToCastAsThoughtItHadFlashAbility extends SpellAbility {
super(card.getSpellAbility().getManaCosts().copy(), card.getName() + " as though it had flash", Zone.HAND, SpellAbilityType.BASE_ALTERNATE); super(card.getSpellAbility().getManaCosts().copy(), card.getName() + " as though it had flash", Zone.HAND, SpellAbilityType.BASE_ALTERNATE);
this.costsToAdd = costsToAdd; this.costsToAdd = costsToAdd;
this.timing = TimingRule.INSTANT; this.timing = TimingRule.INSTANT;
this.ruleAtTheTop = true; this.setRuleAtTheTop(true);
CardUtil.increaseCost(this, costsToAdd); CardUtil.increaseCost(this, costsToAdd);
} }

View file

@ -43,7 +43,7 @@ public class AtTheBeginOfNextCleanupDelayedTriggeredAbility extends DelayedTrigg
@Override @Override
public String getRule() { public String getRule() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String text = modes.getText(); String text = getModes().getText();
if (!text.isEmpty()) { if (!text.isEmpty()) {
sb.append(Character.toUpperCase(text.charAt(0))); sb.append(Character.toUpperCase(text.charAt(0)));
if (text.endsWith(".")) { if (text.endsWith(".")) {

View file

@ -43,7 +43,7 @@ public class AtTheBeginOfNextUpkeepDelayedTriggeredAbility extends DelayedTrigge
@Override @Override
public String getRule() { public String getRule() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String text = modes.getText(); String text = getModes().getText();
if (!text.isEmpty()) { if (!text.isEmpty()) {
sb.append(Character.toUpperCase(text.charAt(0))); sb.append(Character.toUpperCase(text.charAt(0)));
if (text.endsWith(".")) { if (text.endsWith(".")) {

View file

@ -21,7 +21,7 @@ public class CastSourceTriggeredAbility extends TriggeredAbilityImpl {
public CastSourceTriggeredAbility(Effect effect, boolean optional) { public CastSourceTriggeredAbility(Effect effect, boolean optional) {
super(Zone.STACK, effect, optional); super(Zone.STACK, effect, optional);
this.ruleAtTheTop = true; this.setRuleAtTheTop(true);
setTriggerPhrase("When you cast this spell, "); setTriggerPhrase("When you cast this spell, ");
} }

View file

@ -39,7 +39,7 @@ public class BlitzAbility extends SpellAbility {
ability.addEffect(new BlitzAddDelayedTriggeredAbilityEffect()); ability.addEffect(new BlitzAddDelayedTriggeredAbilityEffect());
ability.setRuleVisible(false); ability.setRuleVisible(false);
addSubAbility(ability); addSubAbility(ability);
this.ruleAdditionalCostsVisible = false; this.setAdditionalCostsRuleVisible(false);
this.timing = TimingRule.SORCERY; this.timing = TimingRule.SORCERY;
} }

View file

@ -22,7 +22,7 @@ public class CommanderStormAbility extends TriggeredAbilityImpl {
public CommanderStormAbility() { public CommanderStormAbility() {
super(Zone.STACK, new CommanderStormEffect()); super(Zone.STACK, new CommanderStormEffect());
this.ruleAtTheTop = true; this.setRuleAtTheTop(true);
} }
private CommanderStormAbility(final CommanderStormAbility ability) { private CommanderStormAbility(final CommanderStormAbility ability) {

View file

@ -153,7 +153,7 @@ public class ConspireAbility extends StaticAbility implements OptionalAdditional
public ConspireAbility setAddedById(UUID addedById) { public ConspireAbility setAddedById(UUID addedById) {
this.addedById = addedById; this.addedById = addedById;
CardUtil.castStream( CardUtil.castStream(
this.subAbilities.stream(), this.getSubAbilities().stream(),
ConspireTriggeredAbility.class ConspireTriggeredAbility.class
).forEach(ability -> ability.setAddedById(addedById)); ).forEach(ability -> ability.setAddedById(addedById));
return this; return this;

View file

@ -110,7 +110,7 @@ public class EmergeAbility extends SpellAbility {
this.setCostsTag(EMERGE_ACTIVATION_CREATURE_REFERENCE, mor); //Can access with LKI afterwards this.setCostsTag(EMERGE_ACTIVATION_CREATURE_REFERENCE, mor); //Can access with LKI afterwards
return true; return true;
} else { } else {
activated = false; activated = false; // TODO: research, why
} }
} }
} }

View file

@ -81,7 +81,7 @@ public class WardAbility extends TriggeredAbilityImpl {
if (targetingObject == null || !game.getOpponents(getControllerId()).contains(targetingObject.getControllerId())) { if (targetingObject == null || !game.getOpponents(getControllerId()).contains(targetingObject.getControllerId())) {
return false; return false;
} }
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) { if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false; return false;
} }
getEffects().setTargetPointer(new FixedTarget(targetingObject.getId())); getEffects().setTargetPointer(new FixedTarget(targetingObject.getId()));