forked from External/mage
* Fixed some target pointer handling.
This commit is contained in:
parent
88dd301f82
commit
c02c5a175b
14 changed files with 140 additions and 108 deletions
|
|
@ -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