use of mage.counters.Counters in project mage by magefree.
the class MaulfistRevolutionaryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
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, source.getControllerId(), source, game);
}
return true;
}
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
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.getControllerId(), source, game);
}
}
return true;
}
return false;
}
use of mage.counters.Counters in project mage by magefree.
the class SkyshipPlundererEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
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, source.getControllerId(), source, game);
}
return true;
}
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
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.getControllerId(), source, game);
}
}
return true;
}
return false;
}
use of mage.counters.Counters in project mage by magefree.
the class ChronozoaTest method testDuplicationEffect.
/**
* Test that the tokens are put to battlefield if the last time counter is removed
*/
@Test
public void testDuplicationEffect() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
addCard(Zone.HAND, playerA, "Chronozoa");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa");
setStopAt(9, PhaseStep.PRECOMBAT_MAIN);
execute();
// The original Chronozoa card should be in graveyard
assertGraveyardCount(playerA, 1);
final List<Permanent> creatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE, currentGame);
Assert.assertEquals(2, creatures.size());
for (final Permanent creature : creatures) {
// Make sure the creatures are Chronozoa tokens
Assert.assertEquals("Chronozoa", creature.getName());
Assert.assertEquals("Chronozoa has to be a token", true, creature instanceof PermanentToken);
// Make sure each token has 2 time counters
final Counters counters = creature.getCounters(currentGame);
Assert.assertEquals(1, counters.size());
for (final Counter counter : counters.values()) {
Assert.assertEquals(CounterType.TIME.getName(), counter.getName());
Assert.assertEquals(2, counter.getCount());
}
}
}
use of mage.counters.Counters in project mage by magefree.
the class ThiefOfBloodEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int countersRemoved = 0;
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
Counters counters = permanent.getCounters(game).copy();
for (Counter counter : counters.values()) {
permanent.removeCounters(counter.getName(), counter.getCount(), source, game);
countersRemoved += counter.getCount();
}
}
if (countersRemoved > 0) {
Permanent sourcePermanent = game.getPermanentEntering(source.getSourceId());
if (sourcePermanent != null) {
sourcePermanent.addCounters(CounterType.P1P1.createInstance(countersRemoved), source.getControllerId(), source, game);
}
}
return true;
}
use of mage.counters.Counters in project mage by magefree.
the class UnholyIndentureReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// copy from ReturnToBattlefieldUnderYourControlAttachedEffect
Object object = getValue("attachedTo");
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && object instanceof Permanent && !(object instanceof PermanentToken)) {
// not token
Card card = game.getCard(((Permanent) object).getId());
// Move the card only, if it is still in the next zone after the battlefield
if (card != null && card.getZoneChangeCounter(game) == ((Permanent) object).getZoneChangeCounter(game) + 1) {
Counters countersToAdd = new Counters();
countersToAdd.addCounter(CounterType.P1P1.createInstance());
game.setEnterWithCounters(card.getId(), countersToAdd);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, false, null);
return true;
}
}
return false;
}
Aggregations