forked from External/mage
* Fixed a bug that adding counters with Skyship Plunder or Maulfist Revolution did not trigger counter added events.
This commit is contained in:
parent
350436dee2
commit
17fbee2400
6 changed files with 58 additions and 81 deletions
|
|
@ -54,17 +54,17 @@ import mage.watchers.Watcher;
|
|||
public class FairgroundsTrumpeter extends CardImpl {
|
||||
|
||||
public FairgroundsTrumpeter(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}");
|
||||
this.subtype.add("Elephant");
|
||||
this.power = new MageInt(2);
|
||||
this.toughness = new MageInt(2);
|
||||
|
||||
// At the beginning of each end step, if a +1/+1 counter was placed on a permanent under your control this turn, put a +1/+1 counter on Fairgrounds Trumpeter.
|
||||
this.addAbility(new ConditionalTriggeredAbility(new BeginningOfEndStepTriggeredAbility(
|
||||
new AddCountersSourceEffect(CounterType.P1P1.createInstance()),
|
||||
TargetController.ANY, false), FairgroundsTrumpeterCondition.getInstance(),
|
||||
"At the beginning of each end step, if a +1/+1 counter was placed on a permanent under your control this turn, put a +1/+1 counter on Fairgrounds Trumpeter."),
|
||||
new FairgroundsTrumpeterWatcher());
|
||||
new AddCountersSourceEffect(CounterType.P1P1.createInstance()),
|
||||
TargetController.ANY, false), FairgroundsTrumpeterCondition.getInstance(),
|
||||
"At the beginning of each end step, if a +1/+1 counter was placed on a permanent under your control this turn, put a +1/+1 counter on {this}."),
|
||||
new FairgroundsTrumpeterWatcher());
|
||||
}
|
||||
|
||||
public FairgroundsTrumpeter(final FairgroundsTrumpeter card) {
|
||||
|
|
@ -87,7 +87,7 @@ class FairgroundsTrumpeterCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
FairgroundsTrumpeterWatcher watcher = (FairgroundsTrumpeterWatcher) game.getState().getWatchers().get("FairgroundsTrumpeterWatcher");
|
||||
FairgroundsTrumpeterWatcher watcher = (FairgroundsTrumpeterWatcher) game.getState().getWatchers().get(FairgroundsTrumpeterWatcher.class.getName());
|
||||
return watcher != null && watcher.p1p1AddedToPermanent(source.getControllerId());
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ class FairgroundsTrumpeterWatcher extends Watcher {
|
|||
private final Set<UUID> players = new HashSet<>();
|
||||
|
||||
public FairgroundsTrumpeterWatcher() {
|
||||
super("FairgroundsTrumpeterWatcher", WatcherScope.GAME);
|
||||
super(FairgroundsTrumpeterWatcher.class.getName(), WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public FairgroundsTrumpeterWatcher(final FairgroundsTrumpeterWatcher watcher) {
|
||||
|
|
@ -115,7 +115,7 @@ class FairgroundsTrumpeterWatcher extends Watcher {
|
|||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.COUNTER_ADDED && event.getData().equals(CounterType.P1P1.getName())) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
||||
if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) {
|
||||
if (permanent != null) {
|
||||
players.add(permanent.getControllerId());
|
||||
}
|
||||
}
|
||||
|
|
@ -135,4 +135,3 @@ class FairgroundsTrumpeterWatcher extends Watcher {
|
|||
return new FairgroundsTrumpeterWatcher(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ import mage.cards.CardSetInfo;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
|
@ -95,14 +97,31 @@ class MaulfistRevolutionaryEffect extends OneShotEffect {
|
|||
if (controller != null) {
|
||||
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (player != null) {
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
counter.increase();
|
||||
Counters counters = player.getCounters().copy();
|
||||
for (Counter counter : counters.values()) {
|
||||
CounterType counterType = CounterType.findByName(counter.getName());
|
||||
Counter counterToAdd;
|
||||
if (counterType != null) {
|
||||
counterToAdd = counterType.createInstance();
|
||||
} else {
|
||||
counterToAdd = new Counter(counter.getName());
|
||||
}
|
||||
player.addCounters(counterToAdd, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
counter.increase();
|
||||
Counters counters = permanent.getCounters(game).copy();
|
||||
for (Counter counter : counters.values()) {
|
||||
CounterType counterType = CounterType.findByName(counter.getName());
|
||||
Counter counterToAdd;
|
||||
if (counterType != null) {
|
||||
counterToAdd = counterType.createInstance();
|
||||
} else {
|
||||
counterToAdd = new Counter(counter.getName());
|
||||
}
|
||||
permanent.addCounters(counterToAdd, source, game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ import mage.cards.CardSetInfo;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
|
@ -94,17 +96,35 @@ class SkyshipPlundererEffect extends OneShotEffect {
|
|||
if (controller != null) {
|
||||
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (player != null) {
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
counter.increase();
|
||||
Counters counters = player.getCounters().copy();
|
||||
for (Counter counter : counters.values()) {
|
||||
CounterType counterType = CounterType.findByName(counter.getName());
|
||||
Counter counterToAdd;
|
||||
if (counterType != null) {
|
||||
counterToAdd = counterType.createInstance();
|
||||
} else {
|
||||
counterToAdd = new Counter(counter.getName());
|
||||
}
|
||||
player.addCounters(counterToAdd, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
counter.increase();
|
||||
Counters counters = permanent.getCounters(game).copy();
|
||||
for (Counter counter : counters.values()) {
|
||||
CounterType counterType = CounterType.findByName(counter.getName());
|
||||
Counter counterToAdd;
|
||||
if (counterType != null) {
|
||||
counterToAdd = counterType.createInstance();
|
||||
} else {
|
||||
counterToAdd = new Counter(counter.getName());
|
||||
}
|
||||
permanent.addCounters(counterToAdd, source, game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,13 +73,6 @@ public class Counter implements Serializable {
|
|||
this.count = counter.count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the {@code count} by 1
|
||||
*/
|
||||
public void increase() {
|
||||
count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the passed in {@code amount} to the {@code count}
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@
|
|||
* 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.counters;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -52,11 +51,6 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
|
|||
return new Counters(this);
|
||||
}
|
||||
|
||||
public void addCounter(String name) {
|
||||
putIfAbsent(name, new Counter(name));
|
||||
this.get(name).increase();
|
||||
}
|
||||
|
||||
public void addCounter(String name, int amount) {
|
||||
putIfAbsent(name, new Counter(name));
|
||||
this.get(name).add(amount);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
package mage.counters;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Custom unit tests for {@link Counter}
|
||||
*/
|
||||
|
|
@ -17,20 +16,6 @@ public class CounterTest {
|
|||
counter = new Counter("test", 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldIncreaseCounter() {
|
||||
// given
|
||||
|
||||
// when
|
||||
counter.increase();
|
||||
|
||||
// then
|
||||
assertEquals(2, counter.getCount());
|
||||
assertEquals("test", counter.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldAddMana() {
|
||||
// given
|
||||
|
|
@ -42,38 +27,10 @@ public class CounterTest {
|
|||
assertEquals(6, counter.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldDecreaseCounter() {
|
||||
// given
|
||||
|
||||
|
||||
// when
|
||||
counter.decrease();
|
||||
|
||||
// then
|
||||
assertEquals(0, counter.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldNotDecreaseToLessThanZero() {
|
||||
// given
|
||||
|
||||
// when
|
||||
counter.decrease();
|
||||
counter.decrease();
|
||||
|
||||
// then
|
||||
assertEquals(0, counter.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldRemoveCounters() {
|
||||
// given
|
||||
|
||||
|
||||
// when
|
||||
counter.remove(1);
|
||||
|
||||
|
|
@ -81,7 +38,6 @@ public class CounterTest {
|
|||
assertEquals(0, counter.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldNotRemoveMoreCountersThanAvailable() {
|
||||
// given
|
||||
|
|
@ -93,7 +49,6 @@ public class CounterTest {
|
|||
assertEquals(0, counter.getCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldReturnCopy() {
|
||||
// given
|
||||
|
|
@ -106,7 +61,6 @@ public class CounterTest {
|
|||
assertFalse(copy == counter);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldCreateCounterFromCounter() {
|
||||
// given
|
||||
|
|
@ -119,12 +73,10 @@ public class CounterTest {
|
|||
assertEquals("test", copy.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldCreatDefaultCounter() {
|
||||
// given
|
||||
|
||||
|
||||
// when
|
||||
Counter defaultCounter = new Counter("default");
|
||||
|
||||
|
|
@ -132,4 +84,4 @@ public class CounterTest {
|
|||
assertEquals(1, defaultCounter.getCount());
|
||||
assertEquals("default", defaultCounter.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue