Skip to content

Commit

Permalink
reimplement "don't cause abilities to trigger" effects (#11242)
Browse files Browse the repository at this point in the history
  • Loading branch information
xenohedron authored Oct 2, 2023
1 parent 2ec532b commit bfbdf6b
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 289 deletions.
85 changes: 14 additions & 71 deletions Mage.Sets/src/mage/cards/e/EleshNornMotherOfMachines.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package mage.cards.e;

import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.abilities.effects.common.replacement.AdditionalTriggerControlledETBReplacementEffect;
import mage.abilities.effects.common.ruleModifying.DontCauseTriggerEffect;
import mage.abilities.keyword.VigilanceAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;

import java.util.UUID;

Expand All @@ -23,6 +21,11 @@
*/
public final class EleshNornMotherOfMachines extends CardImpl {

private static final FilterPermanent filter = new FilterPermanent("permanents your opponents control");
static {
filter.add(TargetController.OPPONENT.getControllerPredicate());
}

public EleshNornMotherOfMachines(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{W}");

Expand All @@ -35,74 +38,14 @@ public EleshNornMotherOfMachines(UUID ownerId, CardSetInfo setInfo) {
this.addAbility(VigilanceAbility.getInstance());

// If a permanent entering the battlefield causes a triggered ability of a permanent you control to trigger, that ability triggers an additional time.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AdditionalTriggerControlledETBReplacementEffect()));
this.addAbility(new SimpleStaticAbility(new AdditionalTriggerControlledETBReplacementEffect()));

// Permanents entering the battlefield don't cause abilities of permanents your opponents control to trigger.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new EleshNornMotherOfMachinesPreventionEffect()));
this.addAbility(new SimpleStaticAbility(new DontCauseTriggerEffect(StaticFilters.FILTER_PERMANENTS, false, filter)));
}

private EleshNornMotherOfMachines(final EleshNornMotherOfMachines card) {super(card);}

@Override
public EleshNornMotherOfMachines copy() {return new EleshNornMotherOfMachines(this);}
}

class EleshNornMotherOfMachinesPreventionEffect extends ContinuousRuleModifyingEffectImpl {

EleshNornMotherOfMachinesPreventionEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment, false, false);
staticText = "Permanents entering the battlefield don't cause abilities of permanents your opponents control to trigger";
}

private EleshNornMotherOfMachinesPreventionEffect(final EleshNornMotherOfMachinesPreventionEffect effect) {
super(effect);
}

@Override
public EleshNornMotherOfMachinesPreventionEffect copy() {return new EleshNornMotherOfMachinesPreventionEffect(this);}

@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) {
Ability ability = (Ability) getValue("targetAbility");
if(ability == null || ability.getAbilityType() != AbilityType.TRIGGERED) {
return false;
}

// Elesh Norn should not prevent Bloodghast trigger from the graveyard.
// This checks that the trigger originated from a permanent.
if(ability.getSourcePermanentOrLKI(game) == null) {
return false;
}

if (!game.getOpponents(source.getControllerId()).contains(ability.getControllerId())) {
return false;
}

Permanent enteringPermanent = ((EntersTheBattlefieldEvent) event).getTarget();
if (enteringPermanent == null) {
return false;
}

return (((TriggeredAbility) ability).checkTrigger(event, game));
}

@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject enteringObject = game.getObject(event.getSourceId());
MageObject sourceObject = game.getObject(source);
Ability ability = (Ability) getValue("targetAbility");
if (enteringObject != null && sourceObject != null && ability != null) {
MageObject abilitObject = game.getObject(ability.getSourceId());
if (abilitObject != null) {
return sourceObject.getLogName() + " prevented ability of " + abilitObject.getLogName()
+ " to trigger for " + enteringObject.getLogName() + " entering the battlefield.";
}
}
return null;
}
}
83 changes: 5 additions & 78 deletions Mage.Sets/src/mage/cards/h/Hushbringer.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package mage.cards.h;

import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.abilities.effects.common.ruleModifying.DontCauseTriggerEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.LifelinkAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.filter.StaticFilters;

import java.util.UUID;

Expand All @@ -38,7 +32,7 @@ public Hushbringer(UUID ownerId, CardSetInfo setInfo) {
this.addAbility(LifelinkAbility.getInstance());

// Creatures entering the battlefield or dying don't cause abilities to trigger.
this.addAbility(new SimpleStaticAbility(new HushbringerEffect()));
this.addAbility(new SimpleStaticAbility(new DontCauseTriggerEffect(StaticFilters.FILTER_PERMANENT_CREATURES, true, null)));
}

private Hushbringer(final Hushbringer card) {
Expand All @@ -50,70 +44,3 @@ public Hushbringer copy() {
return new Hushbringer(this);
}
}

class HushbringerEffect extends ContinuousRuleModifyingEffectImpl {

HushbringerEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment, false, false);
staticText = "Creatures entering the battlefield or dying don't cause abilities to trigger";
}

private HushbringerEffect(final HushbringerEffect effect) {
super(effect);
}

@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
|| event.getType() == GameEvent.EventType.ZONE_CHANGE;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Ability ability = (Ability) getValue("targetAbility");
if (ability == null || ability.getAbilityType() != AbilityType.TRIGGERED) {
return false;
}
Permanent permanent;
switch (event.getType()) {
case ENTERS_THE_BATTLEFIELD:
permanent = ((EntersTheBattlefieldEvent) event).getTarget();
break;
case ZONE_CHANGE:
ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
if (!zEvent.isDiesEvent()) {
return false;
}
permanent = zEvent.getTarget();
break;
default:
return false;
}

if (permanent == null || !permanent.isCreature(game)) {
return false;
}
return (((TriggeredAbility) ability).checkTrigger(event, game));
}

@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject enteringObject = game.getObject(event.getSourceId());
MageObject sourceObject = game.getObject(source);
Ability ability = (Ability) getValue("targetAbility");
if (enteringObject == null || sourceObject == null || ability == null) {
return null;
}
MageObject abilitObject = game.getObject(ability.getSourceId());
if (abilitObject == null) {
return null;
}
return sourceObject.getLogName() + " prevented ability of "
+ abilitObject.getLogName() + " from triggering.";
}

@Override
public HushbringerEffect copy() {
return new HushbringerEffect(this);
}
}
69 changes: 4 additions & 65 deletions Mage.Sets/src/mage/cards/h/HushwingGryff.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@

package mage.cards.h;

import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.abilities.effects.common.ruleModifying.DontCauseTriggerEffect;
import mage.abilities.keyword.FlashAbility;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.AbilityType;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;

import java.util.UUID;

/**
*
Expand All @@ -41,7 +30,7 @@ public HushwingGryff(UUID ownerId, CardSetInfo setInfo) {
// Flying
this.addAbility(FlyingAbility.getInstance());
// Creatures entering the battlefield don't cause abilities to trigger.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new HushwingGryffEffect()));
this.addAbility(new SimpleStaticAbility(new DontCauseTriggerEffect()));
}

private HushwingGryff(final HushwingGryff card) {
Expand All @@ -53,53 +42,3 @@ public HushwingGryff copy() {
return new HushwingGryff(this);
}
}

class HushwingGryffEffect extends ContinuousRuleModifyingEffectImpl {

HushwingGryffEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment, false, true);
staticText = "Creatures entering the battlefield don't cause abilities to trigger";
}

private HushwingGryffEffect(final HushwingGryffEffect effect) {
super(effect);
}

@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject enteringObject = game.getObject(event.getSourceId());
MageObject sourceObject = game.getObject(source);
Ability ability = (Ability) getValue("targetAbility");
if (enteringObject != null && sourceObject != null && ability != null) {
MageObject abilitObject = game.getObject(ability.getSourceId());
if (abilitObject != null) {
return sourceObject.getLogName() + " prevented ability of " + abilitObject.getLogName()
+ " to trigger for " + enteringObject.getLogName() + " entering the battlefield.";
}
}
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) {
Ability ability = (Ability) getValue("targetAbility");
if (ability != null && ability.getAbilityType() == AbilityType.TRIGGERED) {
Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget();
if (permanent != null && permanent.isCreature(game)) {
return (((TriggeredAbility) ability).checkTrigger(event, game));
}
}
return false;
}

@Override
public HushwingGryffEffect copy() {
return new HushwingGryffEffect(this);
}

}
5 changes: 2 additions & 3 deletions Mage.Sets/src/mage/cards/t/TocatliHonorGuard.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

package mage.cards.t;

import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.ruleModifying.DontCauseTriggerEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Zone;

/**
*
Expand All @@ -25,7 +24,7 @@ public TocatliHonorGuard(UUID ownerId, CardSetInfo setInfo) {
this.toughness = new MageInt(3);

// Creatures entering the battlefield don't cause abilities to trigger.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new TorporOrbEffect()));
this.addAbility(new SimpleStaticAbility(new DontCauseTriggerEffect()));
}

private TocatliHonorGuard(final TocatliHonorGuard card) {
Expand Down
Loading

0 comments on commit bfbdf6b

Please sign in to comment.