[ZNR] Implemented Angel of Destiny

This commit is contained in:
Evan Kranzler 2020-09-11 21:34:30 -04:00
parent c837898958
commit 91b9e123ab
2 changed files with 174 additions and 0 deletions

View file

@ -0,0 +1,173 @@
package mage.cards.a;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfEndStepTriggeredAbility;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.DoubleStrikeAbility;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.watchers.Watcher;
import java.util.*;
/**
* @author TheElk801
*/
public final class AngelOfDestiny extends CardImpl {
public AngelOfDestiny(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}{W}");
this.subtype.add(SubType.ANGEL);
this.subtype.add(SubType.CLERIC);
this.power = new MageInt(2);
this.toughness = new MageInt(6);
// Flying
this.addAbility(FlyingAbility.getInstance());
// Double strike
this.addAbility(DoubleStrikeAbility.getInstance());
// Whenever a creature you control deals combat damage to a player, you and that player each gain that much life.
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(
new AngelOfDestinyGainLifeEffect(), false, true
));
// At the beginning of your end step, if you have at least 15 life more than your starting life total, each player Angel of Destiny attacked this turn loses the game.
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
new BeginningOfEndStepTriggeredAbility(
new AngelOfDestinyLoseEffect(), TargetController.YOU, false
), AngelOfDestinyCondition.instance, "At the beginning of your end step, " +
"if you have at least 15 life more than your starting life total, " +
"each player {this} attacked this turn loses the game."
), new AngelOfDestinyWatcher());
}
private AngelOfDestiny(final AngelOfDestiny card) {
super(card);
}
@Override
public AngelOfDestiny copy() {
return new AngelOfDestiny(this);
}
}
enum AngelOfDestinyCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
return player != null && player.getLife() >= game.getLife() + 15;
}
}
class AngelOfDestinyGainLifeEffect extends OneShotEffect {
AngelOfDestinyGainLifeEffect() {
super(Outcome.Benefit);
staticText = "you and that player each gain that much life";
}
private AngelOfDestinyGainLifeEffect(final AngelOfDestinyGainLifeEffect effect) {
super(effect);
}
@Override
public AngelOfDestinyGainLifeEffect copy() {
return new AngelOfDestinyGainLifeEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(targetPointer.getFirst(game, source));
int damage = (int) getValue("damage");
if (controller != null) {
controller.gainLife(damage, game, source);
}
if (player != null) {
player.gainLife(damage, game, source);
}
return true;
}
}
class AngelOfDestinyLoseEffect extends OneShotEffect {
AngelOfDestinyLoseEffect() {
super(Outcome.Benefit);
}
private AngelOfDestinyLoseEffect(final AngelOfDestinyLoseEffect effect) {
super(effect);
}
@Override
public AngelOfDestinyLoseEffect copy() {
return new AngelOfDestinyLoseEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
AngelOfDestinyWatcher watcher = game.getState().getWatcher(AngelOfDestinyWatcher.class);
if (watcher == null) {
return false;
}
Set<UUID> playerSet = watcher.getPlayers(new MageObjectReference(
source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game
));
if (playerSet == null) {
return false;
}
for (UUID playerId : playerSet) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
player.lost(game);
}
return true;
}
}
class AngelOfDestinyWatcher extends Watcher {
private final Map<MageObjectReference, Set<UUID>> map = new HashMap<>();
AngelOfDestinyWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.ATTACKER_DECLARED) {
return;
}
map.computeIfAbsent(
new MageObjectReference(event.getSourceId(), game), u -> new HashSet<>()
).add(event.getTargetId());
}
@Override
public void reset() {
super.reset();
map.clear();
}
Set<UUID> getPlayers(MageObjectReference mor) {
return map.getOrDefault(mor, null);
}
}

View file

@ -115,6 +115,7 @@ public final class ZendikarRising extends ExpansionSet {
cards.add(new SetCardInfo("Akoum Warrior", 134, Rarity.UNCOMMON, mage.cards.a.AkoumWarrior.class));
cards.add(new SetCardInfo("Allied Assault", 1, Rarity.UNCOMMON, mage.cards.a.AlliedAssault.class));
cards.add(new SetCardInfo("Ancient Greenwarden", 178, Rarity.MYTHIC, mage.cards.a.AncientGreenwarden.class));
cards.add(new SetCardInfo("Angel of Destiny", 2, Rarity.MYTHIC, mage.cards.a.AngelOfDestiny.class));
cards.add(new SetCardInfo("Angelheart Protector", 3, Rarity.COMMON, mage.cards.a.AngelheartProtector.class));
cards.add(new SetCardInfo("Anticognition", 45, Rarity.COMMON, mage.cards.a.Anticognition.class));
cards.add(new SetCardInfo("Archon of Emeria", 4, Rarity.RARE, mage.cards.a.ArchonOfEmeria.class));