use of mage.counters.Counter in project mage by magefree.
the class FateTransferEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creatureToMoveCountersFrom = game.getPermanent(source.getTargets().get(0).getFirstTarget());
Permanent creatureToMoveCountersTo = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (creatureToMoveCountersFrom != null && creatureToMoveCountersTo != null) {
Permanent copyCreature = creatureToMoveCountersFrom.copy();
for (Counter counter : copyCreature.getCounters(game).values()) {
creatureToMoveCountersFrom.removeCounters(counter, source, game);
creatureToMoveCountersTo.addCounters(counter, source.getControllerId(), source, game);
}
return true;
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class GilderBairnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent target = game.getPermanent(source.getFirstTarget());
if (target != null) {
for (Counter counter : target.getCounters(game).values()) {
Counter newCounter = new Counter(counter.getName(), counter.getCount());
target.addCounters(newCounter, source.getControllerId(), source, game);
}
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class PartingThoughtsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
permanent.destroy(source, game, false);
int numberOfCounters = 0;
for (Counter counter : permanent.getCounters(game).values()) {
numberOfCounters += counter.getCount();
}
if (numberOfCounters > 0) {
controller.drawCards(numberOfCounters, source, game);
controller.loseLife(numberOfCounters, game, source, false);
}
}
return true;
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class AddCounterChoiceSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
Counter counter;
if (player.chooseUse(Outcome.Neutral, "Choose " + counterType1 + " or " + counterType2, null, cap(counterType1.getName()), cap(counterType2.getName()), source, game)) {
counter = counterType1.createInstance();
} else {
counter = counterType2.createInstance();
}
return permanent.addCounters(counter, source.getControllerId(), source, game);
}
use of mage.counters.Counter in project mage by magefree.
the class AddCountersSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (putOnCard) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
if (counter != null) {
Counter newCounter = counter.copy();
int countersToAdd = amount.calculate(game, source, this);
if (countersToAdd > 0 && newCounter.getCount() == 1) {
countersToAdd--;
}
newCounter.add(countersToAdd);
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
card.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects);
if (informPlayers && !game.isSimulation()) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
game.informPlayers(player.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + card.getLogName());
}
}
}
return true;
}
} else {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
if (permanent != null && (// from static ability
source.getSourceObjectZoneChangeCounter() == 0 || source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game))) {
// prevent to add counters to later source objects
if (counter != null) {
Counter newCounter = counter.copy();
int countersToAdd = amount.calculate(game, source, this);
if (amount instanceof StaticValue || countersToAdd > 0) {
if (countersToAdd > 0 && newCounter.getCount() == 1) {
countersToAdd--;
}
newCounter.add(countersToAdd);
int before = permanent.getCounters(game).getCount(newCounter.getName());
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
// if used from a replacement effect, the basic event determines if an effect was already applied to an event
permanent.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects);
if (informPlayers && !game.isSimulation()) {
int amountAdded = permanent.getCounters(game).getCount(newCounter.getName()) - before;
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
game.informPlayers(player.getLogName() + " puts " + amountAdded + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + permanent.getLogName());
}
}
}
}
}
}
return true;
}
return false;
}
Aggregations