[SNC] Implemented Ledger Shredder

This commit is contained in:
Evan Kranzler 2022-04-07 19:58:37 -04:00
parent 495a0ab776
commit 75bd6cf906
6 changed files with 142 additions and 25 deletions

View file

@ -6,6 +6,7 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.hint.Hint;
import mage.abilities.hint.ValueHint;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -17,19 +18,28 @@ import mage.watchers.common.CastSpellLastTurnWatcher;
public class CastSecondSpellTriggeredAbility extends TriggeredAbilityImpl {
private static final Hint hint = new ValueHint("Spells you cast this turn", SpellCastValue.instance);
private final TargetController targetController;
public CastSecondSpellTriggeredAbility(Effect effect) {
this(Zone.BATTLEFIELD, effect, false);
this(effect, TargetController.YOU);
}
public CastSecondSpellTriggeredAbility(Zone zone, Effect effect, boolean optional) {
public CastSecondSpellTriggeredAbility(Effect effect, TargetController targetController) {
this(Zone.BATTLEFIELD, effect, targetController, false);
}
public CastSecondSpellTriggeredAbility(Zone zone, Effect effect, TargetController targetController, boolean optional) {
super(zone, effect, optional);
this.addWatcher(new CastSpellLastTurnWatcher());
this.addHint(hint);
if (targetController == TargetController.YOU) {
this.addHint(hint);
}
this.targetController = targetController;
}
private CastSecondSpellTriggeredAbility(final CastSecondSpellTriggeredAbility ability) {
super(ability);
this.targetController = ability.targetController;
}
@Override
@ -39,8 +49,21 @@ public class CastSecondSpellTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!isControlledBy(event.getPlayerId())) {
return false;
switch (targetController) {
case YOU:
if (!isControlledBy(event.getPlayerId())) {
return false;
}
break;
case OPPONENT:
if (!game.getOpponents(getControllerId()).contains(event.getPlayerId())) {
return false;
}
break;
case ANY:
break;
default:
throw new IllegalArgumentException("TargetController " + targetController + " not supported");
}
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
return watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 2;
@ -48,7 +71,16 @@ public class CastSecondSpellTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getTriggerPhrase() {
return "Whenever you cast your second spell each turn, " ;
switch (targetController) {
case YOU:
return "Whenever you cast your second spell each turn, ";
case OPPONENT:
return "Whenever an opponent casts their second spell each turn, ";
case ANY:
return "Whenever a player casts their second spell each turn, ";
default:
throw new IllegalArgumentException("TargetController " + targetController + " not supported");
}
}
@Override

View file

@ -0,0 +1,58 @@
package mage.abilities.effects.keyword;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* @author TheElk801
*/
public class ConniveSourceEffect extends OneShotEffect {
public ConniveSourceEffect() {
super(Outcome.Benefit);
staticText = "{this} connives. <i>(Draw a card, then discard a card. " +
"If you discarded a nonland card, put a +1/+1 counter on this creature.)</i>";
}
private ConniveSourceEffect(final ConniveSourceEffect effect) {
super(effect);
}
@Override
public ConniveSourceEffect copy() {
return new ConniveSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent == null) {
return false;
}
return permanent != null && connive(permanent, 1, source, game);
}
public static boolean connive(Permanent permanent, int amount, Ability source, Game game) {
if (amount < 1) {
return false;
}
Player player = game.getPlayer(permanent.getControllerId());
if (player == null) {
return false;
}
player.drawCards(amount, source, game);
int counters = player
.discard(amount, false, false, source, game)
.count(StaticFilters.FILTER_CARDS_NON_LAND, game);
if (counters > 0) {
permanent.addCounters(CounterType.P1P1.createInstance(counters), source, game);
}
return true;
}
}

View file

@ -6,11 +6,8 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* @author TheElk801
@ -44,22 +41,8 @@ public class ConniveTargetEffect extends OneShotEffect {
if (permanent == null) {
return false;
}
Player player = game.getPlayer(permanent.getControllerId());
if (player == null) {
return false;
}
int amount = xValue.calculate(game, source, this);
if (amount < 1) {
return false;
}
player.drawCards(amount, source, game);
int counters = player.discard(
amount, false, false, source, game
).count(StaticFilters.FILTER_CARDS_NON_LAND, game);
if (counters > 0) {
permanent.addCounters(CounterType.P1P1.createInstance(counters), source, game);
}
return true;
return amount > 0 && ConniveSourceEffect.connive(permanent, amount, source, game);
}
@Override