* Added return code to addCounter method.

This commit is contained in:
LevelX2 2016-08-11 17:40:51 +02:00
parent 5ee29a14e6
commit 058d25fa56
5 changed files with 52 additions and 31 deletions

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,12 +20,11 @@
* 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.costs.common;
import java.util.UUID;
@ -73,8 +72,7 @@ public class PutCountersSourceCost extends CostImpl {
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null) {
permanent.addCounters(counter, game);
this.paid = true;
this.paid = permanent.addCounters(counter, game);;
}
return paid;
}
@ -84,4 +82,3 @@ public class PutCountersSourceCost extends CostImpl {
return new PutCountersSourceCost(this);
}
}

View file

@ -150,13 +150,13 @@ public interface Card extends MageObject {
Counters getCounters(Game game);
void addCounters(String name, int amount, Game game);
boolean addCounters(String name, int amount, Game game);
void addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects);
boolean addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects);
void addCounters(Counter counter, Game game);
boolean addCounters(Counter counter, Game game);
void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects);
boolean addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects);
void removeCounters(String name, int amount, Game game);

View file

@ -653,12 +653,13 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
}
@Override
public void addCounters(String name, int amount, Game game) {
addCounters(name, amount, game, null);
public boolean addCounters(String name, int amount, Game game) {
return addCounters(name, amount, game, null);
}
@Override
public void addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
public boolean addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
boolean returnCode = true;
GameEvent countersEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, ownerId, name, amount);
countersEvent.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(countersEvent)) {
@ -668,18 +669,24 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
if (!game.replaceEvent(event)) {
game.getState().getCardState(this.objectId).getCounters().addCounter(name, 1);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, ownerId, name, 1));
} else {
returnCode = false;
}
}
} else {
returnCode = false;
}
return returnCode;
}
@Override
public void addCounters(Counter counter, Game game) {
addCounters(counter, game, null);
public boolean addCounters(Counter counter, Game game) {
return addCounters(counter, game, null);
}
@Override
public void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) {
public boolean addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) {
boolean returnCode = true;
GameEvent countersEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, ownerId, counter.getName(), counter.getCount());
countersEvent.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(countersEvent)) {
@ -692,9 +699,14 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
if (!game.replaceEvent(event)) {
game.getState().getCardState(this.objectId).getCounters().addCounter(eventCounter);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, ownerId, counter.getName(), 1));
} else {
returnCode = false;
}
}
} else {
returnCode = false;
}
return returnCode;
}
@Override

View file

@ -333,12 +333,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
}
@Override
public void addCounters(String name, int amount, Game game) {
addCounters(name, amount, game, null);
public boolean addCounters(String name, int amount, Game game) {
return addCounters(name, amount, game, null);
}
@Override
public void addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
public boolean addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
boolean returnCode = true;
GameEvent countersEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, controllerId, name, amount);
countersEvent.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(countersEvent)) {
@ -348,14 +349,20 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
if (!game.replaceEvent(event)) {
counters.addCounter(name, 1);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, controllerId, name, 1));
} else {
returnCode = false;
}
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERS_ADDED, objectId, controllerId, name, amount));
} else {
returnCode = false;
}
return returnCode;
}
@Override
public void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) {
public boolean addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) {
boolean returnCode = true;
GameEvent countersEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, controllerId, counter.getName(), counter.getCount());
countersEvent.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(countersEvent)) {
@ -368,10 +375,15 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
if (!game.replaceEvent(event)) {
counters.addCounter(eventCounter);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, controllerId, counter.getName(), 1));
} else {
returnCode = false;
}
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERS_ADDED, objectId, controllerId, counter.getName(), amount));
} else {
returnCode = false;
}
return returnCode;
}
@Override

View file

@ -811,23 +811,23 @@ public class Spell extends StackObjImpl implements Card {
}
@Override
public void addCounters(String name, int amount, Game game) {
card.addCounters(name, amount, game);
public boolean addCounters(String name, int amount, Game game) {
return card.addCounters(name, amount, game);
}
@Override
public void addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
card.addCounters(name, amount, game, appliedEffects);
public boolean addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
return card.addCounters(name, amount, game, appliedEffects);
}
@Override
public void addCounters(Counter counter, Game game) {
card.addCounters(counter, game);
public boolean addCounters(Counter counter, Game game) {
return card.addCounters(counter, game);
}
@Override
public void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) {
card.addCounters(counter, game, appliedEffects);
public boolean addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) {
return card.addCounters(counter, game, appliedEffects);
}
@Override