mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
refactor: improved target usage, replaced setNotTarget by withNotTarget
This commit is contained in:
parent
dbaa51f462
commit
4b3a19b4d5
385 changed files with 434 additions and 429 deletions
|
|
@ -28,7 +28,7 @@ public class ExileFromGraveCost extends CostImpl {
|
|||
private boolean setTargetPointer = false;
|
||||
|
||||
public ExileFromGraveCost(TargetCardInYourGraveyard target) {
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
this.addTarget(target);
|
||||
if (target.getMaxNumberOfTargets() > 1) {
|
||||
this.text = "exile "
|
||||
|
|
@ -46,19 +46,19 @@ public class ExileFromGraveCost extends CostImpl {
|
|||
}
|
||||
|
||||
public ExileFromGraveCost(TargetCardInYourGraveyard target, String text) {
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
this.addTarget(target);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public ExileFromGraveCost(TargetCardInASingleGraveyard target, String text) {
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
this.addTarget(target);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public ExileFromGraveCost(TargetCardInASingleGraveyard target) {
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
this.addTarget(target);
|
||||
this.text = "exile " + target.getDescription();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class ExileTargetCost extends CostImpl {
|
|||
List<Permanent> permanents = new ArrayList<>();
|
||||
|
||||
public ExileTargetCost(TargetControlledPermanent target) {
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
this.addTarget(target);
|
||||
this.text = "exile " + target.getDescription();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.UUID;
|
|||
public class ReturnToHandChosenControlledPermanentCost extends CostImpl {
|
||||
|
||||
public ReturnToHandChosenControlledPermanentCost(TargetControlledPermanent target) {
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
this.addTarget(target);
|
||||
if (target.getMaxNumberOfTargets() > 1 && target.getMaxNumberOfTargets() == target.getNumberOfTargets()) {
|
||||
this.text = "return " + CardUtil.numberToText(target.getMaxNumberOfTargets()) + ' '
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class SacrificeTargetCost extends CostImpl implements SacrificeCost {
|
|||
|
||||
public SacrificeTargetCost(TargetControlledPermanent target) {
|
||||
this.addTarget(target);
|
||||
target.setNotTarget(true); // sacrifice is never targeted
|
||||
target.withNotTarget(true); // sacrifice is never targeted
|
||||
target.setRequired(false); // can be canceled
|
||||
this.text = "sacrifice " + makeText(target);
|
||||
target.setTargetName(target.getTargetName() + " (to sacrifice)");
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class TapTargetCost extends CostImpl {
|
|||
|
||||
public TapTargetCost(TargetControlledPermanent target) {
|
||||
this.target = target;
|
||||
this.target.setNotTarget(true); // costs are never targeted
|
||||
this.target.withNotTarget(true); // costs are never targeted
|
||||
this.target.setRequired(false); // can be cancel by user
|
||||
this.text = "tap " + (target.getNumberOfTargets() > 1
|
||||
? CardUtil.numberToText(target.getMaxNumberOfTargets()) + ' ' + target.getTargetName()
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class UntapTargetCost extends CostImpl {
|
|||
this.text = makeText(target);
|
||||
|
||||
// It will never target as part of a cost
|
||||
this.target.setNotTarget(true);
|
||||
this.target.withNotTarget(true);
|
||||
}
|
||||
|
||||
protected UntapTargetCost(final UntapTargetCost cost) {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
|
|||
enchantCardInGraveyard = target instanceof TargetCardInGraveyard;
|
||||
if (target != null) {
|
||||
target.withChooseHint("to attach " + card.getName() + " to");
|
||||
target.setNotTarget(true); // always not target because this way it's not handled targeted
|
||||
target.withNotTarget(true); // always not target because this way it's not handled targeted
|
||||
target.clearChosen(); // necessary if e.g. aura is blinked multiple times
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class CipherEffect extends OneShotEffect {
|
|||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (target.canChoose(source.getControllerId(), source, game)
|
||||
&& controller.chooseUse(outcome, "Cipher this spell to a creature?", source, game)) {
|
||||
controller.chooseTarget(outcome, target, source, game);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class CopyPermanentEffect extends OneShotEffect {
|
|||
copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
} else {
|
||||
Target target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (target.canChoose(controller.getId(), source, game)) {
|
||||
controller.choose(Outcome.Copy, target, source, game);
|
||||
copyFromPermanent = game.getPermanent(target.getFirstTarget());
|
||||
|
|
@ -156,7 +156,7 @@ public class CopyPermanentEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
// select new target
|
||||
auraTarget.setNotTarget(true);
|
||||
auraTarget.withNotTarget(true);
|
||||
if (!controller.choose(auraOutcome, auraTarget, source, game)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class DrawDiscardOneOfThemEffect extends OneShotEffect {
|
|||
drawnCards.removeAll(initialHand);
|
||||
if (!drawnCards.isEmpty()) {
|
||||
TargetCard cardToDiscard = new TargetCard(Zone.HAND, new FilterCard("card to discard"));
|
||||
cardToDiscard.setNotTarget(true);
|
||||
cardToDiscard.withNotTarget(true);
|
||||
if (controller.choose(Outcome.Discard, drawnCards, cardToDiscard, source, game)) {
|
||||
Card card = controller.getHand().get(cardToDiscard.getFirstTarget(), game);
|
||||
if (card != null) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class EntersBattlefieldUnderControlOfOpponentOfChoiceEffect extends OneSh
|
|||
return false;
|
||||
}
|
||||
Target target = new TargetOpponent();
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (!controller.choose(Outcome.Benefit, target, source, game)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class ExileCardFromOwnGraveyardControllerEffect extends OneShotEffect {
|
|||
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(Math.min(
|
||||
amount, player.getGraveyard().size()
|
||||
), StaticFilters.FILTER_CARD);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (!player.chooseTarget(outcome, target, source, game)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class MeldEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
TargetPermanent target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
controller.choose(outcome, target, source, game);
|
||||
|
||||
Permanent meldWithPermanent = game.getPermanent(target.getFirstTarget());
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class PopulateEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
Target target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (!target.canChoose(source.getControllerId(), source, game)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class WishEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
TargetCard target = new TargetCard(Zone.ALL, filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (controller.choose(Outcome.Benefit, filteredCards, target, source, game)) {
|
||||
Card card = controller.getSideboard().get(target.getFirstTarget(), game);
|
||||
if (card == null && alsoFromExile) {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class DiscardCardYouChooseTargetEffect extends OneShotEffect {
|
|||
if (player.getHand().size() > numberToReveal) {
|
||||
TargetCard chosenCards = new TargetCard(numberToReveal, numberToReveal,
|
||||
Zone.HAND, new FilterCard("card in " + player.getName() + "'s hand"));
|
||||
chosenCards.setNotTarget(true);
|
||||
chosenCards.withNotTarget(true);
|
||||
if (chosenCards.canChoose(player.getId(), source, game)
|
||||
&& player.chooseTarget(Outcome.Discard, player.getHand(), chosenCards, source, game)) {
|
||||
if (!chosenCards.getTargets().isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class AmassEffect extends OneShotEffect {
|
|||
makeToken(subType).putOntoBattlefield(1, game, source);
|
||||
}
|
||||
Target target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
player.choose(Outcome.BoostCreature, target, source, game);
|
||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||
if (permanent == null) {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class EnlistEffect extends ReplacementEffectImpl {
|
|||
return false;
|
||||
}
|
||||
TargetPermanent target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
controller.choose(outcome, target, source, game);
|
||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||
if (permanent == null || !permanent.tap(source, game)) {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class HideawayExileEffect extends OneShotEffect {
|
|||
return true;
|
||||
}
|
||||
TargetCard target = new TargetCard(Zone.LIBRARY, filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
controller.choose(Outcome.Detriment, cards, target, source, game);
|
||||
Card card = cards.get(target.getFirstTarget(), game);
|
||||
if (card != null) {
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class SoulboundEntersSelfEffect extends OneShotEffect {
|
|||
Player controller = game.getPlayer(permanent.getControllerId());
|
||||
if (controller != null) {
|
||||
TargetControlledPermanent target = new TargetControlledPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (target.canChoose(controller.getId(), source, game)) {
|
||||
if (controller.choose(Outcome.Benefit, target, source, game)) {
|
||||
Permanent chosen = game.getPermanent(target.getFirstTarget());
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
// Paris mulligan - no longer used by default for commander
|
||||
// Player player = getPlayer(playerId);
|
||||
// TargetCardInHand target = new TargetCardInHand(1, player.getHand().size(), new FilterCard("card to mulligan"));
|
||||
// target.setNotTarget(true);
|
||||
// target.withNotTarget(true);
|
||||
// target.setRequired(false);
|
||||
// if (player.choose(Outcome.Exile, player.getHand(), target, this)) {
|
||||
// int numCards = target.getTargets().size();
|
||||
|
|
|
|||
|
|
@ -2688,7 +2688,7 @@ public abstract class GameImpl implements Game {
|
|||
continue;
|
||||
}
|
||||
Target targetLegendaryToKeep = new TargetPermanent(filterLegendName);
|
||||
targetLegendaryToKeep.setNotTarget(true);
|
||||
targetLegendaryToKeep.withNotTarget(true);
|
||||
targetLegendaryToKeep.setTargetName(legend.getName() + " to keep (Legendary Rule)?");
|
||||
controller.choose(Outcome.Benefit, targetLegendaryToKeep, null, this);
|
||||
for (Permanent dupLegend : getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) {
|
||||
|
|
|
|||
|
|
@ -1701,7 +1701,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
Player newProtector;
|
||||
if (opponents.size() > 1) {
|
||||
TargetPlayer target = new TargetPlayer(new FilterOpponent("protector for " + getName()));
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
target.setRequired(true);
|
||||
controller.choose(Outcome.Neutral, target, source, game);
|
||||
newProtector = game.getPlayer(target.getFirstTarget());
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class ReturnSengirNosferatuEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
Target target = new TargetCardInExile(filter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
if (!target.canChoose(source.getControllerId(), source, game)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
|
|||
}
|
||||
|
||||
// select new target
|
||||
auraTarget.setNotTarget(true);
|
||||
auraTarget.withNotTarget(true);
|
||||
if (!controller.choose(auraOutcome, auraTarget, source, game)) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2776,7 +2776,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
boolean casted = false;
|
||||
TargetCard targetCard = new TargetCard(0, 1, Zone.LIBRARY, StaticFilters.FILTER_CARD);
|
||||
targetCard.setTargetName("card to cast from library");
|
||||
targetCard.setNotTarget(true);
|
||||
targetCard.withNotTarget(true);
|
||||
while (!castableCards.isEmpty()) {
|
||||
targetCard.clearChosen();
|
||||
if (!targetPlayer.choose(Outcome.AIDontUseIt, new CardsImpl(castableCards), targetCard, source, game)) {
|
||||
|
|
@ -5194,7 +5194,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
if (choosing) {
|
||||
TargetPermanent target = new TargetControlledCreaturePermanent();
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
target.withChooseHint("to be your Ring-bearer");
|
||||
choose(Outcome.Neutral, target, null, game);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,12 +28,17 @@ public interface Target extends Serializable {
|
|||
boolean isNotTarget();
|
||||
|
||||
/**
|
||||
* controls if it will be checked, if the target can be targeted from source
|
||||
* Mark it as non target (e.g. card's rules do not contain a "target" word)
|
||||
* <p>
|
||||
* Non targeted abilities are unaffected by protection/hexproof and other target related effects
|
||||
* Non targeted spells can't be fizzled on resolve with invalid targets
|
||||
* Non targeted spells chooses targets on resolve, targeted spells chooses targets on activate
|
||||
* All costs must be non targeted
|
||||
*
|
||||
* @param notTarget true = do not check for protection, false = check for
|
||||
* protection
|
||||
* @param notTarget
|
||||
* @return
|
||||
*/
|
||||
void setNotTarget(boolean notTarget);
|
||||
Target withNotTarget(boolean notTarget);
|
||||
|
||||
// methods for targets
|
||||
boolean canChoose(UUID sourceControllerId, Ability source, Game game);
|
||||
|
|
@ -181,7 +186,6 @@ public interface Target extends Serializable {
|
|||
* - The minimum and maximum number of targets is the same (i.e. effect does not have "up to" in its name)
|
||||
* - The number of valid targets is equal to the number of targets still left to be specified
|
||||
*
|
||||
*
|
||||
* @param abilityControllerId
|
||||
* @param source
|
||||
* @param game
|
||||
|
|
|
|||
|
|
@ -546,8 +546,9 @@ public abstract class TargetImpl implements Target {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNotTarget(boolean notTarget) {
|
||||
public TargetImpl withNotTarget(boolean notTarget) {
|
||||
this.notTarget = notTarget;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class TargetCardInGraveyard extends TargetCard {
|
|||
|
||||
public TargetCardInGraveyard(int minNumTargets, int maxNumTargets, FilterCard filter, boolean notTarget) {
|
||||
super(minNumTargets, maxNumTargets, Zone.GRAVEYARD, filter);
|
||||
this.setNotTarget(notTarget);
|
||||
this.withNotTarget(notTarget);
|
||||
}
|
||||
|
||||
protected TargetCardInGraveyard(final TargetCardInGraveyard target) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class TargetCardInHand extends TargetCard {
|
|||
|
||||
public TargetCardInHand(int minNumTargets, int maxNumTargets, FilterCard filter) {
|
||||
super(minNumTargets, maxNumTargets, Zone.HAND, filter);
|
||||
setNotTarget(true);
|
||||
withNotTarget(true);
|
||||
}
|
||||
|
||||
protected TargetCardInHand(final TargetCardInHand target) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class TargetCardInLibrary extends TargetCard {
|
|||
// with a certain card type or color, that player isn't required to find some or all of those cards
|
||||
// even if they're present in that zone.
|
||||
this.setRequired(!filter.hasPredicates());
|
||||
this.setNotTarget(true);
|
||||
this.withNotTarget(true);
|
||||
this.librarySearchLimit = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class TargetCardInYourGraveyard extends TargetCard {
|
|||
|
||||
public TargetCardInYourGraveyard(int minNumTarget, int maxNumTargets, FilterCard filter, boolean notTarget) {
|
||||
super(minNumTarget, maxNumTargets, Zone.GRAVEYARD, filter);
|
||||
this.setNotTarget(notTarget);
|
||||
this.withNotTarget(notTarget);
|
||||
}
|
||||
|
||||
protected TargetCardInYourGraveyard(final TargetCardInYourGraveyard target) {
|
||||
|
|
|
|||
|
|
@ -1288,7 +1288,7 @@ public final class CardUtil {
|
|||
default:
|
||||
Cards castableCards = new CardsImpl(cardMap.keySet());
|
||||
TargetCard target = new TargetCard(0, 1, Zone.ALL, defaultFilter);
|
||||
target.setNotTarget(true);
|
||||
target.withNotTarget(true);
|
||||
player.choose(Outcome.PlayForFree, castableCards, target, source, game);
|
||||
cardToCast = castableCards.get(target.getFirstTarget(), game);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue