mirror of
https://github.com/correl/mage.git
synced 2025-01-13 03:00:10 +00:00
Use getSourceObjectIfItStillExists.
This commit is contained in:
parent
847df3eeb8
commit
a089b70d64
2 changed files with 18 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
@ -43,25 +44,23 @@ public class PutOnLibrarySourceEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean result = false;
|
||||
switch (game.getState().getZone(source.getSourceId())) {
|
||||
case BATTLEFIELD:
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null && source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game)) {
|
||||
result |= permanent.moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop);
|
||||
}
|
||||
case GRAVEYARD:
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null && source.getSourceObjectZoneChangeCounter() == card.getZoneChangeCounter(game)) {
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (player.getGraveyard().contains(card.getId())) {
|
||||
player.getGraveyard().remove(card);
|
||||
result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
|
||||
if (sourceObject == null) {
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
if (sourceObject instanceof Permanent) {
|
||||
((Permanent) sourceObject).moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop);
|
||||
return true;
|
||||
} else if (sourceObject instanceof Card && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (player.getGraveyard().contains(sourceObject.getId())) {
|
||||
player.getGraveyard().remove(((Card) sourceObject));
|
||||
((Card) sourceObject).moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,7 +34,7 @@ public class RevealAndShuffleIntoLibrarySourceEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (sourceObject != null && controller != null) {
|
||||
Player owner = null;
|
||||
|
|
Loading…
Reference in a new issue