use of mage.counters.Counter in project mage by magefree.
the class ClockspinningAddOrRemoveCounterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (player != null && permanent != null) {
if (player.chooseUse(Outcome.Neutral, "Remove a counter?", source, game)) {
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
effect.apply(game, source);
} else {
Counter counter = selectCounterType(game, source, permanent);
if (counter != null) {
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
effect.apply(game, source);
}
}
return true;
}
Card card = game.getCard(source.getFirstTarget());
if (player != null && card != null) {
if (player.chooseUse(Outcome.Neutral, "Remove a counter?", source, game)) {
Counter counter = selectCounterType(game, source, card);
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
effect.apply(game, source);
} else {
Counter counter = selectCounterType(game, source, card);
if (counter != null) {
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
effect.apply(game, source);
}
}
return true;
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class NestingGroundsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent fromPermanent = game.getPermanent(source.getFirstTarget());
Permanent toPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (fromPermanent == null || toPermanent == null || controller == null) {
return false;
}
Set<String> possibleChoices = new HashSet<>(fromPermanent.getCounters(game).keySet());
if (possibleChoices.size() == 0) {
return false;
}
Choice choice = new ChoiceImpl();
choice.setChoices(possibleChoices);
if (controller.choose(outcome, choice, game)) {
String chosen = choice.getChoice();
if (fromPermanent.getCounters(game).containsKey(chosen)) {
CounterType counterType = CounterType.findByName(chosen);
if (counterType != null) {
Counter counter = counterType.createInstance();
fromPermanent.removeCounters(counterType.getName(), 1, source, game);
toPermanent.addCounters(counter, source.getControllerId(), source, game);
return true;
}
}
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class QuarryHaulerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller == null || permanent == null) {
return false;
}
List<String> counterNames = permanent.getCounters(game).values().stream().map(Counter::getName).collect(Collectors.toList());
for (String counterName : counterNames) {
Counter newCounter = CounterType.findByName(counterName).createInstance();
if (controller.chooseUse(Outcome.BoostCreature, "Add or remove a " + counterName + " counter?", null, "Add", "Remove", source, game)) {
permanent.addCounters(newCounter, source.getControllerId(), source, game);
} else {
permanent.removeCounters(newCounter, source, game);
}
}
return true;
}
use of mage.counters.Counter in project mage by magefree.
the class StrengthOfTheTajuruAddCountersTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
int amount = source.getManaCostsToPay().getX();
Counter counter = CounterType.P1P1.createInstance(amount);
for (UUID uuid : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
permanent.addCounters(counter.copy(), source.getControllerId(), source, game);
affectedTargets++;
}
}
return affectedTargets > 0;
}
use of mage.counters.Counter in project mage by magefree.
the class AsLuckWouldHaveItEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
if (getValue("rolled") != null) {
int amount = (Integer) getValue("rolled");
permanent.addCounters(new Counter("luck", amount), source.getControllerId(), source, game);
if (permanent.getCounters(game).getCount("luck") >= 100) {
Player player = game.getPlayer(permanent.getControllerId());
if (player != null) {
player.won(game);
}
}
return true;
}
}
return false;
}
Aggregations