forked from External/mage
Fix for #4137
This commit is contained in:
parent
afd532146d
commit
e2dfa61fa6
1 changed files with 66 additions and 5 deletions
|
|
@ -29,27 +29,36 @@ package mage.cards.p;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.costs.common.UntapSourceCost;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.keyword.ProtectionAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.choices.ChoiceColor;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterObject;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*
|
||||
* @author jeffwadsworth & L_J
|
||||
*/
|
||||
public class PaleWayfarer extends CardImpl {
|
||||
|
||||
|
|
@ -91,8 +100,8 @@ class PaleWayfarerEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent targetCreature = game.getPermanent(source.getFirstTarget());
|
||||
public boolean apply(Game game, Ability source
|
||||
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (targetCreature != null) {
|
||||
Player player = game.getPlayer(targetCreature.getControllerId());
|
||||
if (player != null) {
|
||||
|
|
@ -100,6 +109,13 @@ class PaleWayfarerEffect extends OneShotEffect {
|
|||
if (player.choose(Outcome.Neutral, colorChoice, game)) {
|
||||
game.informPlayers(targetCreature.getName() + ": " + player.getLogName() + " has chosen " + colorChoice.getChoice());
|
||||
game.getState().setValue(targetCreature.getId() + "_color", colorChoice.getColor());
|
||||
|
||||
ObjectColor protectColor = (ObjectColor) game.getState().getValue(targetCreature.getId() + "_color");
|
||||
if (protectColor != null) {
|
||||
ContinuousEffect effect = new ProtectionChosenColorTargetEffect();
|
||||
effect.setTargetPointer(new FixedTarget(targetCreature, game));
|
||||
game.addEffect(effect, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -110,4 +126,49 @@ class PaleWayfarerEffect extends OneShotEffect {
|
|||
public PaleWayfarerEffect copy() {
|
||||
return new PaleWayfarerEffect(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ProtectionChosenColorTargetEffect extends ContinuousEffectImpl {
|
||||
|
||||
protected ObjectColor chosenColor;
|
||||
protected ProtectionAbility protectionAbility;
|
||||
|
||||
public ProtectionChosenColorTargetEffect() {
|
||||
super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||
}
|
||||
|
||||
public ProtectionChosenColorTargetEffect(final ProtectionChosenColorTargetEffect effect) {
|
||||
super(effect);
|
||||
if (effect.chosenColor != null) {
|
||||
this.chosenColor = effect.chosenColor.copy();
|
||||
}
|
||||
if (effect.protectionAbility != null) {
|
||||
this.protectionAbility = effect.protectionAbility.copy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectionChosenColorTargetEffect copy() {
|
||||
return new ProtectionChosenColorTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
|
||||
if (color != null && (protectionAbility == null || !color.equals(chosenColor))) {
|
||||
chosenColor = color;
|
||||
FilterObject protectionFilter = new FilterObject(chosenColor.getDescription());
|
||||
protectionFilter.add(new ColorPredicate(chosenColor));
|
||||
protectionAbility = new ProtectionAbility(protectionFilter);
|
||||
}
|
||||
if (protectionAbility != null) {
|
||||
permanent.addAbility(protectionAbility, source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue