forked from External/mage
[DKA] Blck Cat
Some text improvements Fixed NezumiBoneReader Added randomDiscard parameter to DiscardTargetEffect
This commit is contained in:
parent
ef5594cdd3
commit
37086bfa5c
5 changed files with 111 additions and 11 deletions
|
|
@ -29,9 +29,11 @@ package mage.abilities.effects.common;
|
|||
|
||||
import mage.Constants.Outcome;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
|
|
@ -42,20 +44,30 @@ import mage.players.Player;
|
|||
public class DiscardTargetEffect extends OneShotEffect<DiscardTargetEffect> {
|
||||
|
||||
protected DynamicValue amount;
|
||||
protected boolean randomDiscard;
|
||||
|
||||
public DiscardTargetEffect(DynamicValue amount) {
|
||||
this(amount, false);
|
||||
}
|
||||
|
||||
public DiscardTargetEffect(DynamicValue amount, boolean randomDiscard) {
|
||||
super(Outcome.Discard);
|
||||
this.randomDiscard = randomDiscard;
|
||||
this.amount = amount;
|
||||
setText();
|
||||
}
|
||||
|
||||
public DiscardTargetEffect(int amount) {
|
||||
this(new StaticValue(amount));
|
||||
}
|
||||
|
||||
public DiscardTargetEffect(int amount, boolean randomDiscard) {
|
||||
this(new StaticValue(amount), randomDiscard);
|
||||
}
|
||||
|
||||
public DiscardTargetEffect(final DiscardTargetEffect effect) {
|
||||
super(effect);
|
||||
this.amount = effect.amount.clone();
|
||||
this.randomDiscard = effect.randomDiscard;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -67,14 +79,28 @@ public class DiscardTargetEffect extends OneShotEffect<DiscardTargetEffect> {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
if (player != null) {
|
||||
player.discard(amount.calculate(game, source), source, game);
|
||||
if (randomDiscard) {
|
||||
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) {
|
||||
player.discard(card, source, game);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.discard(amount.calculate(game, source), source, game);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
StringBuilder sb = new StringBuilder("Target player discards ");
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
StringBuilder sb = new StringBuilder("Target ");
|
||||
sb.append(mode.getTargets().get(0).getTargetName());
|
||||
sb.append(" discards ");
|
||||
sb.append(amount).append(" card");
|
||||
try {
|
||||
if (Integer.parseInt(amount.toString()) > 1) {
|
||||
|
|
@ -83,11 +109,14 @@ public class DiscardTargetEffect extends OneShotEffect<DiscardTargetEffect> {
|
|||
} catch (Exception e) {
|
||||
sb.append("s");
|
||||
}
|
||||
if (randomDiscard) {
|
||||
sb.append(" at random");
|
||||
}
|
||||
String message = amount.getMessage();
|
||||
if (message.length() > 0) {
|
||||
sb.append(" for each ");
|
||||
}
|
||||
sb.append(message);
|
||||
staticText = sb.toString();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue