use of mage.counters.Counter in project mage by magefree.
the class EvolutionaryEscalationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Counter counter = CounterType.P1P1.createInstance(3);
boolean addedCounters = false;
for (Target target : source.getTargets()) {
Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
if (targetPermanent != null) {
targetPermanent.addCounters(counter.copy(), source.getControllerId(), source, game);
addedCounters = true;
}
}
return addedCounters;
}
use of mage.counters.Counter in project mage by magefree.
the class TayamLuminousEnigmaReplacementEffect method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
paid = false;
int countersRemoved = 0;
Player controller = game.getPlayer(controllerId);
for (int i = 0; i < countersToRemove; i++) {
if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
if (!permanent.getCounters(game).isEmpty()) {
String counterName = null;
if (permanent.getCounters(game).size() > 1) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : permanent.getCounters(game).values()) {
if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter to remove from " + permanent.getLogName());
if (!controller.choose(Outcome.UnboostCreature, choice, game)) {
return false;
}
counterName = choice.getChoice();
} else {
for (Counter counter : permanent.getCounters(game).values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
if (counterName != null) {
permanent.removeCounters(counterName, 1, source, game);
target.clearChosen();
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes a ").append(counterName).append(" counter from ").append(permanent.getName()).toString());
}
countersRemoved++;
if (countersRemoved == countersToRemove) {
paid = true;
break;
}
}
}
}
} else {
break;
}
}
return paid;
}
use of mage.counters.Counter 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.Counter in project mage by magefree.
the class RemoveCountersAttachedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.getAttachedTo() != null) {
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo != null && counter != null) {
Counter newCounter = counter.copy();
newCounter.add(amount.calculate(game, source, this));
attachedTo.removeCounters(newCounter, source, game);
}
return true;
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class ClockspinningAddOrRemoveCounterEffect method selectCounterType.
private Counter selectCounterType(Game game, Ability source, Card card) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && !card.getCounters(game).isEmpty()) {
String counterName = null;
if (card.getCounters(game).size() > 1) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : card.getCounters(game).values()) {
if (card.getCounters(game).getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter type to add to " + card.getName());
if (controller.choose(Outcome.Neutral, choice, game)) {
counterName = choice.getChoice();
} else {
return null;
}
} else {
for (Counter counter : card.getCounters(game).values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
return new Counter(counterName);
}
return null;
}
Aggregations