[SNC] Implemented shield counter mechanic (#8830)

* [SNC] Implemented shield counter mechanic

* Rework shield counter to be a global replacement effect

* Add unit test for shield counter

Co-authored-by: Evan Kranzler <theelk801@gmail.com>
This commit is contained in:
Daniel Bomar 2022-04-14 08:43:12 -05:00 committed by GitHub
parent a1c62f4495
commit 63239fe8e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 134 additions and 1 deletions

View file

@ -0,0 +1,61 @@
package mage.abilities.effects.keyword;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
*
* @author weirddan455
*/
public class ShieldCounterEffect extends ReplacementEffectImpl {
public ShieldCounterEffect() {
super(Duration.Custom, Outcome.PreventDamage);
this.staticText = "If it would be dealt damage or destroyed, remove a shield counter from it instead";
}
private ShieldCounterEffect(final ShieldCounterEffect effect) {
super(effect);
}
@Override
public ShieldCounterEffect copy() {
return new ShieldCounterEffect(this);
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.getCounters(game).getCount(CounterType.SHIELD) > 0) {
permanent.removeCounters(CounterType.SHIELD.getName(), 1, source, game);
if (!game.isSimulation()) {
game.informPlayers("Removed a shield counter from " + permanent.getLogName());
}
return true;
}
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
switch (event.getType()) {
case DAMAGE_PERMANENT:
case DESTROY_PERMANENT:
return true;
default:
return false;
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
return permanent != null && permanent.getCounters(game).getCount(CounterType.SHIELD) > 0;
}
}

View file

@ -14,6 +14,7 @@ import mage.abilities.effects.Effect;
import mage.abilities.effects.PreventionEffectData;
import mage.abilities.effects.common.CopyEffect;
import mage.abilities.effects.common.InfoEffect;
import mage.abilities.effects.keyword.ShieldCounterEffect;
import mage.abilities.keyword.*;
import mage.abilities.mana.DelayedTriggeredManaAbility;
import mage.abilities.mana.TriggeredManaAbility;
@ -1130,6 +1131,9 @@ public abstract class GameImpl implements Game {
return;
}
// Apply shield counter mechanic from SNC
state.addAbility(new SimpleStaticAbility(Zone.ALL, new ShieldCounterEffect()), null);
// Handle companions
Map<Player, Card> playerCompanionMap = new HashMap<>();
for (Player player : state.getPlayers().values()) {