Fixed that no event was send for removing counters from players.

This commit is contained in:
LevelX2 2016-04-15 18:01:38 +02:00
parent 162ac957c6
commit 22dbb1ef38
8 changed files with 49 additions and 30 deletions

View file

@ -64,7 +64,6 @@ public class Leeches extends CardImpl {
} }
} }
class LeechesEffect extends OneShotEffect { class LeechesEffect extends OneShotEffect {
public LeechesEffect() { public LeechesEffect() {
@ -91,7 +90,7 @@ class LeechesEffect extends OneShotEffect {
int countPoisonCounters = targetPlayer.getCounters().getCount(CounterType.POISON); int countPoisonCounters = targetPlayer.getCounters().getCount(CounterType.POISON);
if (countPoisonCounters > 0) { if (countPoisonCounters > 0) {
targetPlayer.getCounters().removeCounter(CounterType.POISON, countPoisonCounters); targetPlayer.removeCounters(CounterType.POISON.getName(), countPoisonCounters, source, game);
targetPlayer.damage(countPoisonCounters, source.getSourceId(), game, false, true); targetPlayer.damage(countPoisonCounters, source.getSourceId(), game, false, true);
return true; return true;
} }

View file

@ -1441,6 +1441,11 @@ public class TestPlayer implements Player {
computerPlayer.addCounters(counter, game); computerPlayer.addCounters(counter, game);
} }
@Override
public void removeCounters(String name, int amount, Ability source, Game game) {
computerPlayer.removeCounters(name, amount, source, game);
}
@Override @Override
public Abilities<Ability> getAbilities() { public Abilities<Ability> getAbilities() {
return computerPlayer.getAbilities(); return computerPlayer.getAbilities();

View file

@ -348,7 +348,6 @@ public class PlayerStub implements Player {
return false; return false;
} }
@Override @Override
public boolean getPassedAllTurns() { public boolean getPassedAllTurns() {
return false; return false;
@ -1019,6 +1018,11 @@ public class PlayerStub implements Player {
} }
@Override
public void removeCounters(String name, int amount, Ability source, Game game) {
}
@Override @Override
public List<UUID> getAttachments() { public List<UUID> getAttachments() {
return null; return null;

View file

@ -69,7 +69,7 @@ public class PayLoyaltyCost extends CostImpl {
if (amount > 0) { if (amount > 0) {
planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount)); planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount));
} else if (amount < 0) { } else if (amount < 0) {
planeswalker.getCounters().removeCounter(CounterType.LOYALTY, Math.abs(amount)); planeswalker.removeCounters(CounterType.LOYALTY.getName(), Math.abs(amount), game);
} }
planeswalker.addLoyaltyUsed(); planeswalker.addLoyaltyUsed();
this.paid = true; this.paid = true;

View file

@ -98,24 +98,22 @@ public class RemoveCounterCost extends CostImpl {
if (counterTypeToRemove != null) { if (counterTypeToRemove != null) {
counterName = counterTypeToRemove.getName(); counterName = counterTypeToRemove.getName();
} else { } else if (permanent.getCounters().size() > 1 && counterTypeToRemove == null) {
if (permanent.getCounters().size() > 1 && counterTypeToRemove == null) { Choice choice = new ChoiceImpl(true);
Choice choice = new ChoiceImpl(true); Set<String> choices = new HashSet<>();
Set<String> choices = new HashSet<>(); for (Counter counter : permanent.getCounters().values()) {
for (Counter counter : permanent.getCounters().values()) { if (permanent.getCounters().getCount(counter.getName()) > 0) {
if (permanent.getCounters().getCount(counter.getName()) > 0) { choices.add(counter.getName());
choices.add(counter.getName());
}
} }
choice.setChoices(choices); }
choice.setMessage("Choose a counter to remove from " + permanent.getLogName()); choice.setChoices(choices);
controller.choose(Outcome.UnboostCreature, choice, game); choice.setMessage("Choose a counter to remove from " + permanent.getLogName());
counterName = choice.getChoice(); controller.choose(Outcome.UnboostCreature, choice, game);
} else { counterName = choice.getChoice();
for (Counter counter : permanent.getCounters().values()) { } else {
if (counter.getCount() > 0) { for (Counter counter : permanent.getCounters().values()) {
counterName = counter.getName(); if (counter.getCount() > 0) {
} counterName = counter.getName();
} }
} }
} }
@ -129,6 +127,7 @@ public class RemoveCounterCost extends CostImpl {
} }
permanent.removeCounters(counterName, numberOfCountersSelected, game); permanent.removeCounters(counterName, numberOfCountersSelected, game);
if (permanent.getCounters().getCount(counterName) == 0) { if (permanent.getCounters().getCount(counterName) == 0) {
// this removes only the item with number = 0 from the collection
permanent.getCounters().removeCounter(counterName); permanent.getCounters().removeCounter(counterName);
} }
countersRemoved += numberOfCountersSelected; countersRemoved += numberOfCountersSelected;

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.common; package mage.abilities.effects.common;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -62,12 +61,11 @@ public class RemoveAllCountersSourceEffect extends OneShotEffect {
@java.lang.Override @java.lang.Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if(sourcePermanent != null) { if (sourcePermanent != null) {
int count = sourcePermanent.getCounters().getCount(counterType); int count = sourcePermanent.getCounters().getCount(counterType);
sourcePermanent.getCounters().removeCounter(counterType, count); sourcePermanent.removeCounters(counterType.getName(), count, game);
return true; return true;
} }
return false; return false;
} }
} }

View file

@ -582,6 +582,8 @@ public interface Player extends MageItem, Copyable<Player> {
void addCounters(Counter counter, Game game); void addCounters(Counter counter, Game game);
void removeCounters(String name, int amount, Ability source, Game game);
List<UUID> getAttachments(); List<UUID> getAttachments();
boolean addAttachment(UUID permanentId, Game game); boolean addAttachment(UUID permanentId, Game game);

View file

@ -1839,6 +1839,18 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
} }
@Override
public void removeCounters(String name, int amount, Ability source, Game game) {
for (int i = 0; i < amount; i++) {
counters.removeCounter(name, 1);
GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTER_REMOVED,
getId(), (source == null ? null : source.getSourceId()), (source == null ? null : source.getControllerId()));
event.setData(name);
event.setAmount(1);
game.fireEvent(event);
}
}
protected boolean canDamage(MageObject source, Game game) { protected boolean canDamage(MageObject source, Game game) {
for (ProtectionAbility ability : abilities.getProtectionAbilities()) { for (ProtectionAbility ability : abilities.getProtectionAbilities()) {
if (!ability.canTarget(source, game)) { if (!ability.canTarget(source, game)) {