* Some target pointer changes and code clean up.

This commit is contained in:
LevelX2 2020-07-26 00:16:14 +02:00
parent 142681c354
commit 7a78be8c6a
207 changed files with 531 additions and 358 deletions

View file

@ -77,7 +77,7 @@ public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
switch (setTargetPointer) {
case PERMANENT:
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(permanent.getId()));
effect.setTargetPointer(new FixedTarget(permanent, game));
}
break;
case PLAYER:

View file

@ -67,7 +67,7 @@ public class LeavesBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
for (Effect effect : this.getEffects()) {
switch (setTargetPointer) {
case PERMANENT:
effect.setTargetPointer(new FixedTarget(permanent.getId()));
effect.setTargetPointer(new FixedTarget(permanent, game));
break;
case PLAYER:
effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));

View file

@ -1,4 +1,3 @@
package mage.abilities.common;
import java.util.ArrayList;
@ -78,7 +77,7 @@ class LicidEffect extends OneShotEffect {
if (licid != null) {
UUID messageId = UUID.randomUUID();
LicidContinuousEffect effect = new LicidContinuousEffect(messageId);
effect.setTargetPointer(new FixedTarget(licid.getId()));
effect.setTargetPointer(new FixedTarget(licid, game));
game.addEffect(effect, source);
new AttachEffect(Outcome.Neutral).apply(game, source);
SpecialAction specialAction = new LicidSpecialAction(this.specialActionCost, messageId, licid.getIdName());

View file

@ -85,7 +85,7 @@ public class PutCardIntoGraveFromAnywhereAllTriggeredAbility extends TriggeredAb
switch (setTargetPointer) {
case CARD:
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game)));
effect.setTargetPointer(new FixedTarget(card, game));
}
break;
case PLAYER:

View file

@ -52,7 +52,7 @@ public class TapForManaAllTriggeredAbility extends TriggeredAbilityImpl {
}
switch(setTargetPointer) {
case PERMANENT:
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId()));
getEffects().get(0).setTargetPointer(new FixedTarget(permanent, game));
break;
case PLAYER:
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getControllerId()));

View file

@ -49,7 +49,7 @@ public class TapForManaAllTriggeredManaAbility extends TriggeredManaAbility {
effect.setValue("mana", mEvent.getMana());
switch(setTargetPointer) {
case PERMANENT:
effect.setTargetPointer(new FixedTarget(permanent.getId()));
effect.setTargetPointer(new FixedTarget(permanent, game));
break;
case PLAYER:
effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));

View file

@ -38,7 +38,7 @@ public class TapLandForManaAllTriggeredManaAbility extends TriggeredManaAbility
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (permanent != null && permanent.isLand()) {
if (setTargetPointer) {
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId()));
getEffects().get(0).setTargetPointer(new FixedTarget(permanent, game));
}
return true;
}

View file

@ -34,7 +34,7 @@ public class CastCardFromGraveyardThenExileItEffect extends OneShotEffect {
Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
if (card != null) {
ContinuousEffect effect = new CastCardFromGraveyardEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game)));
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
effect = new ExileReplacementEffect(card.getId());
game.addEffect(effect, source);

View file

@ -1,5 +1,9 @@
package mage.abilities.effects.common;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.Ability;
@ -20,11 +24,6 @@ import mage.util.CardUtil;
import mage.util.functions.ApplyToPermanent;
import mage.util.functions.EmptyApplyToPermanent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
/**
* @author LevelX2
*/
@ -71,8 +70,8 @@ public class CreateTokenCopyTargetEffect extends OneShotEffect {
}
/**
* @param playerId null the token is controlled/owned by the controller of
* the source ability
* @param playerId null the token is controlled/owned by the
* controller of the source ability
* @param additionalCardType the token gains this card type in addition
* @param hasHaste the token gains haste
* @param number number of tokens to put into play
@ -133,7 +132,7 @@ public class CreateTokenCopyTargetEffect extends OneShotEffect {
}
Permanent permanent;
if (useLKI) {
permanent = ((FixedTarget) getTargetPointer()).getTargetedPermanentOrLKIBattlefield(game);
permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
} else {
permanent = game.getPermanentOrLKIBattlefield(targetId);
}

View file

@ -49,7 +49,7 @@ public class DamageTargetControllerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (permanent != null) {
Player targetController = game.getPlayer(permanent.getControllerId());
if (targetController != null) {

View file

@ -1,5 +1,6 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.MageSingleton;
import mage.abilities.effects.AsThoughEffectImpl;
@ -17,8 +18,6 @@ import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author phulin
*/
@ -58,7 +57,7 @@ public class ExileAdventureSpellEffect extends OneShotEffect implements MageSing
Card parentCard = adventureSpellCard.getParentCard();
if (controller.moveCardsToExile(parentCard, source, game, true, exileId, "On an Adventure from " + controller.getName())) {
ContinuousEffect effect = new AdventureCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(parentCard.getId(), game));
effect.setTargetPointer(new FixedTarget(parentCard, game));
game.addEffect(effect, source);
}
}
@ -104,4 +103,4 @@ class AdventureCastFromExileEffect extends AsThoughEffectImpl {
}
return false;
}
}
}

View file

@ -39,7 +39,7 @@ public class InfoEffect extends OneShotEffect {
// add simple static info to permanent's rules
SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect(info));
GainAbilityTargetEffect gainAbilityEffect = new GainAbilityTargetEffect(ability, Duration.WhileOnBattlefield);
gainAbilityEffect.setTargetPointer(new FixedTarget(permanent.getId()));
gainAbilityEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(gainAbilityEffect, source);
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.keyword;
import mage.abilities.Ability;
@ -78,7 +77,7 @@ public class BolsterEffect extends OneShotEffect {
}
if (selectedCreature != null) {
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount.calculate(game, source, this)));
effect.setTargetPointer(new FixedTarget(selectedCreature.getId()));
effect.setTargetPointer(new FixedTarget(selectedCreature, game));
return effect.apply(game, source);
}
}

View file

@ -1,9 +1,10 @@
package mage.filter.predicate.other;
import mage.abilities.keyword.MorphAbility;
import mage.cards.Card;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
* @author North
@ -13,7 +14,15 @@ public enum FaceDownPredicate implements Predicate<Card> {
@Override
public boolean apply(Card input, Game game) {
return input.isFaceDown(game);
if (game.inCheckPlayableState()) {
// Check for cost reduction of possible face down spell to cast
if (input != null && !(input instanceof Permanent)) {
return input.getAbilities().containsClass(MorphAbility.class);
}
return false;
} else {
return input.isFaceDown(game);
}
}
@Override

View file

@ -93,7 +93,7 @@ class DarettiScrapSavantEffect extends OneShotEffect {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
Effect effect = new ReturnFromGraveyardToBattlefieldTargetEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game)));
effect.setTargetPointer(new FixedTarget(card, game));
effect.setText("return that card to the battlefield at the beginning of the next end step");
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(Zone.COMMAND, effect, TargetController.ANY), source);
return true;

View file

@ -53,7 +53,7 @@ class LilianaDefiantNecromancerEmblemEffect extends OneShotEffect {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null) {
Effect effect = new ReturnFromGraveyardToBattlefieldTargetEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game)));
effect.setTargetPointer(new FixedTarget(card, game));
effect.setText("return that card to the battlefield at the beginning of the next end step");
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(Zone.COMMAND, effect, TargetController.ANY), source);
return true;

View file

@ -93,7 +93,7 @@ class AgyremEffect extends OneShotEffect {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null) {
Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game)));
effect.setTargetPointer(new FixedTarget(card, game));
effect.setText("return that card to the battlefield under its owner's control at the beginning of the next end step");
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect, TargetController.ANY), source);
return true;
@ -123,7 +123,7 @@ class AgyremEffect2 extends OneShotEffect {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null) {
Effect effect = new ReturnFromGraveyardToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game)));
effect.setTargetPointer(new FixedTarget(card, game));
effect.setText("return it to its owner's hand at the beginning of the next end step");
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect, TargetController.ANY), source);
return true;

View file

@ -5,8 +5,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -94,4 +96,25 @@ public class FirstTargetPointer implements TargetPointer {
}
@Override
public Permanent getFirstTargetPermanentOrLKI(Game game, Ability source) {
UUID targetId = source.getFirstTarget();
Permanent permanent;
if (zoneChangeCounter.containsKey(targetId)) {
permanent = game.getPermanent(targetId);
if (permanent != null && permanent.getZoneChangeCounter(game) == zoneChangeCounter.get(targetId)) {
return permanent;
}
MageObject mageObject = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD, zoneChangeCounter.get(targetId));
if (mageObject instanceof Permanent) {
return (Permanent) mageObject;
}
} else {
permanent = game.getPermanent(targetId);
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(targetId, Zone.BATTLEFIELD);
}
}
return permanent;
}
}

View file

@ -1,5 +1,10 @@
package mage.target.targetpointer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.cards.Card;
@ -7,11 +12,6 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class FixedTarget implements TargetPointer {
private final UUID targetId;
@ -28,10 +28,11 @@ public class FixedTarget implements TargetPointer {
}
/**
* Target counter is immediatly initialised with current zoneChangeCounter value from the GameState
* Sets fixed the currect zone chnage counter
* Target counter is immediatly initialised with current zoneChangeCounter
* value from the GameState Sets fixed the currect zone chnage counter
*
* @param card used to get the objectId
* @param game
* @param game
*/
public FixedTarget(Card card, Game game) {
this.targetId = card.getId();
@ -129,18 +130,23 @@ public class FixedTarget implements TargetPointer {
return zoneChangeCounter;
}
public Permanent getTargetedPermanentOrLKIBattlefield(Game game) {
Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
if (permanent != null && permanent.getZoneChangeCounter(game) != zoneChangeCounter) {
permanent = (Permanent) game.getLastKnownInformation(targetId, Zone.BATTLEFIELD, zoneChangeCounter);
}
return permanent;
}
@Override
public FixedTarget getFixedTarget(Game game, Ability source) {
init(game, source);
return this;
}
@Override
public Permanent getFirstTargetPermanentOrLKI(Game game, Ability source) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && permanent.getZoneChangeCounter(game) == zoneChangeCounter) {
return permanent;
}
MageObject mageObject = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD, zoneChangeCounter);
if (mageObject instanceof Permanent) {
return (Permanent) mageObject;
}
return null;
}
}

View file

@ -5,17 +5,18 @@
*/
package mage.target.targetpointer;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.cards.Cards;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.cards.Cards;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
* @author LevelX2
@ -116,4 +117,34 @@ public class FixedTargets implements TargetPointer {
}
return null;
}
@Override
public Permanent getFirstTargetPermanentOrLKI(Game game, Ability source) {
UUID targetId = null;
int zoneChangeCounter = Integer.MIN_VALUE;
if (!targets.isEmpty()) {
MageObjectReference mor = targets.get(0);
targetId = mor.getSourceId();
zoneChangeCounter = mor.getZoneChangeCounter();
} else if (!targetsNotInitialized.isEmpty()) {
targetId = targetsNotInitialized.get(0);
}
if (targetId != null) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null
&& (zoneChangeCounter == Integer.MIN_VALUE || permanent.getZoneChangeCounter(game) == zoneChangeCounter)) {
return permanent;
}
MageObject mageObject;
if (zoneChangeCounter == Integer.MIN_VALUE) {
mageObject = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD);
} else {
mageObject = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD, zoneChangeCounter);
}
if (mageObject instanceof Permanent) {
return (Permanent) mageObject;
}
}
return null;
}
}

View file

@ -1,9 +1,12 @@
package mage.target.targetpointer;
import java.util.*;
import mage.MageObject;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
public class SecondTargetPointer implements TargetPointer {
@ -81,4 +84,30 @@ public class SecondTargetPointer implements TargetPointer {
}
return null;
}
@Override
public Permanent getFirstTargetPermanentOrLKI(Game game, Ability source) {
if (source.getTargets().size() > 1) {
Permanent permanent;
UUID targetId = source.getTargets().get(1).getFirstTarget();
if (zoneChangeCounter.containsKey(targetId)) {
permanent = game.getPermanent(targetId);
if (permanent != null && permanent.getZoneChangeCounter(game) == zoneChangeCounter.get(targetId)) {
return permanent;
}
MageObject mageObject = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD, zoneChangeCounter.get(targetId));
if (mageObject instanceof Permanent) {
return (Permanent) mageObject;
}
} else {
permanent = game.getPermanent(targetId);
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(targetId, Zone.BATTLEFIELD);
}
}
return permanent;
}
return null;
}
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.game.Game;
import mage.game.permanent.Permanent;
public interface TargetPointer extends Serializable {
@ -17,4 +18,20 @@ public interface TargetPointer extends Serializable {
TargetPointer copy();
FixedTarget getFixedTarget(Game game, Ability source);
/**
* Retrieves the permanent according the first targetId and
* zoneChangeCounter if set.<br>
* Retrieves also the LKI if the permanent is no longer onto the
* battlefield.<br>
* This should not be used for true targeted objects, because they are not
* retrieved using LKI (608.2b).<br>
* This is only used if the the target pointer is used to transfer
* information about a related permanent (often from triggered abilities).
*
* @param game
* @param source
* @return permanent
*/
Permanent getFirstTargetPermanentOrLKI(Game game, Ability source);
}

View file

@ -10,13 +10,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author Ludwig.Hirth
* @author LevelX2
*/
public class ThirdTargetPointer implements TargetPointer {
@ -95,4 +98,30 @@ public class ThirdTargetPointer implements TargetPointer {
return null;
}
@Override
public Permanent getFirstTargetPermanentOrLKI(Game game, Ability source) {
if (source.getTargets().size() > 2) {
Permanent permanent;
UUID targetId = source.getTargets().get(2).getFirstTarget();
if (zoneChangeCounter.containsKey(targetId)) {
permanent = game.getPermanent(targetId);
if (permanent != null && permanent.getZoneChangeCounter(game) == zoneChangeCounter.get(targetId)) {
return permanent;
}
MageObject mageObject = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD, zoneChangeCounter.get(targetId));
if (mageObject instanceof Permanent) {
return (Permanent) mageObject;
}
} else {
permanent = game.getPermanent(targetId);
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(targetId, Zone.BATTLEFIELD);
}
}
return permanent;
}
return null;
}
}