Merge pull request #2273 from Dilnu/master

Fix an edge case in the zones code
This commit is contained in:
Samuel Sandeen 2016-09-14 19:34:35 -04:00 committed by GitHub
commit 0c8ff64027
2 changed files with 27 additions and 6 deletions

View file

@ -90,7 +90,7 @@ class MindlessNullEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
return !(game.getBattlefield().countAll(filter, source.getControllerId(), game) == 0);
return game.getBattlefield().countAll(filter, source.getControllerId(), game) != 0;
}
@Override

View file

@ -82,7 +82,11 @@ public class ZonesHandler {
// Handle normal cases
ZoneChangeEvent event = info.event;
Zone toZone = event.getToZone();
Card targetCard = game.getCard(event.getTargetId());
Card targetCard = getTargetCard(game, event.getTargetId());
if (targetCard == null) {
// This should never happen.
return;
}
Cards cards;
if (targetCard instanceof MeldCard) {
cards = ((MeldCard) targetCard).getHalves();
@ -161,6 +165,19 @@ public class ZonesHandler {
}
}
private static Card getTargetCard(Game game, UUID targetId) {
if (game.getCard(targetId) != null) {
return game.getCard(targetId);
}
if (game.getMeldCard(targetId) != null) {
return game.getMeldCard(targetId);
}
if (game.getPermanent(targetId) != null) {
return game.getPermanent(targetId);
}
return null;
}
private static boolean maybeRemoveFromSourceZone(ZoneChangeInfo info, Game game) {
// Handle Unmelded Cards
if (info instanceof ZoneChangeInfo.Unmelded) {
@ -185,11 +202,12 @@ public class ZonesHandler {
}
// Handle all normal cases
ZoneChangeEvent event = info.event;
Card card = game.getCard(event.getTargetId());
boolean success = false;
Card card = getTargetCard(game, event.getTargetId());
if (card == null) {
return success;
// If we can't find the card we can't remove it.
return false;
}
boolean success = false;
if (info.faceDown) {
card.setFaceDown(true, game);
}
@ -200,6 +218,9 @@ public class ZonesHandler {
Permanent permanent;
if (card instanceof MeldCard) {
permanent = new PermanentMeld(card, event.getPlayerId(), game);
} else if (card instanceof Permanent) {
// This should never happen.
permanent = (Permanent) card;
} else {
permanent = new PermanentCard(card, event.getPlayerId(), game);
}
@ -239,7 +260,7 @@ public class ZonesHandler {
if (success) {
if (event.getToZone() == Zone.BATTLEFIELD && event.getTarget() != null) {
event.getTarget().updateZoneChangeCounter(game, event);
} else {
} else if (!(card instanceof Permanent)) {
card.updateZoneChangeCounter(game, event);
}
}