forked from External/mage
New LoseLifeAllEffect, added amount and random option to DiscardEachPlayerEffect.
This commit is contained in:
parent
cb1c3ff535
commit
7f00d990ab
2 changed files with 127 additions and 4 deletions
|
|
@ -1,30 +1,58 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants;
|
||||
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;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DiscardEachPlayerEffect extends OneShotEffect<DiscardEachPlayerEffect> {
|
||||
|
||||
protected DynamicValue amount;
|
||||
protected boolean randomDiscard;
|
||||
|
||||
public DiscardEachPlayerEffect() {
|
||||
this(new StaticValue(1), false);
|
||||
}
|
||||
|
||||
public DiscardEachPlayerEffect(int amount, boolean randomDiscard) {
|
||||
this(new StaticValue(amount), randomDiscard);
|
||||
}
|
||||
|
||||
public DiscardEachPlayerEffect(DynamicValue amount, boolean randomDiscard) {
|
||||
super(Constants.Outcome.Discard);
|
||||
staticText = "each player discards a card";
|
||||
this.randomDiscard = randomDiscard;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public DiscardEachPlayerEffect(final DiscardEachPlayerEffect effect) {
|
||||
super(effect);
|
||||
this.randomDiscard = effect.randomDiscard;
|
||||
this.amount = effect.amount;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (UUID playerId : game.getPlayerList()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.discard(1, 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;
|
||||
|
|
@ -35,4 +63,22 @@ public class DiscardEachPlayerEffect extends OneShotEffect<DiscardEachPlayerEffe
|
|||
return new DiscardEachPlayerEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Each player discards ");
|
||||
sb.append(amount).append(" card");
|
||||
try {
|
||||
if (Integer.parseInt(amount.toString()) > 1) {
|
||||
sb.append("s");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sb.append("s");
|
||||
}
|
||||
if (randomDiscard) {
|
||||
sb.append(" at random");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue