Implemented Single Combat

This commit is contained in:
Evan Kranzler 2019-04-05 22:28:54 -04:00
parent f56bdfe577
commit b18428f68f
2 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,128 @@
package mage.cards.s;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterCreatureOrPlaneswalkerPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.permanent.PermanentIdPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.target.TargetPermanent;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class SingleCombat extends CardImpl {
public SingleCombat(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{W}{W}");
// Each player chooses a creature or planeswalker they control, then sacrifices the rest. Players can't cast creature or planeswalker spells until the end of your next turn.
this.getSpellAbility().addEffect(new SingleCombatEffect());
this.getSpellAbility().addEffect(new SingleCombatRestrictionEffect());
}
private SingleCombat(final SingleCombat card) {
super(card);
}
@Override
public SingleCombat copy() {
return new SingleCombat(this);
}
}
class SingleCombatEffect extends OneShotEffect {
private static final FilterPermanent filter
= new FilterControlledPermanent("creature or planeswalker you control (to keep)");
static {
filter.add(Predicates.or(
new CardTypePredicate(CardType.CREATURE),
new CardTypePredicate(CardType.PLANESWALKER)
));
}
SingleCombatEffect() {
super(Outcome.Benefit);
staticText = "Each player chooses a creature or planeswalker they control, then sacrifices the rest.";
}
private SingleCombatEffect(final SingleCombatEffect effect) {
super(effect);
}
@Override
public SingleCombatEffect copy() {
return new SingleCombatEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent filterSac = new FilterCreatureOrPlaneswalkerPermanent();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
filterSac.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterSac, source.getControllerId(), game)) {
permanent.sacrifice(source.getSourceId(), game);
}
return true;
}
}
class SingleCombatRestrictionEffect extends ContinuousRuleModifyingEffectImpl {
SingleCombatRestrictionEffect() {
super(Duration.UntilYourNextTurn, Outcome.Neutral);
staticText = "Players can't cast creature or planeswalker spells until the end of your next turn.";
}
private SingleCombatRestrictionEffect(final SingleCombatRestrictionEffect effect) {
super(effect);
}
@Override
public SingleCombatRestrictionEffect copy() {
return new SingleCombatRestrictionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Card card = game.getCard(event.getSourceId());
return card != null && (card.isCreature() || card.isPlaneswalker());
}
}

View file

@ -116,6 +116,7 @@ public final class WarOfTheSpark extends ExpansionSet {
cards.add(new SetCardInfo("Role Reversal", 214, Rarity.RARE, mage.cards.r.RoleReversal.class));
cards.add(new SetCardInfo("Samut's Sprint", 142, Rarity.COMMON, mage.cards.s.SamutsSprint.class));
cards.add(new SetCardInfo("Samut, Tyrant Smasher", 235, Rarity.UNCOMMON, mage.cards.s.SamutTyrantSmasher.class));
cards.add(new SetCardInfo("Single Combat", 30, Rarity.RARE, mage.cards.s.SingleCombat.class));
cards.add(new SetCardInfo("Sorin's Thirst", 104, Rarity.COMMON, mage.cards.s.SorinsThirst.class));
cards.add(new SetCardInfo("Sorin, Vengeful Bloodlord", 217, Rarity.RARE, mage.cards.s.SorinVengefulBloodlord.class));
cards.add(new SetCardInfo("Spellgorger Weird", 145, Rarity.COMMON, mage.cards.s.SpellgorgerWeird.class));