use of mage.counters.Counter in project mage by magefree.
the class FlayEssenceEffect 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) {
int life = 0;
for (Counter counter : permanent.getCounters(game).values()) {
life += counter.getCount();
}
controller.moveCards(permanent, Zone.EXILED, source, game);
controller.gainLife(life, game, source);
return true;
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class LeechBonderEffect 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 SunburstEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (permanent != null) {
int countersAmount = amount.calculate(game, source, this);
if (countersAmount > 0) {
Counter counter;
if (permanent.isCreature(game)) {
counter = CounterType.P1P1.createInstance(countersAmount);
} else {
counter = CounterType.CHARGE.createInstance(countersAmount);
}
// the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
permanent.addCounters(counter, source.getControllerId(), source, game, appliedEffects);
if (!game.isSimulation()) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
game.informPlayers(player.getLogName() + " puts " + counter.getCount() + ' ' + counter.getName() + " counter on " + permanent.getName());
}
}
}
}
return true;
}
use of mage.counters.Counter in project mage by magefree.
the class CardImpl method addCounters.
public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List<UUID> appliedEffects, boolean isEffect, int maxCounters) {
boolean returnCode = true;
GameEvent addingAllEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, source, playerAddingCounters, counter.getName(), counter.getCount());
addingAllEvent.setAppliedEffects(appliedEffects);
addingAllEvent.setFlag(isEffect);
if (!game.replaceEvent(addingAllEvent)) {
int amount;
if (maxCounters < Integer.MAX_VALUE) {
amount = Integer.min(addingAllEvent.getAmount(), maxCounters - this.getCounters(game).getCount(counter.getName()));
} else {
amount = addingAllEvent.getAmount();
}
boolean isEffectFlag = addingAllEvent.getFlag();
int finalAmount = amount;
for (int i = 0; i < amount; i++) {
Counter eventCounter = counter.copy();
eventCounter.remove(eventCounter.getCount() - 1);
GameEvent addingOneEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, source, playerAddingCounters, counter.getName(), 1);
addingOneEvent.setAppliedEffects(appliedEffects);
addingOneEvent.setFlag(isEffectFlag);
if (!game.replaceEvent(addingOneEvent)) {
getCounters(game).addCounter(eventCounter);
GameEvent addedOneEvent = GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, source, playerAddingCounters, counter.getName(), 1);
addedOneEvent.setFlag(addingOneEvent.getFlag());
game.fireEvent(addedOneEvent);
} else {
finalAmount--;
returnCode = false;
}
}
if (finalAmount > 0) {
GameEvent addedAllEvent = GameEvent.getEvent(GameEvent.EventType.COUNTERS_ADDED, objectId, source, playerAddingCounters, counter.getName(), amount);
addedAllEvent.setFlag(isEffectFlag);
game.fireEvent(addedAllEvent);
}
} else {
returnCode = false;
}
return returnCode;
}
use of mage.counters.Counter in project mage by magefree.
the class PermanentImpl method getValue.
@Override
public String getValue(GameState state) {
StringBuilder sb = threadLocalBuilder.get();
sb.append(controllerId).append(getName()).append(tapped).append(damage);
sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue());
sb.append(abilities.getValue());
for (Counter counter : getCounters(state).values()) {
sb.append(counter.getName()).append(counter.getCount());
}
return sb.toString();
}
Aggregations