mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 05:52:06 -08:00
* GainAbilityTargetEffect - reworked to support static/dynamic targets, added support of spells (card + related permanent); * SpellCastControllerTriggeredAbility - now it can setup the target to a card instead a spell; * Added checks/errors on wrong ability adding code (example: if you add permanent's ability by game state instead permanent's method); * Tyvar Kell Emblem now use a standard code; * Test framework: added additional logs for some errors;
99 lines
3.6 KiB
Java
99 lines
3.6 KiB
Java
package mage.abilities.common;
|
|
|
|
import mage.abilities.TriggeredAbilityImpl;
|
|
import mage.abilities.effects.Effect;
|
|
import mage.constants.Zone;
|
|
import mage.filter.FilterSpell;
|
|
import mage.game.Game;
|
|
import mage.game.events.GameEvent;
|
|
import mage.game.stack.Spell;
|
|
import mage.target.targetpointer.FixedTarget;
|
|
|
|
/**
|
|
* @author North
|
|
*/
|
|
public class SpellCastControllerTriggeredAbility extends TriggeredAbilityImpl {
|
|
|
|
private static final FilterSpell spellCard = new FilterSpell("a spell");
|
|
|
|
protected FilterSpell filter;
|
|
protected String rule;
|
|
|
|
// The source SPELL that triggered the ability will be set as target to effect
|
|
protected boolean rememberSource = false;
|
|
// Use it if you want remember CARD instead spell
|
|
protected boolean rememberSourceAsCard = false;
|
|
|
|
public SpellCastControllerTriggeredAbility(Effect effect, boolean optional) {
|
|
this(Zone.BATTLEFIELD, effect, spellCard, optional, false);
|
|
}
|
|
|
|
public SpellCastControllerTriggeredAbility(Effect effect, FilterSpell filter, boolean optional) {
|
|
this(effect, filter, optional, false);
|
|
}
|
|
|
|
public SpellCastControllerTriggeredAbility(Effect effect, FilterSpell filter, boolean optional, String rule) {
|
|
this(effect, filter, optional, false);
|
|
this.rule = rule;
|
|
}
|
|
|
|
public SpellCastControllerTriggeredAbility(Effect effect, FilterSpell filter, boolean optional, boolean rememberSource) {
|
|
this(Zone.BATTLEFIELD, effect, filter, optional, rememberSource);
|
|
}
|
|
|
|
public SpellCastControllerTriggeredAbility(Zone zone, Effect effect, FilterSpell filter, boolean optional, boolean rememberSource) {
|
|
this(zone, effect, filter, optional, rememberSource, false);
|
|
}
|
|
|
|
public SpellCastControllerTriggeredAbility(Zone zone, Effect effect, FilterSpell filter, boolean optional, boolean rememberSource, boolean rememberSourceAsCard) {
|
|
super(zone, effect, optional);
|
|
this.filter = filter;
|
|
this.rememberSource = rememberSource;
|
|
this.rememberSourceAsCard = rememberSourceAsCard;
|
|
}
|
|
|
|
public SpellCastControllerTriggeredAbility(final SpellCastControllerTriggeredAbility ability) {
|
|
super(ability);
|
|
this.filter = ability.filter;
|
|
this.rule = ability.rule;
|
|
this.rememberSource = ability.rememberSource;
|
|
this.rememberSourceAsCard = ability.rememberSourceAsCard;
|
|
}
|
|
|
|
@Override
|
|
public boolean checkEventType(GameEvent event, Game game) {
|
|
return event.getType() == GameEvent.EventType.SPELL_CAST;
|
|
}
|
|
|
|
@Override
|
|
public boolean checkTrigger(GameEvent event, Game game) {
|
|
if (event.getPlayerId().equals(this.getControllerId())) {
|
|
Spell spell = game.getStack().getSpell(event.getTargetId());
|
|
if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) {
|
|
if (rememberSource) {
|
|
if (rememberSourceAsCard) {
|
|
this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getCard().getId(), game));
|
|
} else {
|
|
this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId(), game));
|
|
}
|
|
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public String getRule() {
|
|
if (rule != null && !rule.isEmpty()) {
|
|
return rule;
|
|
}
|
|
return "Whenever you cast " + filter.getMessage() + ", " + super.getRule();
|
|
}
|
|
|
|
@Override
|
|
public SpellCastControllerTriggeredAbility copy() {
|
|
return new SpellCastControllerTriggeredAbility(this);
|
|
}
|
|
}
|