Implemented Ghired's Belligerence

This commit is contained in:
Evan Kranzler 2019-08-02 14:43:23 -04:00
parent 4ee1a4e0cc
commit 2fab876d05
3 changed files with 140 additions and 13 deletions

View file

@ -0,0 +1,113 @@
package mage.cards.g;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DamageMultiEffect;
import mage.abilities.effects.common.PopulateEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.target.common.TargetCreaturePermanentAmount;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class GhiredsBelligerence extends CardImpl {
public GhiredsBelligerence(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{R}{R}");
// Ghired's Belligerence deals X damage divided as you choose among any number of target creatures. Whenever a creature dealt damage this way dies this turn, populate.
this.getSpellAbility().addEffect(new GhiredsBelligerenceEffect());
this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(ManacostVariableValue.instance));
}
private GhiredsBelligerence(final GhiredsBelligerence card) {
super(card);
}
@Override
public GhiredsBelligerence copy() {
return new GhiredsBelligerence(this);
}
}
class GhiredsBelligerenceEffect extends OneShotEffect {
private static final DamageMultiEffect effect = new DamageMultiEffect(ManacostVariableValue.instance);
GhiredsBelligerenceEffect() {
super(Outcome.Benefit);
staticText = "{this} deals X damage divided as you choose among any number of target creatures. " +
"Whenever a creature dealt damage this way dies this turn, populate.";
}
private GhiredsBelligerenceEffect(final GhiredsBelligerenceEffect effect) {
super(effect);
}
@Override
public GhiredsBelligerenceEffect copy() {
return new GhiredsBelligerenceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
if (!effect.apply(game, source)) {
return false;
}
if (effect.getDamagedSet().isEmpty()) {
return true;
}
game.addDelayedTriggeredAbility(new GhiredsBelligerenceDelayedTriggeredAbility(effect.getDamagedSet()), source);
return true;
}
}
class GhiredsBelligerenceDelayedTriggeredAbility extends DelayedTriggeredAbility {
private final Set<MageObjectReference> referenceSet = new HashSet<>();
GhiredsBelligerenceDelayedTriggeredAbility(Set<MageObjectReference> referenceSet) {
super(new PopulateEffect(), Duration.EndOfTurn, false);
this.referenceSet.addAll(referenceSet);
}
private GhiredsBelligerenceDelayedTriggeredAbility(final GhiredsBelligerenceDelayedTriggeredAbility ability) {
super(ability);
this.referenceSet.addAll(ability.referenceSet);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
return zEvent.isDiesEvent() && referenceSet.stream().anyMatch(mor -> mor.refersTo(zEvent.getTarget(), game));
}
@Override
public GhiredsBelligerenceDelayedTriggeredAbility copy() {
return new GhiredsBelligerenceDelayedTriggeredAbility(this);
}
@Override
public String getRule() {
return "Whenever a creature dealt damage this way dies this turn, populate.";
}
}

View file

@ -21,6 +21,7 @@ public final class Commander2019Edition extends ExpansionSet {
this.hasBasicLands = false; // temporary fix for tests
cards.add(new SetCardInfo("Anje's Ravager", 22, Rarity.RARE, mage.cards.a.AnjesRavager.class));
cards.add(new SetCardInfo("Ghired's Belligerence", 25, Rarity.RARE, mage.cards.g.GhiredsBelligerence.class));
cards.add(new SetCardInfo("Ghired, Conclave Exile", 42, Rarity.MYTHIC, mage.cards.g.GhiredConclaveExile.class));
cards.add(new SetCardInfo("Kadena's Silencer", 8, Rarity.RARE, mage.cards.k.KadenasSilencer.class));
cards.add(new SetCardInfo("Kadena, Slinking Sorcerer", 45, Rarity.MYTHIC, mage.cards.k.KadenaSlinkingSorcerer.class));

View file

@ -1,6 +1,6 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
@ -12,14 +12,18 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DamageMultiEffect extends OneShotEffect {
protected DynamicValue amount;
private String sourceName = "{source}";
private final Set<MageObjectReference> damagedSet = new HashSet<>();
public DamageMultiEffect(int amount) {
this(new StaticValue(amount));
@ -37,6 +41,7 @@ public class DamageMultiEffect extends OneShotEffect {
public DamageMultiEffect(final DamageMultiEffect effect) {
super(effect);
this.damagedSet.addAll(effect.damagedSet);
this.amount = effect.amount;
this.sourceName = effect.sourceName;
}
@ -48,17 +53,21 @@ public class DamageMultiEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
if (!source.getTargets().isEmpty()) {
Target multiTarget = source.getTargets().get(0);
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true);
} else {
Player player = game.getPlayer(target);
if (player != null) {
player.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true);
}
this.damagedSet.clear();
if (source.getTargets().isEmpty()) {
return true;
}
Target multiTarget = source.getTargets().get(0);
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
if (permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true) > 0) {
damagedSet.add(new MageObjectReference(permanent, game));
} ;
} else {
Player player = game.getPlayer(target);
if (player != null) {
player.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true);
}
}
}
@ -83,4 +92,8 @@ public class DamageMultiEffect extends OneShotEffect {
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
public Set<MageObjectReference> getDamagedSet() {
return damagedSet;
}
}