* Fixed AddCardTypeSourceEffect with limited duration and object reference was applied on wrong objects (fixes failing crew test).

This commit is contained in:
LevelX2 2017-02-25 12:05:43 +01:00
parent 624e69ecb6
commit f06ee144f7

View file

@ -27,6 +27,7 @@
*/
package mage.abilities.effects.common.continuous;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
@ -59,16 +60,27 @@ public class AddCardTypeSourceEffect extends ContinuousEffectImpl {
this.addedCardType = effect.addedCardType;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (Duration.Custom.equals(this.duration) || this.duration.toString().startsWith("End")) {
affectedObjectList.add(new MageObjectReference(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()), game));
if (affectedObjectList.isEmpty()) {
this.discard();
}
}
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (permanent != null
&& (affectedObjectList.isEmpty() || affectedObjectList.contains(new MageObjectReference(permanent, game)))) {
if (!permanent.getCardType().contains(addedCardType)) {
permanent.getCardType().add(addedCardType);
}
return true;
}
else if (this.getDuration().equals(Duration.Custom)) {
} else if (this.getDuration().equals(Duration.Custom)) {
this.discard();
}
return false;