mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
[TDM] Implement Avenger of the Fallen
This commit is contained in:
parent
532c18be13
commit
753c11f7a6
3 changed files with 80 additions and 12 deletions
|
|
@ -2,12 +2,13 @@ package mage.abilities.keyword;
|
|||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.AttacksTriggeredAbility;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.CreateTokenEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.token.RedWarriorToken;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
|
|
@ -16,10 +17,11 @@ import mage.util.CardUtil;
|
|||
public class MobilizeAbility extends AttacksTriggeredAbility {
|
||||
|
||||
public MobilizeAbility(int count) {
|
||||
super(new MobilizeEffect(count), false, "Mobilize " + count + " <i>(Whenever this creature attacks, create "
|
||||
+ (count == 1 ? "a" : CardUtil.numberToText(count)) + " tapped and attacking 1/1 red Warrior creature "
|
||||
+ (count == 1 ? "token" : "tokens") + ". Sacrifice " + (count == 1 ? "it" : "them")
|
||||
+ " at the beginning of the next end step.)");
|
||||
this(StaticValue.get(count));
|
||||
}
|
||||
|
||||
public MobilizeAbility(DynamicValue count) {
|
||||
super(new MobilizeEffect(count), false, makeText(count));
|
||||
}
|
||||
|
||||
protected MobilizeAbility(final MobilizeAbility ability) {
|
||||
|
|
@ -30,13 +32,33 @@ public class MobilizeAbility extends AttacksTriggeredAbility {
|
|||
public MobilizeAbility copy() {
|
||||
return new MobilizeAbility(this);
|
||||
}
|
||||
|
||||
private static String makeText(DynamicValue amount) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String message;
|
||||
String numToText;
|
||||
boolean plural;
|
||||
if (amount instanceof StaticValue) {
|
||||
int count = ((StaticValue) amount).getValue();
|
||||
message = "" + count;
|
||||
numToText = CardUtil.numberToText(count, "a");
|
||||
plural = count > 1;
|
||||
} else {
|
||||
message = "X, where X is " + amount.getMessage() + '.';
|
||||
numToText = "X";
|
||||
plural = true;
|
||||
}
|
||||
return "Mobilize " + message + " <i>(Whenever this creature attacks, create " +
|
||||
numToText + " tapped and attacking 1/1 red Warrior creature token" + (plural ? "s" : "") +
|
||||
". Sacrifice " + (plural ? "them" : "it") + " at the beginning of the next end step.)</i>";
|
||||
}
|
||||
}
|
||||
|
||||
class MobilizeEffect extends OneShotEffect {
|
||||
|
||||
private final int count;
|
||||
private final DynamicValue count;
|
||||
|
||||
MobilizeEffect(int count) {
|
||||
MobilizeEffect(DynamicValue count) {
|
||||
super(Outcome.Benefit);
|
||||
this.count = count;
|
||||
}
|
||||
|
|
@ -53,13 +75,9 @@ class MobilizeEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
CreateTokenEffect effect = new CreateTokenEffect(new RedWarriorToken(), this.count, true, true);
|
||||
effect.apply(game, source);
|
||||
effect.sacrificeTokensCreatedAtNextEndStep(game, source);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue