Added early eventType check for ContinuousRuleModifying effects.

This commit is contained in:
LevelX2 2015-01-22 22:41:03 +01:00
parent 8ea8e77b88
commit dbffbad3cb
44 changed files with 343 additions and 188 deletions

View file

@ -28,29 +28,22 @@
package mage.sets.alarareborn;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.NameACardEffect;
import mage.cards.CardImpl;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
/**
*

View file

@ -137,14 +137,17 @@ class SpiritOfTheLabyrinthEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DRAW_CARD;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.DRAW_CARD) {
SpiritOfTheLabyrinthWatcher watcher = (SpiritOfTheLabyrinthWatcher) game.getState().getWatchers().get("DrewCard");
if (watcher != null && watcher.hasPlayerDrewCardThisTurn(event.getPlayerId())) {
return true;
}
}
return false;
}

View file

@ -65,7 +65,6 @@ public class AkromaAngelOfFury extends CardImpl {
this.supertype.add("Legendary");
this.subtype.add("Angel");
this.color.setRed(true);
this.power = new MageInt(6);
this.toughness = new MageInt(6);

View file

@ -106,9 +106,14 @@ class WakeTheDeadEffect extends ContinuousRuleModifiyingEffectImpl {
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType().equals(GameEvent.EventType.CAST_SPELL) && event.getSourceId().equals(source.getSourceId())) {
if (event.getSourceId().equals(source.getSourceId())) {
if (game.getPhase().getType().equals(TurnPhase.COMBAT)) {
return !game.getOpponents(source.getControllerId()).contains(game.getActivePlayerId());
}

View file

@ -29,11 +29,6 @@
package mage.sets.dragonsmaze;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
@ -41,21 +36,20 @@ import mage.abilities.SpellAbility;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.NameACardEffect;
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
import mage.abilities.keyword.FlashbackAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
/**
@ -83,7 +77,6 @@ public class CouncilOfTheAbsolute extends CardImpl {
// Spells with the chosen name cost 2 less for you to cast.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CouncilOfTheAbsoluteCostReductionEffect()));
}
public CouncilOfTheAbsolute (final CouncilOfTheAbsolute card) {
@ -127,9 +120,14 @@ class CouncilOfTheAbsoluteReplacementEffect extends ContinuousRuleModifiyingEffe
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.CAST_SPELL && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId());
if (object != null && object.getName().equals(game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY))) {
return true;

View file

@ -146,14 +146,17 @@ class RenderSilentEffect extends ContinuousRuleModifiyingEffectImpl {
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL ) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null && player.getId().equals(event.getPlayerId())) {
return true;
}
}
return false;
}

View file

@ -110,15 +110,19 @@ class MoonholdEffect extends ContinuousRuleModifiyingEffectImpl {
public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
return "You can't play land cards this turn (" + mageObject.getLogName() + ").";
return "you can't play land cards this turn (" + mageObject.getLogName() + ").";
}
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.PLAY_LAND;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.PLAY_LAND
&& event.getPlayerId().equals(source.getFirstTarget())) {
if (event.getPlayerId().equals(source.getFirstTarget())) {
return true;
}
return false;
@ -154,10 +158,14 @@ class MoonholdEffect2 extends ContinuousRuleModifiyingEffectImpl {
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL
&& event.getPlayerId().equals(source.getFirstTarget())) {
if (event.getPlayerId().equals(source.getFirstTarget())) {
Card card = game.getCard(event.getSourceId());
if (card != null && card.getCardType().contains(CardType.CREATURE)) {
return true;

View file

@ -79,9 +79,14 @@ class HewedStoneRetainersEffect extends ContinuousRuleModifiyingEffectImpl {
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL && event.getSourceId().equals(source.getSourceId())) {
if (event.getSourceId().equals(source.getSourceId())) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()) == 0) {
return true;

View file

@ -96,14 +96,17 @@ class WardscaleDragonRuleEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL ) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null && sourcePermanent.isAttacking()) {
return event.getPlayerId() == game.getCombat().getDefendingPlayerId(sourcePermanent.getId(), game);
}
}
return false;
}
}

View file

@ -81,7 +81,7 @@ class DamageCantBePreventedEffect extends ContinuousRuleModifiyingEffectImpl {
public DamageCantBePreventedEffect() {
super(Duration.EndOfTurn, Outcome.Benefit, false, false);
staticText = "Damage can't be prevented this turn";
staticText = "damage can't be prevented this turn";
}
public DamageCantBePreventedEffect(final DamageCantBePreventedEffect effect) {
@ -98,11 +98,13 @@ class DamageCantBePreventedEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.PREVENT_DAMAGE;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType().equals(GameEvent.EventType.PREVENT_DAMAGE)) {
return true;
}
return false;
}
}

View file

@ -182,9 +182,14 @@ class AngelicArbiterEffect2 extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.CAST_SPELL && game.getActivePlayerId().equals(event.getPlayerId()) && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
if (game.getActivePlayerId().equals(event.getPlayerId()) && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
AngelicArbiterWatcher2 watcher = (AngelicArbiterWatcher2) game.getState().getWatchers().get("PlayerAttacked");
if (watcher != null && watcher.hasPlayerAttackedThisTurn(event.getPlayerId())) {
return true;

View file

@ -97,9 +97,14 @@ class AggressiveMiningEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.PLAY_LAND;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getType().equals(GameEvent.EventType.PLAY_LAND) && event.getPlayerId().equals(source.getControllerId());
return event.getPlayerId().equals(source.getControllerId());
}
}

View file

@ -100,9 +100,13 @@ class HushwingGryffEffect extends ContinuousRuleModifiyingEffectImpl {
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent permanent = ((EntersTheBattlefieldEvent)event).getTarget();
if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) {
// Because replacement events have to be executed
@ -110,7 +114,6 @@ class HushwingGryffEffect extends ContinuousRuleModifiyingEffectImpl {
game.getContinuousEffects().replaceEvent(event, game);
return true;
}
}
return false;
}

View file

@ -110,9 +110,14 @@ class CeaseFireEffect extends ContinuousRuleModifiyingEffectImpl {
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL && event.getPlayerId().equals(source.getFirstTarget())) {
if (event.getPlayerId().equals(source.getFirstTarget())) {
MageObject object = game.getObject(event.getSourceId());
if (filter.match((Spell) object, game)) {
return true;

View file

@ -30,12 +30,12 @@ package mage.sets.returntoravnica;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.CantCounterAbility;
import mage.abilities.common.CantBeCounteredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.abilities.effects.common.CantCounterSourceEffect;
import mage.abilities.effects.common.CantBeCounteredSourceEffect;
import mage.abilities.effects.common.DestroyAllEffect;
import mage.cards.CardImpl;
import mage.constants.Zone;
@ -55,7 +55,7 @@ public class SupremeVerdict extends CardImpl {
this.color.setBlue(true);
// Supreme Verdict can't be countered.
Ability ability = new CantCounterAbility();
Ability ability = new CantBeCounteredAbility();
ability.setRuleAtTheTop(true);
this.addAbility(ability);

View file

@ -129,14 +129,17 @@ class XantidSwarmReplacementEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL ) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null && player.getId().equals(event.getPlayerId())) {
return true;
}
}
return false;
}
}

View file

@ -111,9 +111,14 @@ class VexingShusherCantCounterTargetEffect extends ContinuousRuleModifiyingEffec
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.COUNTER;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getType() == EventType.COUNTER && event.getTargetId().equals(targetPointer.getFirst(game, source));
return event.getTargetId().equals(targetPointer.getFirst(game, source));
}
}

View file

@ -144,15 +144,18 @@ class EtherswornCanonistReplacementEffect extends ContinuousRuleModifiyingEffect
return new EtherswornCanonistReplacementEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL) {
EtherswornCanonistWatcher watcher = (EtherswornCanonistWatcher)game.getState().getWatchers().get("EtherswornCanonistWatcher");
Card card = game.getCard(event.getSourceId());
if (card != null && !card.getCardType().contains(CardType.ARTIFACT) && watcher.castNonArtifactSpell(event.getPlayerId())) {
return true;
}
}
return false;
}

View file

@ -91,14 +91,17 @@ class IncinerateEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.REGENERATE;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.wasDamaged(event.getTargetId(), game);
}
}
return false;
}

View file

@ -28,19 +28,13 @@
package mage.sets.theros;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.keyword.ScryEffect;
import mage.abilities.effects.common.ruleModifying.CantRegenerateTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.DamagedByWatcher;

View file

@ -105,6 +105,13 @@ class ShipbreakerKrakenReplacementEffect extends ContinuousRuleModifiyingEffectI
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.LOST_CONTROL ||
event.getType() == GameEvent.EventType.ZONE_CHANGE ||
event.getType() == GameEvent.EventType.UNTAP;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// Source must be on the battlefield (it's neccessary to check here because if as response to the enter

View file

@ -105,9 +105,13 @@ class UnderworldCerberusEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TARGET;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.TARGET) {
Card targetCard = game.getCard(event.getTargetId());
StackObject stackObject = (StackObject) game.getStack().getStackObject(event.getSourceId());
if (targetCard != null && stackObject != null) {
@ -116,7 +120,6 @@ class UnderworldCerberusEffect extends ContinuousRuleModifiyingEffectImpl {
return true;
}
}
}
return false;
}
}

View file

@ -87,6 +87,11 @@ class AbyssalPersecutorCannotWinEffect extends ContinuousRuleModifiyingEffectImp
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.LOSES || event.getType() == EventType.WINS ;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if ((event.getType() == EventType.LOSES && game.getOpponents(source.getControllerId()).contains(event.getPlayerId()))

View file

@ -99,6 +99,16 @@ public class ConditionalContinuousRuleModifyingEffect extends ContinuousRuleModi
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
if (effect.checksEventType(event, game)) {
return true;
} else if (otherwiseEffect != null) {
return otherwiseEffect.checksEventType(event, game);
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!initDone) { // if simpleStaticAbility, init won't be called

View file

@ -646,6 +646,9 @@ public class ContinuousEffects implements Serializable {
*/
public boolean preventedByRuleModification(GameEvent event, Ability targetAbility, Game game, boolean checkPlayableMode) {
for (ContinuousRuleModifiyingEffect effect: continuousRuleModifyingEffects) {
if (!effect.checksEventType(event, game)) {
continue;
}
for (Ability sourceAbility : continuousRuleModifyingEffects.getAbility(effect.getId())) {
if (!(sourceAbility instanceof StaticAbility) || sourceAbility.isInUseableZone(game, null, false)) {
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {

View file

@ -38,6 +38,15 @@ import mage.game.events.GameEvent;
*/
public interface ContinuousRuleModifiyingEffect extends ContinuousEffect {
/**
* This check for the relevant events is called at first to prevent further actions if
* the current event is ignored from this effect
* @param event
* @param game
* @return
*/
boolean checksEventType(GameEvent event, Game game);
/**
*
* @param event the event to check if it may happen

View file

@ -78,6 +78,11 @@ public abstract class ContinuousRuleModifiyingEffectImpl extends ContinuousEffec
this.messageToGameLog = effect.messageToGameLog;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return true;

View file

@ -61,16 +61,19 @@ public class CantActivateAbilitiesAttachedEffect extends ContinuousRuleModifiyin
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ACTIVATE_ABILITY;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
if (event.getSourceId().equals(enchantment.getAttachedTo())) {
return true;
}
}
}
return false;
}
}

View file

@ -80,9 +80,13 @@ public class CantBeCounteredControlledEffect extends ContinuousRuleModifiyingEff
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.COUNTER;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.COUNTER) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.getControllerId().equals(source.getControllerId())
&& filterTarget.match(spell, game)) {
@ -95,7 +99,6 @@ public class CantBeCounteredControlledEffect extends ContinuousRuleModifiyingEff
}
}
}
}
return false;
}

View file

@ -74,16 +74,20 @@ public class CantBeCounteredSourceEffect extends ContinuousRuleModifiyingEffectI
return staticText;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.COUNTER;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.COUNTER) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null) {
if (spell.getSourceId().equals(source.getSourceId())) {
return true;
}
}
}
return false;
}

View file

@ -81,9 +81,13 @@ public class CantBeTargetedAllEffect extends ContinuousRuleModifiyingEffectImpl
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.TARGET;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.TARGET) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && filterTarget.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
if (filterSource == null) {
@ -96,7 +100,6 @@ public class CantBeTargetedAllEffect extends ContinuousRuleModifiyingEffectImpl
}
}
}
}
return false;
}

View file

@ -72,9 +72,13 @@ public class CantBeTargetedAttachedEffect extends ContinuousRuleModifiyingEffect
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.TARGET;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.TARGET) {
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment != null && event.getTargetId().equals(attachment.getAttachedTo())) {
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
@ -82,7 +86,6 @@ public class CantBeTargetedAttachedEffect extends ContinuousRuleModifiyingEffect
return true;
}
}
}
return false;
}

View file

@ -67,9 +67,14 @@ public class CantBeTargetedSourceEffect extends ContinuousRuleModifiyingEffectIm
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.TARGET;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.TARGET && event.getTargetId().equals(source.getSourceId())) {
if (event.getTargetId().equals(source.getSourceId())) {
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
if (sourceObject != null && filterSource.match(sourceObject, source.getControllerId(), game)) {
return true;

View file

@ -67,9 +67,14 @@ public class CantBeTargetedTargetEffect extends ContinuousRuleModifiyingEffectIm
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.TARGET;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.TARGET && getTargetPointer().getTargets(game, source).contains(event.getTargetId())) {
if (getTargetPointer().getTargets(game, source).contains(event.getTargetId())) {
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
if (sourceObject != null && filterSource.match(sourceObject, source.getControllerId(), game)) {
return true;

View file

@ -42,6 +42,10 @@ public class DontUntapInControllersNextUntapStepSourceEffect extends ContinuousR
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.UNTAP_STEP || event.getType() == GameEvent.EventType.UNTAP;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {

View file

@ -87,6 +87,11 @@ public class DontUntapInControllersNextUntapStepTargetEffect extends ContinuousR
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.UNTAP_STEP || event.getType() == EventType.UNTAP;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// the check for turn number is needed if multiple effects are added to prevent untap in next untap step of controller
@ -119,7 +124,6 @@ public class DontUntapInControllersNextUntapStepTargetEffect extends ContinuousR
}
validForTurnNum = game.getTurnNum();
}
}
if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == EventType.UNTAP) {

View file

@ -41,6 +41,7 @@ import static mage.constants.TargetController.YOU;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -77,9 +78,14 @@ public class DontUntapInControllersUntapStepAllEffect extends ContinuousRuleModi
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.UNTAP;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (GameEvent.EventType.UNTAP.equals(event.getType()) && PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
if (PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null) {
switch(targetController) {

View file

@ -45,10 +45,14 @@ public class DontUntapInControllersUntapStepEnchantedEffect extends ContinuousRu
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.UNTAP;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (GameEvent.EventType.UNTAP.equals(event.getType()) && PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
if (PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());

View file

@ -62,10 +62,14 @@ public class DontUntapInControllersUntapStepSourceEffect extends ContinuousRuleM
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.UNTAP;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP
&& event.getType() == EventType.UNTAP
&& event.getTargetId().equals(source.getSourceId())) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.getControllerId().equals(game.getActivePlayerId())) {

View file

@ -38,7 +38,6 @@ import mage.constants.Outcome;
import mage.constants.PhaseStep;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
/**
@ -75,9 +74,14 @@ public class DontUntapInControllersUntapStepTargetEffect extends ContinuousRuleM
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.UNTAP;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (GameEvent.EventType.UNTAP.equals(event.getType()) && PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
if (PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
for (UUID targetId : targetPointer.getTargets(game, source)) {
if (event.getTargetId().equals(targetId)) {
Permanent permanent = game.getPermanent(targetId);

View file

@ -109,10 +109,14 @@ class EpicReplacementEffect extends ContinuousRuleModifiyingEffectImpl {
return null;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL
&& source.getControllerId() == event.getPlayerId()) {
if (source.getControllerId() == event.getPlayerId()) {
MageObject object = game.getObject(event.getSourceId());
if (object != null) {
return true;

View file

@ -68,9 +68,13 @@ public class CantCastMoreThanOneSpellEffect extends ContinuousRuleModifiyingEffe
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL) {
switch (targetController) {
case YOU:
if (!event.getPlayerId().equals(source.getControllerId())) {
@ -97,7 +101,6 @@ public class CantCastMoreThanOneSpellEffect extends ContinuousRuleModifiyingEffe
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId())> 0) {
return true;
}
}
return false;
}

View file

@ -35,6 +35,7 @@ import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
/**
*
@ -62,14 +63,17 @@ public class CantRegenerateTargetEffect extends ContinuousRuleModifiyingEffectIm
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == EventType.REGENERATE;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (GameEvent.EventType.REGENERATE.equals(event.getType())) {
UUID targetId = getTargetPointer().getFirst(game, source);
if (targetId != null) {
return targetId.equals(event.getTargetId());
}
}
return false;
}
}

View file

@ -55,6 +55,11 @@ class SplitSecondEffect extends ContinuousRuleModifiyingEffectImpl {
return "You can't cast spells or activate abilities that aren't mana abilities (Split second).";
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL || event.getType() == GameEvent.EventType.ACTIVATE_ABILITY;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL) {