[STX] Implemented Dramatic Finale

This commit is contained in:
Evan Kranzler 2021-04-08 18:56:18 -04:00
parent 79b23d3292
commit 6ff3ca5c1e
7 changed files with 107 additions and 71 deletions

View file

@ -0,0 +1,54 @@
package mage.cards.d;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.continuous.BoostControlledEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.permanent.token.SilverquillToken;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class DramaticFinale extends CardImpl {
private static final FilterPermanent filter
= new FilterControlledCreaturePermanent("one or more nontoken creatures you control");
static {
filter.add(Predicates.not(TokenPredicate.instance));
}
public DramaticFinale(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{W/B}{W/B}{W/B}{W/B}");
// Creature tokens you control get +1/+1.
this.addAbility(new SimpleStaticAbility(new BoostControlledEffect(
1, 1, Duration.WhileOnBattlefield, StaticFilters.FILTER_CREATURE_TOKENS
)));
// Whenever one or more nontoken creatures you control die, create a 2/1 white and black Inkling creature token with flying. This ability triggers only once each turn.
this.addAbility(new DiesCreatureTriggeredAbility(
new CreateTokenEffect(new SilverquillToken()), false, filter
).setTriggersOnce(true));
}
private DramaticFinale(final DramaticFinale card) {
super(card);
}
@Override
public DramaticFinale copy() {
return new DramaticFinale(this);
}
}

View file

@ -5,7 +5,6 @@ import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldControlledTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.continuous.BoostControlledEffect;
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
@ -18,10 +17,7 @@ import mage.constants.SubType;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.token.ElfWarriorToken;
import mage.util.CardUtil;
import java.util.UUID;
@ -46,7 +42,9 @@ public final class ElvishWarmaster extends CardImpl {
this.toughness = new MageInt(2);
// Whenever one or more other Elves enters the battlefield under your control, create a 1/1 green Elf Warrior creature token. This ability triggers only once each turn.
this.addAbility(new ElvishWarmasterTriggeredAbility(new CreateTokenEffect(new ElfWarriorToken()), filter));
this.addAbility(new EntersBattlefieldControlledTriggeredAbility(
new CreateTokenEffect(new ElfWarriorToken()), filter
).setTriggersOnce(true));
// {5}{G}{G}: Elves you control get +2/+2 and gain deathtouch until end of turn.
Ability ability = new SimpleActivatedAbility(new BoostControlledEffect(
@ -67,42 +65,3 @@ public final class ElvishWarmaster extends CardImpl {
return new ElvishWarmaster(this);
}
}
class ElvishWarmasterTriggeredAbility extends EntersBattlefieldControlledTriggeredAbility {
public ElvishWarmasterTriggeredAbility(Effect effect, FilterPermanent filter) {
super(effect, filter);
}
public ElvishWarmasterTriggeredAbility(final ElvishWarmasterTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Integer lastTurnTriggered = (Integer) game.getState()
.getValue(CardUtil.getCardZoneString("lastTurnTriggered" + originalId, sourceId, game));
if (lastTurnTriggered != null && lastTurnTriggered == game.getTurnNum()) {
return false;
}
return super.checkTrigger(event, game);
}
@Override
public void trigger(Game game, UUID controllerId) {
game.getState().setValue(CardUtil
.getCardZoneString("lastTurnTriggered" + originalId, sourceId, game), game.getTurnNum());
super.trigger(game, controllerId);
}
@Override
public String getRule() {
return "Whenever one or more other Elves enter the battlefield under your control, " +
"create a 1/1 green Elf Warrior creature token. This ability triggers only once each turn.";
}
@Override
public ElvishWarmasterTriggeredAbility copy() {
return new ElvishWarmasterTriggeredAbility(this);
}
}

View file

@ -13,9 +13,7 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.PermanentToken;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
@ -49,6 +47,7 @@ class StonebindersFamiliarTriggeredAbility extends TriggeredAbilityImpl {
StonebindersFamiliarTriggeredAbility() {
super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance()));
this.setTriggersOnce(true);
}
private StonebindersFamiliarTriggeredAbility(final StonebindersFamiliarTriggeredAbility ability) {
@ -62,11 +61,6 @@ class StonebindersFamiliarTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (Objects.equals(game.getState().getValue(
CardUtil.getCardZoneString("lastTurnTriggered" + originalId, sourceId, game)
), game.getTurnNum())) {
return false;
}
ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
return zEvent.getToZone() == Zone.EXILED
&& isControlledBy(game.getActivePlayerId())
@ -74,14 +68,6 @@ class StonebindersFamiliarTriggeredAbility extends TriggeredAbilityImpl {
|| !(zEvent.getTarget() instanceof PermanentToken));
}
@Override
public void trigger(Game game, UUID controllerId) {
game.getState().setValue(CardUtil.getCardZoneString(
"lastTurnTriggered" + originalId, sourceId, game
), game.getTurnNum());
super.trigger(game, controllerId);
}
@Override
public String getRule() {
return "Whenever one or more cards are put into exile during your turn, " +

View file

@ -82,6 +82,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet {
cards.add(new SetCardInfo("Divide by Zero", 41, Rarity.UNCOMMON, mage.cards.d.DivideByZero.class));
cards.add(new SetCardInfo("Double Major", 179, Rarity.RARE, mage.cards.d.DoubleMajor.class));
cards.add(new SetCardInfo("Dragonsguard Elite", 127, Rarity.RARE, mage.cards.d.DragonsguardElite.class));
cards.add(new SetCardInfo("Dramatic Finale", 180, Rarity.RARE, mage.cards.d.DramaticFinale.class));
cards.add(new SetCardInfo("Dream Strix", 42, Rarity.RARE, mage.cards.d.DreamStrix.class));
cards.add(new SetCardInfo("Dueling Coach", 15, Rarity.UNCOMMON, mage.cards.d.DuelingCoach.class));
cards.add(new SetCardInfo("Eager First-Year", 16, Rarity.COMMON, mage.cards.e.EagerFirstYear.class));

View file

@ -2,8 +2,6 @@
package mage.abilities;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import mage.MageObject;
import mage.constants.Zone;
import mage.game.Game;
@ -13,6 +11,9 @@ import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import org.apache.log4j.Logger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author BetaSteward_at_googlemail.com
* <p>
@ -39,7 +40,7 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
}
public void checkStateTriggers(Game game) {
for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext();) {
for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext(); ) {
TriggeredAbility ability = it.next();
if (ability instanceof StateTriggeredAbility && ((StateTriggeredAbility) ability).canTrigger(game)) {
checkTrigger(ability, null, game);
@ -48,7 +49,7 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
}
public void checkTriggers(GameEvent event, Game game) {
for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext();) {
for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext(); ) {
TriggeredAbility ability = it.next();
if (ability.checkEventType(event, game)) {
checkTrigger(ability, event, game);
@ -90,7 +91,7 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
}
}
if (ability.checkTrigger(event, game)) {
if (ability.checkTrigger(event, game) && ability.checkTriggeredAlready(game)) {
NumberOfTriggersEvent numberOfTriggersEvent = new NumberOfTriggersEvent(ability, event);
if (!game.replaceEvent(numberOfTriggersEvent)) {
for (int i = 0; i < numberOfTriggersEvent.getAmount(); i++) {
@ -105,8 +106,8 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
/**
* Adds a by sourceId gained triggered ability
*
* @param ability - the gained ability
* @param sourceId - the source that assigned the ability
* @param ability - the gained ability
* @param sourceId - the source that assigned the ability
* @param attachedTo - the object that gained the ability
*/
public void add(TriggeredAbility ability, UUID sourceId, MageObject attachedTo) {

View file

@ -1,12 +1,12 @@
package mage.abilities;
import java.util.UUID;
import mage.game.Game;
import mage.game.events.GameEvent;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public interface TriggeredAbility extends Ability {
@ -37,6 +37,10 @@ public interface TriggeredAbility extends Ability {
*/
boolean checkTrigger(GameEvent event, Game game);
boolean checkTriggeredAlready(Game game);
TriggeredAbility setTriggersOnce(boolean triggersOnce);
boolean checkInterveningIfClause(Game game);
boolean isOptional();

View file

@ -8,13 +8,13 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.Locale;
import java.util.UUID;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
/**
* @author BetaSteward_at_googlemail.com
@ -23,6 +23,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
protected boolean optional;
protected boolean leavesTheBattlefieldTrigger;
private boolean triggersOnce = false;
public TriggeredAbilityImpl(Zone zone, Effect effect) {
this(zone, effect, false);
@ -48,16 +49,43 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
super(ability);
this.optional = ability.optional;
this.leavesTheBattlefieldTrigger = ability.leavesTheBattlefieldTrigger;
this.triggersOnce = ability.triggersOnce;
}
@Override
public void trigger(Game game, UUID controllerId) {
//20091005 - 603.4
if (checkInterveningIfClause(game)) {
addthing(game);
game.addTriggeredAbility(this);
}
}
private final void addthing(Game game) {
if (!triggersOnce) {
return;
}
game.getState().setValue(CardUtil.getCardZoneString(
"lastTurnTriggered" + originalId, sourceId, game
), game.getTurnNum());
}
@Override
public boolean checkTriggeredAlready(Game game) {
if (!triggersOnce) {
return true;
}
Integer lastTurnTriggered = (Integer) game.getState().getValue(
CardUtil.getCardZoneString("lastTurnTriggered" + originalId, sourceId, game)
);
return lastTurnTriggered == null || lastTurnTriggered != game.getTurnNum();
}
public TriggeredAbility setTriggersOnce(boolean triggersOnce) {
this.triggersOnce = triggersOnce;
return this;
}
@Override
public boolean checkInterveningIfClause(Game game) {
return true;
@ -130,6 +158,9 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
}
sb.append(superRule);
if (triggersOnce) {
sb.append(" This abilities triggers only once each turn.");
}
}
return sb.toString();
@ -247,7 +278,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
if (!source.hasSourceObjectAbility(game, sourceObject, event)) {
return false; // the permanent does currently not have or before it dies the ability so no trigger
}
// check now it is in graveyard (only if it is no token and was the target itself)
if (source.getSourceId().equals(event.getTargetId()) // source is also the target
&& !(sourceObject instanceof PermanentToken) // it's no token