mirror of
https://github.com/correl/mage.git
synced 2024-12-27 03:00:13 +00:00
Added random discard option to DiscardControllerEffect. Used it in Hannabi Blast.
This commit is contained in:
parent
a326d91f52
commit
fb3a9e3166
2 changed files with 43 additions and 47 deletions
|
@ -30,16 +30,12 @@ package mage.sets.championsofkamigawa;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import mage.Constants;
|
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Rarity;
|
import mage.Constants.Rarity;
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.abilities.effects.OneShotEffect;
|
|
||||||
import mage.abilities.effects.common.DamageTargetEffect;
|
import mage.abilities.effects.common.DamageTargetEffect;
|
||||||
|
import mage.abilities.effects.common.DiscardControllerEffect;
|
||||||
import mage.abilities.effects.common.ReturnToHandSpellEffect;
|
import mage.abilities.effects.common.ReturnToHandSpellEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.game.Game;
|
|
||||||
import mage.players.Player;
|
|
||||||
import mage.target.common.TargetCreatureOrPlayer;
|
import mage.target.common.TargetCreatureOrPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +51,7 @@ public class HanabiBlast extends CardImpl<HanabiBlast> {
|
||||||
this.getSpellAbility().addEffect(new DamageTargetEffect(2));
|
this.getSpellAbility().addEffect(new DamageTargetEffect(2));
|
||||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
|
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
|
||||||
this.getSpellAbility().addEffect(ReturnToHandSpellEffect.getInstance());
|
this.getSpellAbility().addEffect(ReturnToHandSpellEffect.getInstance());
|
||||||
this.getSpellAbility().addEffect(new HanabiBlastDiscardEffect());
|
this.getSpellAbility().addEffect(new DiscardControllerEffect(1, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public HanabiBlast (final HanabiBlast card) {
|
public HanabiBlast (final HanabiBlast card) {
|
||||||
|
@ -68,34 +64,3 @@ public class HanabiBlast extends CardImpl<HanabiBlast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class HanabiBlastDiscardEffect extends OneShotEffect<HanabiBlastDiscardEffect> {
|
|
||||||
|
|
||||||
private static final String effectText = "discard a card at random";
|
|
||||||
|
|
||||||
HanabiBlastDiscardEffect () {
|
|
||||||
super(Constants.Outcome.Discard);
|
|
||||||
staticText = effectText;
|
|
||||||
}
|
|
||||||
|
|
||||||
HanabiBlastDiscardEffect(HanabiBlastDiscardEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
|
||||||
if (player != null) {
|
|
||||||
player.discard(player.getHand().getRandom(game), source, game);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HanabiBlastDiscardEffect copy() {
|
|
||||||
return new HanabiBlastDiscardEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import mage.abilities.Ability;
|
||||||
import mage.abilities.dynamicvalue.DynamicValue;
|
import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
|
import mage.cards.Card;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
|
@ -42,20 +43,31 @@ import mage.players.Player;
|
||||||
public class DiscardControllerEffect extends OneShotEffect<DiscardControllerEffect> {
|
public class DiscardControllerEffect extends OneShotEffect<DiscardControllerEffect> {
|
||||||
|
|
||||||
protected DynamicValue amount;
|
protected DynamicValue amount;
|
||||||
|
protected boolean randomDiscard;
|
||||||
public DiscardControllerEffect(DynamicValue amount) {
|
|
||||||
super(Outcome.Discard);
|
|
||||||
this.amount = amount;
|
|
||||||
setText();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiscardControllerEffect(int amount) {
|
public DiscardControllerEffect(int amount) {
|
||||||
this(new StaticValue(amount));
|
this(new StaticValue(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DiscardControllerEffect(int amount, boolean randomDiscard) {
|
||||||
|
this(new StaticValue(amount), randomDiscard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiscardControllerEffect(DynamicValue amount) {
|
||||||
|
this(amount, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiscardControllerEffect(DynamicValue amount, boolean randomDiscard) {
|
||||||
|
super(Outcome.Discard);
|
||||||
|
this.amount = amount;
|
||||||
|
this.randomDiscard = randomDiscard;
|
||||||
|
setText();
|
||||||
|
}
|
||||||
|
|
||||||
public DiscardControllerEffect(final DiscardControllerEffect effect) {
|
public DiscardControllerEffect(final DiscardControllerEffect effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
this.amount = effect.amount.copy();
|
this.amount = effect.amount.copy();
|
||||||
|
this.randomDiscard = effect.randomDiscard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,17 +77,33 @@ public class DiscardControllerEffect extends OneShotEffect<DiscardControllerEffe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
|
boolean result = false;
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player player = game.getPlayer(source.getControllerId());
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.discard(amount.calculate(game, source), source, game);
|
if (randomDiscard) {
|
||||||
return true;
|
int maxAmount = Math.min(amount.calculate(game, source), player.getHand().size());
|
||||||
|
for (int i = 0; i < maxAmount; i++) {
|
||||||
|
Card card = player.getHand().getRandom(game);
|
||||||
|
if (card != null) {
|
||||||
|
result |= player.discard(card, source, game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.discard(amount.calculate(game, source), source, game);
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setText() {
|
private void setText() {
|
||||||
StringBuilder sb = new StringBuilder("Discard ");
|
StringBuilder sb = new StringBuilder("Discard ");
|
||||||
sb.append(amount).append(" card");
|
if (amount.toString().equals("1")) {
|
||||||
|
sb.append("a");
|
||||||
|
} else {
|
||||||
|
sb.append(amount);
|
||||||
|
}
|
||||||
|
sb.append(" card");
|
||||||
try {
|
try {
|
||||||
if (Integer.parseInt(amount.toString()) > 1) {
|
if (Integer.parseInt(amount.toString()) > 1) {
|
||||||
sb.append("s");
|
sb.append("s");
|
||||||
|
@ -83,6 +111,9 @@ public class DiscardControllerEffect extends OneShotEffect<DiscardControllerEffe
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sb.append("s");
|
sb.append("s");
|
||||||
}
|
}
|
||||||
|
if (randomDiscard) {
|
||||||
|
sb.append(" at random");
|
||||||
|
}
|
||||||
String message = amount.getMessage();
|
String message = amount.getMessage();
|
||||||
if (message.length() > 0) {
|
if (message.length() > 0) {
|
||||||
sb.append(" for each ");
|
sb.append(" for each ");
|
||||||
|
|
Loading…
Reference in a new issue