refactor: remaining copy() for target pointer from #11743

This commit is contained in:
xenohedron 2024-02-03 16:29:11 -05:00
parent 6cf05a554c
commit f398368c96
16 changed files with 47 additions and 47 deletions

View file

@ -129,7 +129,7 @@ class DoUnlessAnyOpponentPaysEffect extends OneShotEffect {
// do the effects if nobody paid
if (doEffect) {
for (Effect effect : executingEffects) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
if (effect instanceof OneShotEffect) {
result &= effect.apply(game, source);
} else {

View file

@ -50,10 +50,10 @@ public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
public boolean apply(Game game, Ability source) {
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.apply(game, source);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.apply(game, source);
}
if (!conditionState && effect.getDuration() == Duration.OneUse) {
@ -69,10 +69,10 @@ public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(sourceId, affectedAbility, source, game, playerId);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(sourceId, affectedAbility, source, game, playerId);
}
return false;
@ -82,10 +82,10 @@ public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(sourceId, source, affectedControllerId, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(sourceId, source, affectedControllerId, game);
}
return false;

View file

@ -81,10 +81,10 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
} else {
condition = baseCondition;
}
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
effect.init(source, game);
if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
otherwiseEffect.init(source, game);
}
initDone = true;
@ -122,10 +122,10 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
}
boolean conditionState = condition != null && condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.apply(game, source);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.apply(game, source);
}
switch (effect.getDuration()) {

View file

@ -52,10 +52,10 @@ public class ConditionalContinuousRuleModifyingEffect extends ContinuousRuleModi
} else {
condition = baseCondition;
}
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
effect.init(source, game);
if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
otherwiseEffect.init(source, game);
}
initDone = true;
@ -82,10 +82,10 @@ public class ConditionalContinuousRuleModifyingEffect extends ContinuousRuleModi
init(source, game);
}
if (condition.apply(game, source)) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(event, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(event, source, game);
}
return false;

View file

@ -51,10 +51,10 @@ public class ConditionalCostModificationEffect extends CostModificationEffectImp
public boolean apply(Game game, Ability source, Ability abilityToModify) {
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.apply(game, source, abilityToModify);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.apply(game, source, abilityToModify);
}
if (!conditionState && effect.getDuration() == Duration.OneUse) {
@ -70,10 +70,10 @@ public class ConditionalCostModificationEffect extends CostModificationEffectImp
public boolean applies(Ability abilityToModify, Ability source, Game game) {
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(abilityToModify, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(abilityToModify, source, game);
}
return false;

View file

@ -53,7 +53,7 @@ public class ConditionalOneShotEffect extends OneShotEffect {
if (toApply.isEmpty()) {
return true;
}
toApply.setTargetPointer(this.targetPointer);
toApply.setTargetPointer(this.getTargetPointer().copy());
toApply.stream().forEach(effect -> effect.apply(game, source));
return true;
}

View file

@ -68,10 +68,10 @@ public class ConditionalPreventionEffect extends PreventionEffectImpl {
} else {
condition = baseCondition;
}
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
effect.init(source, game);
if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
otherwiseEffect.init(source, game);
}
initDone = true;
@ -80,10 +80,10 @@ public class ConditionalPreventionEffect extends PreventionEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.replaceEvent(event, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.replaceEvent(event, source, game);
}
@ -110,10 +110,10 @@ public class ConditionalPreventionEffect extends PreventionEffectImpl {
}
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(event, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(event, source, game);
}
return false;

View file

@ -60,10 +60,10 @@ public class ConditionalReplacementEffect extends ReplacementEffectImpl {
} else {
condition = baseCondition;
}
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
effect.init(source, game);
if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
otherwiseEffect.init(source, game);
}
initDone = true;
@ -72,10 +72,10 @@ public class ConditionalReplacementEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.replaceEvent(event, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.replaceEvent(event, source, game);
}
if (!conditionState && effect.getDuration() == Duration.OneUse) {
@ -100,10 +100,10 @@ public class ConditionalReplacementEffect extends ReplacementEffectImpl {
}
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(event, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(event, source, game);
}
return false;

View file

@ -64,10 +64,10 @@ public class ConditionalRequirementEffect extends RequirementEffect {
} else {
condition = baseCondition;
}
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
effect.init(source, game);
if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
otherwiseEffect.init(source, game);
}
initDone = true;
@ -80,10 +80,10 @@ public class ConditionalRequirementEffect extends RequirementEffect {
}
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(permanent, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(permanent, source, game);
}
if (!conditionState && effect.getDuration() == Duration.OneUse) {

View file

@ -63,10 +63,10 @@ public class ConditionalRestrictionEffect extends RestrictionEffect {
} else {
condition = baseCondition;
}
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
effect.init(source, game);
if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
otherwiseEffect.init(source, game);
}
initDone = true;
@ -79,10 +79,10 @@ public class ConditionalRestrictionEffect extends RestrictionEffect {
}
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
return effect.applies(permanent, source, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
return otherwiseEffect.applies(permanent, source, game);
}
if (effect.getDuration() == Duration.OneUse) {

View file

@ -51,7 +51,7 @@ public class DoIfClashWonEffect extends OneShotEffect {
executingEffect.setTargetPointer(new FixedTarget(opponent.getId()));
}
} else {
executingEffect.setTargetPointer(this.targetPointer);
executingEffect.setTargetPointer(this.getTargetPointer().copy());
}
if (executingEffect instanceof OneShotEffect) {
return executingEffect.apply(game, source);

View file

@ -111,7 +111,7 @@ public class DoIfCostPaid extends OneShotEffect {
private void applyEffects(Game game, Ability source, Effects effects) {
if (!effects.isEmpty()) {
for (Effect effect : effects) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
if (effect instanceof OneShotEffect) {
effect.apply(game, source);
} else {

View file

@ -104,7 +104,7 @@ public class DoUnlessAnyPlayerPaysEffect extends OneShotEffect {
// do the effects if nobody paid
if (doEffect) {
for (Effect effect : executingEffects) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
if (effect instanceof OneShotEffect) {
result &= effect.apply(game, source);
} else {

View file

@ -75,7 +75,7 @@ public class DoUnlessControllerPaysEffect extends OneShotEffect {
// do the effects if not paid
if (doEffect) {
for (Effect effect : executingEffects) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
if (effect instanceof OneShotEffect) {
result &= effect.apply(game, source);
} else {

View file

@ -110,7 +110,7 @@ public class DoUnlessTargetPlayerOrTargetsControllerPaysEffect extends OneShotEf
// do the effects if not paid
if (doEffect) {
for (Effect effect : executingEffects) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
if (effect instanceof OneShotEffect) {
result &= effect.apply(game, source);
} else {
@ -118,7 +118,7 @@ public class DoUnlessTargetPlayerOrTargetsControllerPaysEffect extends OneShotEf
}
}
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
otherwiseEffect.setTargetPointer(this.getTargetPointer().copy());
if (otherwiseEffect instanceof OneShotEffect) {
result &= otherwiseEffect.apply(game, source);
} else {

View file

@ -65,7 +65,7 @@ public class FlipCoinEffect extends OneShotEffect {
}
boolean result = true;
for (Effect effect : controller.flipCoin(source, game, true) ? executingEffectsWon : executingEffectsLost) {
effect.setTargetPointer(this.targetPointer);
effect.setTargetPointer(this.getTargetPointer().copy());
if (effect instanceof OneShotEffect) {
result &= effect.apply(game, source);
} else {