mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
* Fixed some target pointer handling.
This commit is contained in:
parent
88dd301f82
commit
c02c5a175b
14 changed files with 140 additions and 108 deletions
|
|
@ -45,6 +45,7 @@ import mage.constants.Zone;
|
|||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.Targets;
|
||||
|
|
@ -535,6 +536,17 @@ public interface Ability extends Controllable, Serializable {
|
|||
*/
|
||||
MageObject getSourceObjectIfItStillExists(Game game);
|
||||
|
||||
/**
|
||||
* Returns the permanent that actually existed while the ability triggerd or
|
||||
* an ability was activated only if it has not changed zone meanwhile. If
|
||||
* not set yet, the current permanent if one exists will be retrieved from
|
||||
* the game and returned.
|
||||
*
|
||||
* @param game
|
||||
* @return
|
||||
*/
|
||||
Permanent getSourcePermanentIfItStillExists(Game game);
|
||||
|
||||
String getTargetDescription(Targets targets, Game game);
|
||||
|
||||
void setCanFizzle(boolean canFizzle);
|
||||
|
|
|
|||
|
|
@ -1211,6 +1211,19 @@ public abstract class AbilityImpl implements Ability {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permanent getSourcePermanentIfItStillExists(Game game) {
|
||||
if (sourceObject == null) {
|
||||
setSourceObject(game.getObject(getSourceId()), game);
|
||||
}
|
||||
if (sourceObject instanceof Permanent) {
|
||||
if (game.getState().getZoneChangeCounter(getSourceId()) == getSourceObjectZoneChangeCounter()) {
|
||||
return (Permanent) sourceObject;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceObjectZoneChangeCounter() {
|
||||
return sourceObjectZoneChangeCounter;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import mage.constants.*;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.Targets;
|
||||
|
|
@ -529,12 +530,17 @@ public class StackAbility extends StackObjImpl implements Ability {
|
|||
|
||||
@Override
|
||||
public MageObject getSourceObject(Game game) {
|
||||
return game.getBaseObject(getSourceId());
|
||||
return this.ability.getSourceObject(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MageObject getSourceObjectIfItStillExists(Game game) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
return this.ability.getSourceObjectIfItStillExists(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permanent getSourcePermanentIfItStillExists(Game game) {
|
||||
return this.ability.getSourcePermanentIfItStillExists(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class FirstTargetPointer implements TargetPointer {
|
|||
Card card = game.getCard(target);
|
||||
if (card != null) {
|
||||
this.zoneChangeCounter.put(target, card.getZoneChangeCounter(game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,9 +66,9 @@ public class FirstTargetPointer implements TargetPointer {
|
|||
if (zoneChangeCounter.containsKey(targetId)) {
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null && zoneChangeCounter.containsKey(targetId)
|
||||
&& card.getZoneChangeCounter(game) != zoneChangeCounter.get(targetId)) {
|
||||
// because if dies trigger has to trigger as permanent has already moved zone, we have to check if target was on the battlefield immed. before
|
||||
// but no longer if new permanent is already on the battlefield
|
||||
&& card.getZoneChangeCounter(game) != zoneChangeCounter.get(targetId)) {
|
||||
// because if dies trigger has to trigger as permanent has already moved zone, we have to check if target was on the battlefield immed. before
|
||||
// but no longer if new permanent is already on the battlefield
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
|
||||
if (permanent == null || permanent.getZoneChangeCounter(game) != zoneChangeCounter.get(targetId)) {
|
||||
return null;
|
||||
|
|
@ -82,4 +82,16 @@ public class FirstTargetPointer implements TargetPointer {
|
|||
public TargetPointer copy() {
|
||||
return new FirstTargetPointer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FixedTarget getFixedTarget(Game game, Ability source) {
|
||||
this.init(game, source);
|
||||
UUID firstId = getFirst(game, source);
|
||||
if (firstId != null) {
|
||||
return new FixedTarget(firstId, game.getState().getZoneChangeCounter(firstId));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
package mage.target.targetpointer;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
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;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
public class FixedTarget implements TargetPointer {
|
||||
|
||||
|
|
@ -65,10 +64,7 @@ public class FixedTarget implements TargetPointer {
|
|||
public void init(Game game, Ability source) {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null) {
|
||||
this.zoneChangeCounter = card.getZoneChangeCounter(game);
|
||||
}
|
||||
this.zoneChangeCounter = game.getState().getZoneChangeCounter(targetId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -121,4 +117,10 @@ public class FixedTarget implements TargetPointer {
|
|||
return permanent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FixedTarget getFixedTarget(Game game, Ability source) {
|
||||
init(game, source);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package mage.target.targetpointer;
|
||||
|
||||
import java.util.*;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SecondTargetPointer implements TargetPointer {
|
||||
|
||||
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
|
||||
|
|
@ -59,7 +58,7 @@ public class SecondTargetPointer implements TargetPointer {
|
|||
if (zoneChangeCounter.containsKey(targetId)) {
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null && zoneChangeCounter.containsKey(targetId)
|
||||
&& card.getZoneChangeCounter(game) != zoneChangeCounter.get(targetId)) {
|
||||
&& card.getZoneChangeCounter(game) != zoneChangeCounter.get(targetId)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -72,4 +71,15 @@ public class SecondTargetPointer implements TargetPointer {
|
|||
public TargetPointer copy() {
|
||||
return new SecondTargetPointer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FixedTarget getFixedTarget(Game game, Ability source) {
|
||||
this.init(game, source);
|
||||
UUID firstId = getFirst(game, source);
|
||||
if (firstId != null) {
|
||||
return new FixedTarget(firstId, game.getState().getZoneChangeCounter(firstId));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,14 @@ import mage.abilities.Ability;
|
|||
import mage.game.Game;
|
||||
|
||||
public interface TargetPointer extends Serializable {
|
||||
|
||||
void init(Game game, Ability source);
|
||||
|
||||
List<UUID> getTargets(Game game, Ability source);
|
||||
|
||||
UUID getFirst(Game game, Ability source);
|
||||
|
||||
TargetPointer copy();
|
||||
|
||||
FixedTarget getFixedTarget(Game game, Ability source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,4 +84,15 @@ public class ThirdTargetPointer implements TargetPointer {
|
|||
public TargetPointer copy() {
|
||||
return new ThirdTargetPointer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FixedTarget getFixedTarget(Game game, Ability source) {
|
||||
this.init(game, source);
|
||||
UUID firstId = getFirst(game, source);
|
||||
if (firstId != null) {
|
||||
return new FixedTarget(firstId, game.getState().getZoneChangeCounter(firstId));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue