mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
-don't static import static filters
-use existing choose color and gain protection from color attached effects -update naming and add null check for AttachedToCreatureSourceTriggeredAbility
This commit is contained in:
parent
c567fc2ee1
commit
874ff7179f
5 changed files with 25 additions and 86 deletions
|
|
@ -13,19 +13,21 @@ import static mage.constants.CardType.CREATURE;
|
|||
*
|
||||
* @author htrajan
|
||||
*/
|
||||
public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl {
|
||||
public class AttachedToCreatureSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public AttachedToCreatureTriggeredAbility(Effect effect, boolean optional) {
|
||||
public AttachedToCreatureSourceTriggeredAbility(Effect effect, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
}
|
||||
|
||||
public AttachedToCreatureTriggeredAbility(final AttachedToCreatureTriggeredAbility ability) {
|
||||
public AttachedToCreatureSourceTriggeredAbility(final AttachedToCreatureSourceTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.ATTACHED && event.getSourceId().equals(this.getSourceId());
|
||||
return event.getType() == GameEvent.EventType.ATTACHED
|
||||
&& event.getSourceId() != null
|
||||
&& event.getSourceId().equals(this.getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -40,7 +42,7 @@ public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AttachedToCreatureTriggeredAbility copy() {
|
||||
return new AttachedToCreatureTriggeredAbility(this);
|
||||
public AttachedToCreatureSourceTriggeredAbility copy() {
|
||||
return new AttachedToCreatureSourceTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.keyword.ProtectionAbility;
|
||||
import mage.choices.ChoiceColor;
|
||||
import mage.constants.Duration;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author htrajan
|
||||
*/
|
||||
public class GainProtectionFromColorAttachedEffect extends GainAbilitySourceEffect {
|
||||
|
||||
FilterCard protectionFilter;
|
||||
|
||||
public GainProtectionFromColorAttachedEffect(Duration duration) {
|
||||
super(new ProtectionAbility(new FilterCard()), duration);
|
||||
protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter();
|
||||
}
|
||||
|
||||
public GainProtectionFromColorAttachedEffect(final GainProtectionFromColorAttachedEffect effect) {
|
||||
super(effect);
|
||||
this.protectionFilter = effect.protectionFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GainProtectionFromColorAttachedEffect copy() {
|
||||
return new GainProtectionFromColorAttachedEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
super.init(source, game);
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
ChoiceColor colorChoice = new ChoiceColor(true);
|
||||
colorChoice.setMessage("Choose color for protection ability");
|
||||
if (controller.choose(outcome, colorChoice, game)) {
|
||||
game.informPlayers("Choosen color: " + colorChoice.getColor());
|
||||
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
|
||||
protectionFilter.setMessage(colorChoice.getChoice());
|
||||
((ProtectionAbility) ability).setFilter(protectionFilter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null && permanent.getAttachedTo() != null) {
|
||||
Permanent attachedPermanent = game.getPermanent(permanent.getAttachedTo());
|
||||
attachedPermanent.addAbility(ability, source.getSourceId(), game);
|
||||
} else {
|
||||
// the source permanent is no longer on the battlefield, or it is not attached -- effect can be discarded
|
||||
discard();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue