mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Added DiscardHandTargetEffect, some additions to game log messages.
This commit is contained in:
parent
9021449970
commit
5869f77f0c
6 changed files with 166 additions and 40 deletions
|
@ -63,8 +63,10 @@ public class Effects extends ArrayList<Effect> {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<AddCountersAllEffect> {
|
||||
|
||||
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<AddCountersAllEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean applied = false;
|
||||
if (counter != null) {
|
||||
UUID controllerId = source.getControllerId();
|
||||
List<Permanent> 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<Permanent> 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();
|
||||
|
|
|
@ -61,8 +61,9 @@ public class AddCountersControllerEffect extends OneShotEffect<AddCountersContro
|
|||
|
||||
public AddCountersControllerEffect(final AddCountersControllerEffect effect) {
|
||||
super(effect);
|
||||
if (effect.counter != null)
|
||||
if (effect.counter != null) {
|
||||
this.counter = effect.counter.copy();
|
||||
}
|
||||
this.enchantedEquipped = effect.enchantedEquipped;
|
||||
}
|
||||
|
||||
|
@ -76,8 +77,12 @@ public class AddCountersControllerEffect extends OneShotEffect<AddCountersContro
|
|||
Permanent permanent = game.getPermanent(eUuid);
|
||||
if (permanent != null) {
|
||||
uuid = permanent.getControllerId();
|
||||
} else return false;
|
||||
} else return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Player player = game.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
|
@ -92,8 +97,9 @@ public class AddCountersControllerEffect extends OneShotEffect<AddCountersContro
|
|||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("its controller gets ").append(Integer.toString(counter.getCount())).append(" ").append(counter.getName()).append(" counters");
|
||||
staticText = sb.toString();
|
||||
} else
|
||||
} else {
|
||||
staticText = "its controller gets a " + counter.getName() + " counter";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,6 +37,7 @@ import mage.game.permanent.Permanent;
|
|||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
|
@ -80,27 +81,40 @@ public class AddCountersTargetEffect extends OneShotEffect<AddCountersTargetEffe
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int affectedTargets = 0;
|
||||
for (UUID uuid : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(uuid);
|
||||
if (permanent != null) {
|
||||
if (counter != null) {
|
||||
Counter newCounter = counter.copy();
|
||||
newCounter.add(amount.calculate(game, source));
|
||||
permanent.addCounters(newCounter, game);
|
||||
affectedTargets ++;
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
if (controller != null && sourceObject != null) {
|
||||
int affectedTargets = 0;
|
||||
for (UUID uuid : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(uuid);
|
||||
if (permanent != null) {
|
||||
if (counter != null) {
|
||||
Counter newCounter = counter.copy();
|
||||
newCounter.add(amount.calculate(game, source));
|
||||
permanent.addCounters(newCounter, game);
|
||||
affectedTargets ++;
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
Player player = game.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
Counter newCounter = counter.copy();
|
||||
newCounter.add(amount.calculate(game, source));
|
||||
player.addCounters(newCounter, game);
|
||||
affectedTargets ++;
|
||||
game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ")
|
||||
.append(controller.getName()).append(" puts ")
|
||||
.append(counter.getCount()).append(" ").append(counter.getName().toLowerCase())
|
||||
.append(" counter on ").append(player.getName()).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Player player = game.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
Counter newCounter = counter.copy();
|
||||
newCounter.add(amount.calculate(game, source));
|
||||
player.addCounters(newCounter, game);
|
||||
affectedTargets ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return affectedTargets > 0;
|
||||
}
|
||||
return affectedTargets > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<DiscardHandTargetEffect> {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ import mage.game.draft.DraftCube;
|
|||
*/
|
||||
public class LimitedOptions implements Serializable {
|
||||
|
||||
protected List<String> sets = new ArrayList<String>();
|
||||
protected List<String> sets = new ArrayList<>();
|
||||
protected int constructionTime;
|
||||
protected String draftCubeName;
|
||||
protected DraftCube draftCube;
|
||||
|
|
Loading…
Reference in a new issue