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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -61,7 +61,7 @@ public class BecomesTargetSourceTriggeredAbility extends TriggeredAbilityImpl {
if (targetingObject == null || !filter.match(targetingObject, getControllerId(), this, game)) {
return false;
}
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) {
if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false;
}
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);
this.costsToAdd = costsToAdd;
this.timing = TimingRule.INSTANT;
this.ruleAtTheTop = true;
this.setRuleAtTheTop(true);
CardUtil.increaseCost(this, costsToAdd);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -153,7 +153,7 @@ public class ConspireAbility extends StaticAbility implements OptionalAdditional
public ConspireAbility setAddedById(UUID addedById) {
this.addedById = addedById;
CardUtil.castStream(
this.subAbilities.stream(),
this.getSubAbilities().stream(),
ConspireTriggeredAbility.class
).forEach(ability -> ability.setAddedById(addedById));
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
return true;
} 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())) {
return false;
}
if (CardUtil.checkTargetedEventAlreadyUsed(this.id.toString(), targetingObject, event, game)) {
if (CardUtil.checkTargetedEventAlreadyUsed(this.getId().toString(), targetingObject, event, game)) {
return false;
}
getEffects().setTargetPointer(new FixedTarget(targetingObject.getId()));