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 {
public LeechesEffect() {
@ -91,7 +90,7 @@ class LeechesEffect extends OneShotEffect {
int countPoisonCounters = targetPlayer.getCounters().getCount(CounterType.POISON);
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);
return true;
}

View file

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

View file

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

View file

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

View file

@ -98,8 +98,7 @@ public class RemoveCounterCost extends CostImpl {
if (counterTypeToRemove != null) {
counterName = counterTypeToRemove.getName();
} else {
if (permanent.getCounters().size() > 1 && counterTypeToRemove == null) {
} else if (permanent.getCounters().size() > 1 && counterTypeToRemove == null) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : permanent.getCounters().values()) {
@ -118,7 +117,6 @@ public class RemoveCounterCost extends CostImpl {
}
}
}
}
if (counterName != null) {
int countersLeft = countersToRemove - countersRemoved;
int countersOnPermanent = permanent.getCounters().getCount(counterName);
@ -129,6 +127,7 @@ public class RemoveCounterCost extends CostImpl {
}
permanent.removeCounters(counterName, numberOfCountersSelected, game);
if (permanent.getCounters().getCount(counterName) == 0) {
// this removes only the item with number = 0 from the collection
permanent.getCounters().removeCounter(counterName);
}
countersRemoved += numberOfCountersSelected;

View file

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

View file

@ -582,6 +582,8 @@ public interface Player extends MageItem, Copyable<Player> {
void addCounters(Counter counter, Game game);
void removeCounters(String name, int amount, Ability source, Game game);
List<UUID> getAttachments();
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) {
for (ProtectionAbility ability : abilities.getProtectionAbilities()) {
if (!ability.canTarget(source, game)) {