forked from External/mage
replace some instances of getPlayers with getPlayersInRange (#8348)
This commit is contained in:
parent
5ecdd4fb4a
commit
f14e15d33a
9 changed files with 151 additions and 173 deletions
|
|
@ -4,24 +4,19 @@ import mage.abilities.Ability;
|
|||
import mage.abilities.Mode;
|
||||
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
|
||||
import mage.abilities.common.EntersBattlefieldAbility;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.CreateTokenTargetEffect;
|
||||
import mage.abilities.effects.common.EntersBattlefieldUnderControlOfOpponentOfChoiceEffect;
|
||||
import mage.abilities.effects.common.SetPlayerLifeSourceEffect;
|
||||
import mage.abilities.effects.common.discard.DiscardHandControllerEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.TargetController;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.token.ZombieToken;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.effects.common.EntersBattlefieldUnderControlOfOpponentOfChoiceEffect;
|
||||
|
||||
import static mage.constants.Outcome.Benefit;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
|
|
@ -62,7 +57,7 @@ public final class CaptiveAudience extends CardImpl {
|
|||
class CaptiveAudienceCreateTokensEffect extends OneShotEffect {
|
||||
|
||||
CaptiveAudienceCreateTokensEffect() {
|
||||
super(Benefit);
|
||||
super(Outcome.Benefit);
|
||||
staticText = "Each opponent creates five 2/2 black Zombie creature tokens.";
|
||||
}
|
||||
|
||||
|
|
@ -77,17 +72,9 @@ class CaptiveAudienceCreateTokensEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (player != null && controller.hasOpponent(player.getId(), game)) {
|
||||
Effect effect = new CreateTokenTargetEffect(new ZombieToken(), 5);
|
||||
effect.setTargetPointer(new FixedTarget(player.getId(), game));
|
||||
effect.apply(game, source);
|
||||
}
|
||||
for (UUID playerId : game.getOpponents(source.getControllerId())) {
|
||||
new ZombieToken().putOntoBattlefield(5, game, source, playerId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@ package mage.cards.c;
|
|||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.DealtDamageToSourceTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.DamagePlayersEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.TargetController;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -28,7 +30,9 @@ public final class CoalhaulerSwine extends CardImpl {
|
|||
this.toughness = new MageInt(4);
|
||||
|
||||
// Whenever Coalhauler Swine is dealt damage, it deals that much damage to each player.
|
||||
this.addAbility(new DealtDamageToSourceTriggeredAbility(new CoalhaulerSwineEffect(), false, false, true));
|
||||
this.addAbility(new DealtDamageToSourceTriggeredAbility(new DamagePlayersEffect(
|
||||
Outcome.Neutral, CoalhaulerSwineValue.instance, TargetController.ANY, "it"
|
||||
), false, false, true));
|
||||
}
|
||||
|
||||
private CoalhaulerSwine(final CoalhaulerSwine card) {
|
||||
|
|
@ -39,33 +43,28 @@ public final class CoalhaulerSwine extends CardImpl {
|
|||
public CoalhaulerSwine copy() {
|
||||
return new CoalhaulerSwine(this);
|
||||
}
|
||||
}
|
||||
|
||||
static class CoalhaulerSwineEffect extends OneShotEffect {
|
||||
enum CoalhaulerSwineValue implements DynamicValue {
|
||||
instance;
|
||||
|
||||
public CoalhaulerSwineEffect() {
|
||||
super(Outcome.Damage);
|
||||
staticText = "it deals that much damage to each player";
|
||||
}
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
return (Integer) effect.getValue("damage");
|
||||
}
|
||||
|
||||
public CoalhaulerSwineEffect(final CoalhaulerSwineEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
@Override
|
||||
public CoalhaulerSwineValue copy() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoalhaulerSwineEffect copy() {
|
||||
return new CoalhaulerSwineEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (UUID playerId : game.getPlayers().keySet()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.damage((Integer) this.getValue("damage"), source.getSourceId(), source, game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "that much";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,16 @@ import mage.cards.CardImpl;
|
|||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author LoneFox
|
||||
|
|
@ -47,7 +50,7 @@ public final class Disorder extends CardImpl {
|
|||
|
||||
class DisorderEffect extends OneShotEffect {
|
||||
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("white creature");
|
||||
private static final FilterPermanent filter = new FilterCreaturePermanent("white creature");
|
||||
|
||||
static {
|
||||
filter.add(new ColorPredicate(ObjectColor.WHITE));
|
||||
|
|
@ -69,13 +72,16 @@ class DisorderEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
||||
filter.add(new ControllerIdPredicate(player.getId()));
|
||||
filter.add(new ColorPredicate(ObjectColor.WHITE));
|
||||
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
|
||||
player.damage(2, source.getSourceId(), source, game);
|
||||
}
|
||||
for (Player player : game
|
||||
.getBattlefield()
|
||||
.getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Controllable::getControllerId)
|
||||
.distinct()
|
||||
.map(game::getPlayer)
|
||||
.collect(Collectors.toList())) {
|
||||
player.damage(2, source.getSourceId(), source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
|
||||
package mage.cards.d;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.cards.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.TargetController;
|
||||
import mage.constants.Zone;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class DuskmantleSeer extends CardImpl {
|
||||
|
|
@ -33,9 +30,11 @@ public final class DuskmantleSeer extends CardImpl {
|
|||
|
||||
// Flying
|
||||
this.addAbility(FlyingAbility.getInstance());
|
||||
// At the beginning of your upkeep, each player reveals the top card of their library, loses life equal to that card's converted mana cost, then puts it into their hand.
|
||||
this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new DuskmantleSeerEffect(), TargetController.YOU, false, false));
|
||||
|
||||
// At the beginning of your upkeep, each player reveals the top card of their library, loses life equal to that card's converted mana cost, then puts it into their hand.
|
||||
this.addAbility(new BeginningOfUpkeepTriggeredAbility(
|
||||
new DuskmantleSeerEffect(), TargetController.YOU, false
|
||||
));
|
||||
}
|
||||
|
||||
private DuskmantleSeer(final DuskmantleSeer card) {
|
||||
|
|
@ -52,7 +51,8 @@ class DuskmantleSeerEffect extends OneShotEffect {
|
|||
|
||||
public DuskmantleSeerEffect() {
|
||||
super(Outcome.Detriment);
|
||||
this.staticText = "each player reveals the top card of their library, loses life equal to that card's mana value, then puts it into their hand";
|
||||
this.staticText = "each player reveals the top card of their library, " +
|
||||
"loses life equal to that card's mana value, then puts it into their hand";
|
||||
}
|
||||
|
||||
public DuskmantleSeerEffect(final DuskmantleSeerEffect effect) {
|
||||
|
|
@ -66,19 +66,18 @@ class DuskmantleSeerEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourceCard = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
if (sourceCard == null) {
|
||||
return false;
|
||||
}
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (player.getLibrary().hasCards()) {
|
||||
Card card = player.getLibrary().getFromTop(game);
|
||||
if (card != null) {
|
||||
player.revealCards(source, ": Revealed by " + player.getName(), new CardsImpl(card), game);
|
||||
player.loseLife(card.getManaValue(), game, source, false);
|
||||
player.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
Card card = player.getLibrary().getFromTop(game);
|
||||
if (card == null) {
|
||||
continue;
|
||||
}
|
||||
player.revealCards(source, new CardsImpl(card), game);
|
||||
player.loseLife(card.getManaValue(), game, source, false);
|
||||
player.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ package mage.cards.l;
|
|||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.RestrictionEffect;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.effects.common.combat.CantAttackBlockUnlessConditionSourceEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +29,9 @@ public final class LupinePrototype extends CardImpl {
|
|||
this.toughness = new MageInt(5);
|
||||
|
||||
// Lupine Prototype can't attack or block unless a player has no cards in hand.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new LupinePrototypeEffect()));
|
||||
this.addAbility(new SimpleStaticAbility(
|
||||
new CantAttackBlockUnlessConditionSourceEffect(LupinePrototypeCondition.instance)
|
||||
));
|
||||
}
|
||||
|
||||
private LupinePrototype(final LupinePrototype card) {
|
||||
|
|
@ -42,43 +44,23 @@ public final class LupinePrototype extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class LupinePrototypeEffect extends RestrictionEffect {
|
||||
enum LupinePrototypeCondition implements Condition {
|
||||
instance;
|
||||
|
||||
public LupinePrototypeEffect() {
|
||||
super(Duration.WhileOnBattlefield);
|
||||
staticText = "{this} can't attack or block unless a player has no cards in hand";
|
||||
}
|
||||
|
||||
public LupinePrototypeEffect(final LupinePrototypeEffect effect) {
|
||||
super(effect);
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return game
|
||||
.getState()
|
||||
.getPlayersInRange(source.getControllerId(), game)
|
||||
.stream()
|
||||
.map(game::getPlayer)
|
||||
.filter(Objects::nonNull)
|
||||
.map(Player::getHand)
|
||||
.anyMatch(Set::isEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(Permanent permanent, Ability source, Game game) {
|
||||
if (permanent.getId().equals(source.getSourceId())) {
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (player != null && player.getHand().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// don't apply for all other creatures!
|
||||
return false;
|
||||
public String toString() {
|
||||
return "a player has no cards in hand";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game, boolean canUseChooseDialogs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAttack(Game game, boolean canUseChooseDialogs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LupinePrototypeEffect copy() {
|
||||
return new LupinePrototypeEffect(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,5 @@
|
|||
|
||||
package mage.cards.m;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
|
|
@ -13,15 +9,18 @@ import mage.abilities.keyword.TrampleAbility;
|
|||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public final class MenacingOgre extends CardImpl {
|
||||
|
|
@ -79,7 +78,8 @@ class MenacingOgreEffect extends OneShotEffect {
|
|||
Map<Player, Integer> numberChosen = new HashMap<>();
|
||||
|
||||
//players choose numbers
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
number = player.getAmount(0, 1000, message, game);
|
||||
numberChosen.put(player, number);
|
||||
|
|
@ -92,7 +92,8 @@ class MenacingOgreEffect extends OneShotEffect {
|
|||
}
|
||||
}
|
||||
//reveal numbers to players and follow through with effect
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
game.informPlayers(player.getLogName() + " chose number " + numberChosen.get(player));
|
||||
if (numberChosen.get(player) >= highestNumber) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.r;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.CardImpl;
|
||||
|
|
@ -11,15 +9,16 @@ import mage.constants.Outcome;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public final class RepayInKind extends CardImpl {
|
||||
|
||||
public RepayInKind(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{5}{B}{B}");
|
||||
|
||||
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{5}{B}{B}");
|
||||
|
||||
// Each player's life total becomes the lowest life total among all players.
|
||||
this.getSpellAbility().addEffect(new RepayInKindEffect());
|
||||
|
|
@ -48,17 +47,19 @@ class RepayInKindEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int lowestLife = game.getPlayer(source.getControllerId()).getLife();
|
||||
for (Player playerid : game.getPlayers().values()) {
|
||||
if (playerid != null) {
|
||||
if (lowestLife > playerid.getLife()) {
|
||||
lowestLife = playerid.getLife();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Player playerId : game.getPlayers().values()) {
|
||||
if (playerId != null) {
|
||||
playerId.setLife(lowestLife, game, source);
|
||||
int lowestLife = game
|
||||
.getState()
|
||||
.getPlayersInRange(source.getControllerId(), game)
|
||||
.stream()
|
||||
.map(game::getPlayer)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToInt(Player::getLife)
|
||||
.min()
|
||||
.orElse(0);
|
||||
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.setLife(lowestLife, game, source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -68,5 +69,4 @@ class RepayInKindEffect extends OneShotEffect {
|
|||
public RepayInKindEffect copy() {
|
||||
return new RepayInKindEffect(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class SengirTheDarkBaronWatcher extends Watcher {
|
|||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() != GameEvent.EventType.BEGINNING_PHASE_PRE) {
|
||||
if (event.getType() == GameEvent.EventType.BEGINNING_PHASE_PRE) {
|
||||
game.getPlayers()
|
||||
.values()
|
||||
.stream()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
|
@ -9,15 +10,17 @@ import mage.constants.TargetController;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DamagePlayersEffect extends OneShotEffect {
|
||||
private DynamicValue amount;
|
||||
private TargetController controller;
|
||||
private String sourceName = "{this}";
|
||||
|
||||
private final DynamicValue amount;
|
||||
private final TargetController controller;
|
||||
private final String sourceName;
|
||||
|
||||
public DamagePlayersEffect(int amount) {
|
||||
this(Outcome.Damage, StaticValue.get(amount));
|
||||
|
|
@ -28,10 +31,7 @@ public class DamagePlayersEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
public DamagePlayersEffect(int amount, TargetController controller, String whoDealDamageName) {
|
||||
this(Outcome.Damage, StaticValue.get(amount), controller);
|
||||
|
||||
this.sourceName = whoDealDamageName;
|
||||
setText(); // TODO: replace to @Override public String getText()
|
||||
this(Outcome.Damage, StaticValue.get(amount), controller, whoDealDamageName);
|
||||
}
|
||||
|
||||
public DamagePlayersEffect(Outcome outcome, DynamicValue amount) {
|
||||
|
|
@ -39,10 +39,14 @@ public class DamagePlayersEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
public DamagePlayersEffect(Outcome outcome, DynamicValue amount, TargetController controller) {
|
||||
this(outcome, amount, controller, "{this}");
|
||||
}
|
||||
|
||||
public DamagePlayersEffect(Outcome outcome, DynamicValue amount, TargetController controller, String whoDealDamageName) {
|
||||
super(outcome);
|
||||
this.amount = amount;
|
||||
this.controller = controller;
|
||||
setText();
|
||||
this.sourceName = whoDealDamageName;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -55,26 +59,25 @@ public class DamagePlayersEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Collection<UUID> players;
|
||||
switch (controller) {
|
||||
case ANY:
|
||||
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.damage(amount.calculate(game, source, this), source.getSourceId(), source, game);
|
||||
}
|
||||
}
|
||||
case EACH_PLAYER:
|
||||
players = game.getState().getPlayersInRange(source.getControllerId(), game);
|
||||
break;
|
||||
case OPPONENT:
|
||||
for (UUID playerId : game.getOpponents(source.getControllerId())) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.damage(amount.calculate(game, source, this), source.getSourceId(), source, game);
|
||||
}
|
||||
}
|
||||
players = game.getOpponents(source.getControllerId());
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("TargetController type not supported.");
|
||||
}
|
||||
int damage = amount.calculate(game, source, this);
|
||||
for (UUID playerId : players) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.damage(damage, source.getSourceId(), source, game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -83,19 +86,20 @@ public class DamagePlayersEffect extends OneShotEffect {
|
|||
return new DamagePlayersEffect(this);
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
StringBuilder sb = new StringBuilder().append(this.sourceName).append(" deals ").append(amount.toString());
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
String message = sourceName + " deals " + amount.toString() + " damage to each ";
|
||||
switch (controller) {
|
||||
case ANY:
|
||||
sb.append(" damage to each player");
|
||||
break;
|
||||
case EACH_PLAYER:
|
||||
return message + "player";
|
||||
case OPPONENT:
|
||||
sb.append(" damage to each opponent");
|
||||
break;
|
||||
return message + "opponent";
|
||||
default:
|
||||
throw new UnsupportedOperationException("TargetController type not supported.");
|
||||
}
|
||||
staticText = sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue