use of mage.counters.Counter in project mage by magefree.
the class EntersBattlefieldWithXCountersEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
if (source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
}
if (permanent != null) {
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility != null && spellAbility.getSourceId().equals(source.getSourceId()) && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
if (spellAbility.getSourceId().equals(source.getSourceId())) {
// put into play by normal cast
int amount = spellAbility.getManaCostsToPay().getX();
if (amount > 0) {
Counter counterToAdd = counter.copy();
counterToAdd.add(amount - counter.getCount());
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
permanent.addCounters(counterToAdd, source.getControllerId(), source, game, appliedEffects);
}
}
}
}
return true;
}
use of mage.counters.Counter in project mage by magefree.
the class ProliferateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Counter newCounter = null;
if (controller == null) {
return false;
}
Target target = new TargetPermanentOrPlayer(0, Integer.MAX_VALUE, new FilterPermanentOrPlayerWithCounter(), true);
Map<String, Serializable> options = new HashMap<>();
options.put("UI.right.btn.text", "Done");
controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options);
for (UUID chosen : target.getTargets()) {
Permanent permanent = game.getPermanent(chosen);
if (permanent != null) {
if (!permanent.getCounters(game).isEmpty()) {
for (Counter counter : permanent.getCounters(game).values()) {
newCounter = new Counter(counter.getName());
permanent.addCounters(newCounter, source.getControllerId(), source, game);
}
if (newCounter != null) {
game.informPlayers(permanent.getName() + " had 1 " + newCounter.getName() + " counter added to it.");
}
}
} else {
Player player = game.getPlayer(chosen);
if (player != null) {
if (!player.getCounters().isEmpty()) {
for (Counter counter : player.getCounters().values()) {
newCounter = new Counter(counter.getName());
player.addCounters(newCounter, source.getControllerId(), source, game);
}
if (newCounter != null) {
game.informPlayers(player.getLogName() + " had 1 " + newCounter.getName() + " counter added to them.");
}
}
}
}
}
return true;
}
use of mage.counters.Counter in project mage by magefree.
the class AddCountersAttachedEffect 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();
int countersToAdd = amount.calculate(game, source, this);
if (countersToAdd > 0) {
countersToAdd--;
newCounter.add(countersToAdd);
attachedTo.addCounters(newCounter, source.getControllerId(), source, game);
}
}
return true;
}
return false;
}
use of mage.counters.Counter in project mage by magefree.
the class ElspethConquersDeathReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = game.getCard(source.getFirstTarget());
if (player == null || card == null) {
return false;
}
player.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return false;
}
Counter counter = player.chooseUse(outcome, "Choose a type of counter to add", null, "+1/+1", "Loyalty", source, game) ? CounterType.P1P1.createInstance() : CounterType.LOYALTY.createInstance();
permanent.addCounters(counter, source.getControllerId(), source, game);
return true;
}
use of mage.counters.Counter in project mage by magefree.
the class GrimdancerEffect 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;
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose two abilities");
choice.setChoices(choices);
if (!player.choose(outcome, choice, game)) {
return false;
}
Counter counter1 = null;
Counter counter2 = null;
switch(choice.getChoice()) {
case "Menace and deathtouch":
counter1 = CounterType.MENACE.createInstance();
counter2 = CounterType.DEATHTOUCH.createInstance();
break;
case "Menace and lifelink":
counter1 = CounterType.MENACE.createInstance();
counter2 = CounterType.LIFELINK.createInstance();
break;
case "Deathtouch and lifelink":
counter1 = CounterType.DEATHTOUCH.createInstance();
counter2 = CounterType.LIFELINK.createInstance();
break;
}
permanent.addCounters(counter1, source.getControllerId(), source, game);
permanent.addCounters(counter2, source.getControllerId(), source, game);
return true;
}
Aggregations