diff --git a/Mage.Sets/src/mage/cards/d/DargoTheShipwrecker.java b/Mage.Sets/src/mage/cards/d/DargoTheShipwrecker.java new file mode 100644 index 00000000000..4a7a5840582 --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DargoTheShipwrecker.java @@ -0,0 +1,142 @@ +package mage.cards.d; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.Cost; +import mage.abilities.costs.common.SacrificeXTargetCost; +import mage.abilities.effects.common.cost.CostModificationEffectImpl; +import mage.abilities.keyword.PartnerAbility; +import mage.abilities.keyword.TrampleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.util.CardUtil; +import mage.watchers.Watcher; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class DargoTheShipwrecker extends CardImpl { + + public DargoTheShipwrecker(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{6}{R}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.GIANT); + this.subtype.add(SubType.PIRATE); + this.power = new MageInt(7); + this.toughness = new MageInt(5); + + // As an additional cost to cast this spell, you may sacrifice any number of artifacts and/or creatures. This spell costs {2} less to cast for each permanent sacrificed this way and {2} less to cast for each other artifact or creature you've sacrificed this turn. + Cost cost = new SacrificeXTargetCost(StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT_OR_CREATURE); + cost.setText("As an additional cost to cast this spell, " + + "you may sacrifice any number of artifacts and/or creatures. " + + "This spell costs {2} less to cast for each permanent sacrificed this way " + + "and {2} less to cast for each other artifact or creature you've sacrificed this turn."); + this.getSpellAbility().addCost(cost); + Ability ability = new SimpleStaticAbility(Zone.ALL, new DargoTheShipwreckerEffect()); + ability.setRuleVisible(false); + this.addAbility(ability, new DargoTheShipwreckerWatcher()); + + // Trample + this.addAbility(TrampleAbility.getInstance()); + + // Partner + this.addAbility(PartnerAbility.getInstance()); + } + + private DargoTheShipwrecker(final DargoTheShipwrecker card) { + super(card); + } + + @Override + public DargoTheShipwrecker copy() { + return new DargoTheShipwrecker(this); + } +} + +class DargoTheShipwreckerEffect extends CostModificationEffectImpl { + + public DargoTheShipwreckerEffect() { + super(Duration.WhileOnStack, Outcome.Benefit, CostModificationType.REDUCE_COST); + } + + public DargoTheShipwreckerEffect(final DargoTheShipwreckerEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source, Ability abilityToModify) { + SpellAbility spellAbility = (SpellAbility) abilityToModify; + int reduction = 0; + for (Cost cost : spellAbility.getCosts()) { + if (!(cost instanceof SacrificeXTargetCost)) { + continue; + } + if (game.inCheckPlayableState()) { + // allows to cast in getPlayable + reduction += ((SacrificeXTargetCost) cost).getMaxValue(spellAbility, game); + } else { + // real cast + reduction += ((SacrificeXTargetCost) cost).getAmount(); + } + break; + } + DargoTheShipwreckerWatcher watcher = game.getState().getWatcher(DargoTheShipwreckerWatcher.class); + if (watcher != null) { + reduction += watcher.getSacCount(source.getControllerId()); + } + CardUtil.adjustCost(spellAbility, reduction * 2); + return true; + } + + @Override + public boolean applies(Ability abilityToModify, Ability source, Game game) { + return abilityToModify instanceof SpellAbility && abilityToModify.getSourceId().equals(source.getSourceId()); + } + + @Override + public DargoTheShipwreckerEffect copy() { + return new DargoTheShipwreckerEffect(this); + } +} + +class DargoTheShipwreckerWatcher extends Watcher { + + private static final Map sacMap = new HashMap<>(); + + DargoTheShipwreckerWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() != GameEvent.EventType.SACRIFICED_PERMANENT) { + return; + } + Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId()); + if (permanent != null && (permanent.isCreature() || permanent.isArtifact())) { + sacMap.compute(event.getPlayerId(), (u, i) -> i == null ? 1 : Integer.sum(i, 1)); + } + } + + @Override + public void reset() { + sacMap.clear(); + super.reset(); + } + + int getSacCount(UUID playerId) { + return sacMap.getOrDefault(playerId, 0); + } +} diff --git a/Mage.Sets/src/mage/sets/CommanderLegends.java b/Mage.Sets/src/mage/sets/CommanderLegends.java index 133f8b5fb17..bf21bad554f 100644 --- a/Mage.Sets/src/mage/sets/CommanderLegends.java +++ b/Mage.Sets/src/mage/sets/CommanderLegends.java @@ -126,6 +126,7 @@ public final class CommanderLegends extends ExpansionSet { cards.add(new SetCardInfo("Cultivate", 424, Rarity.COMMON, mage.cards.c.Cultivate.class)); cards.add(new SetCardInfo("Cuombajj Witches", 116, Rarity.UNCOMMON, mage.cards.c.CuombajjWitches.class)); cards.add(new SetCardInfo("Danitha Capashen, Paragon", 370, Rarity.UNCOMMON, mage.cards.d.DanithaCapashenParagon.class)); + cards.add(new SetCardInfo("Dargo, the Shipwrecker", 172, Rarity.UNCOMMON, mage.cards.d.DargoTheShipwrecker.class)); cards.add(new SetCardInfo("Daring Saboteur", 64, Rarity.UNCOMMON, mage.cards.d.DaringSaboteur.class)); cards.add(new SetCardInfo("Dawn Charm", 371, Rarity.UNCOMMON, mage.cards.d.DawnCharm.class)); cards.add(new SetCardInfo("Dawnglade Regent", 222, Rarity.RARE, mage.cards.d.DawngladeRegent.class));