mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
wip
This commit is contained in:
parent
5c93480f23
commit
e09a922e31
6 changed files with 274 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import static mage.constants.CardType.CREATURE;
|
||||
|
||||
public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public AttachedToCreatureTriggeredAbility(Effect effect, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
}
|
||||
|
||||
public AttachedToCreatureTriggeredAbility(final AttachedToCreatureTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.ATTACHED && event.getSourceId().equals(this.getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Permanent attachedPermanent = game.getPermanent(event.getTargetId());
|
||||
return attachedPermanent != null && attachedPermanent.getCardType().contains(CREATURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "As {this} becomes attached to a creature, " + super.getRule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttachedToCreatureTriggeredAbility copy() {
|
||||
return new AttachedToCreatureTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
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 LevelX2
|
||||
*/
|
||||
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