From 5869f77f0cb08368bf93ce037728a645bf92389f Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 29 Apr 2014 13:47:59 +0200 Subject: [PATCH] Added DiscardHandTargetEffect, some additions to game log messages. --- Mage/src/mage/abilities/effects/Effects.java | 4 +- .../common/counter/AddCountersAllEffect.java | 39 +++++--- .../counter/AddCountersControllerEffect.java | 14 ++- .../counter/AddCountersTargetEffect.java | 52 ++++++---- .../discard/DiscardHandTargetEffect.java | 95 +++++++++++++++++++ .../mage/game/tournament/LimitedOptions.java | 2 +- 6 files changed, 166 insertions(+), 40 deletions(-) create mode 100644 Mage/src/mage/abilities/effects/common/discard/DiscardHandTargetEffect.java diff --git a/Mage/src/mage/abilities/effects/Effects.java b/Mage/src/mage/abilities/effects/Effects.java index 97646501ea4..f4640ddc7f1 100644 --- a/Mage/src/mage/abilities/effects/Effects.java +++ b/Mage/src/mage/abilities/effects/Effects.java @@ -63,8 +63,10 @@ public class Effects extends ArrayList { } rule = effect.getText(mode); if (rule != null) { - if (rule.startsWith("and ") || rule.startsWith(",")) { + if (rule.startsWith("and ")) { endString = " "; + } else if (rule.startsWith(",")) { + endString = ""; } sbText.append(endString).append(rule); } diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java index 37abf4450cd..0214231f51a 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java @@ -29,6 +29,7 @@ package mage.abilities.effects.common.counter; import java.util.List; import java.util.UUID; +import mage.MageObject; import mage.constants.Outcome; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; @@ -36,6 +37,7 @@ import mage.counters.Counter; import mage.filter.FilterPermanent; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.players.Player; /** * @@ -43,8 +45,8 @@ import mage.game.permanent.Permanent; */ public class AddCountersAllEffect extends OneShotEffect { - private Counter counter; - private FilterPermanent filter; + private final Counter counter; + private final FilterPermanent filter; public AddCountersAllEffect(Counter counter, FilterPermanent filter) { super(Outcome.Benefit); @@ -61,27 +63,34 @@ public class AddCountersAllEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - boolean applied = false; - if (counter != null) { - UUID controllerId = source.getControllerId(); - List permanents = game.getBattlefield().getAllActivePermanents(); - for (Permanent permanent : permanents) { - if (filter.match(permanent, source.getSourceId(), controllerId, game)) { - permanent.addCounters(counter.copy(), game); - applied = true; + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = game.getObject(source.getSourceId()); + if (controller != null && sourceObject != null) { + if (counter != null) { + UUID controllerId = source.getControllerId(); + List permanents = game.getBattlefield().getAllActivePermanents(); + for (Permanent permanent : permanents) { + if (filter.match(permanent, source.getSourceId(), controllerId, game)) { + permanent.addCounters(counter.copy(), game); + game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ") + .append(controller.getName()).append(" puts ") + .append(counter.getCount()).append(" ").append(counter.getName().toLowerCase()) + .append(" counter on ").append(permanent.getName()).toString()); + } } - } - } - return applied; + } + return true; + } + return false; } private void setText() { StringBuilder sb = new StringBuilder(); sb.append("put "); if (counter.getCount() > 1) { - sb.append(Integer.toString(counter.getCount())).append(" ").append(counter.getName()).append(" counters on each "); + sb.append(Integer.toString(counter.getCount())).append(" ").append(counter.getName().toLowerCase()).append(" counters on each "); } else { - sb.append("a ").append(counter.getName()).append(" counter on each "); + sb.append("a ").append(counter.getName().toLowerCase()).append(" counter on each "); } sb.append(filter.getMessage()); staticText = sb.toString(); diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersControllerEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersControllerEffect.java index b547233d61e..6e1159c3bad 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersControllerEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersControllerEffect.java @@ -61,8 +61,9 @@ public class AddCountersControllerEffect extends OneShotEffect 0; } - return affectedTargets > 0; + return false; } @Override diff --git a/Mage/src/mage/abilities/effects/common/discard/DiscardHandTargetEffect.java b/Mage/src/mage/abilities/effects/common/discard/DiscardHandTargetEffect.java new file mode 100644 index 00000000000..d5384b62f6f --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/discard/DiscardHandTargetEffect.java @@ -0,0 +1,95 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.abilities.effects.common.discard; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ + +public class DiscardHandTargetEffect extends OneShotEffect { + + protected String targetDescription; + + public DiscardHandTargetEffect() { + this(""); + } + public DiscardHandTargetEffect(String targetDescription) { + super(Outcome.Discard); + this.targetDescription = targetDescription; + } + + public DiscardHandTargetEffect(final DiscardHandTargetEffect effect) { + super(effect); + this.targetDescription = effect.targetDescription; + } + + @Override + public DiscardHandTargetEffect copy() { + return new DiscardHandTargetEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + for (UUID playerId: getTargetPointer().getTargets(game, source)) { + Player player = game.getPlayer(playerId); + if (player != null) { + player.discard(player.getHand().size(), source, game); + } + } + return true; + } + return false; + } + + @Override + public String getText(Mode mode) { + if (staticText != null && !staticText.isEmpty()) { + return staticText; + } + StringBuilder sb = new StringBuilder(); + if (targetDescription.length() > 0) { + sb.append(targetDescription); + } else { + sb.append("target ").append(mode.getTargets().get(0).getTargetName()); + } + sb.append(" discards his or her hand"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/Mage/src/mage/game/tournament/LimitedOptions.java b/Mage/src/mage/game/tournament/LimitedOptions.java index 3db3aed3926..e44b7efec9d 100644 --- a/Mage/src/mage/game/tournament/LimitedOptions.java +++ b/Mage/src/mage/game/tournament/LimitedOptions.java @@ -39,7 +39,7 @@ import mage.game.draft.DraftCube; */ public class LimitedOptions implements Serializable { - protected List sets = new ArrayList(); + protected List sets = new ArrayList<>(); protected int constructionTime; protected String draftCubeName; protected DraftCube draftCube;