* Fixed some target pointer handling.

This commit is contained in:
LevelX2 2018-02-22 17:46:23 +01:00
parent 88dd301f82
commit c02c5a175b
14 changed files with 140 additions and 108 deletions

View file

@ -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);

View file

@ -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;