Search in sources :

Example 1 with CounterType

use of mage.counters.CounterType in project mage by magefree.

the class MaulfistRevolutionaryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (player != null) {
            Counters counters = player.getCounters().copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                player.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
            return true;
        }
        Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (permanent != null) {
            Counters counters = permanent.getCounters(game).copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                permanent.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Counter(mage.counters.Counter) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) Counters(mage.counters.Counters)

Example 2 with CounterType

use of mage.counters.CounterType in project mage by magefree.

the class SkyshipPlundererEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (player != null) {
            Counters counters = player.getCounters().copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                player.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
            return true;
        }
        Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (permanent != null) {
            Counters counters = permanent.getCounters(game).copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                permanent.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Counter(mage.counters.Counter) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) Counters(mage.counters.Counters)

Example 3 with CounterType

use of mage.counters.CounterType 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;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CounterType(mage.counters.CounterType) Counter(mage.counters.Counter) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 4 with CounterType

use of mage.counters.CounterType in project mage by magefree.

the class TizerusChargerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    Player player = game.getPlayer(source.getControllerId());
    if (permanent == null || player == null) {
        return false;
    }
    SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
    if (!(spellAbility instanceof EscapeAbility) || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
        return false;
    }
    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
    CounterType counterType = player.chooseUse(outcome, "Choose +1/+1 or flying", null, "+1/+1", "Flying", source, game) ? CounterType.P1P1 : CounterType.FLYING;
    permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game, appliedEffects);
    return true;
}
Also used : Player(mage.players.Player) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) EscapeAbility(mage.abilities.keyword.EscapeAbility)

Example 5 with CounterType

use of mage.counters.CounterType in project mage by magefree.

the class KathrilAspectWarperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game) == 0) {
        return false;
    }
    Set<CounterType> counterSet = player.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game).stream().map(Card::getAbilities).flatMap(Collection::stream).map(this::checkAbility).collect(Collectors.toSet());
    if (counterSet == null || counterSet.size() == 0) {
        return false;
    }
    int countersAdded = 0;
    for (CounterType counterType : counterSet) {
        if (counterType == null) {
            continue;
        }
        FilterControlledPermanent filter = new FilterControlledCreaturePermanent("creature to give a " + counterType + " counter");
        Target target = new TargetControlledPermanent(filter);
        target.setNotTarget(true);
        if (!player.choose(outcome, target, source.getSourceId(), game)) {
            continue;
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent == null) {
            continue;
        }
        if (permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game)) {
            countersAdded++;
        }
    }
    if (countersAdded == 0) {
        return false;
    }
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return true;
    }
    permanent.addCounters(CounterType.P1P1.createInstance(countersAdded), source.getControllerId(), source, game);
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) CounterType(mage.counters.CounterType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Collection(java.util.Collection) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Aggregations

CounterType (mage.counters.CounterType)9 Permanent (mage.game.permanent.Permanent)9 Player (mage.players.Player)6 Counter (mage.counters.Counter)5 Counters (mage.counters.Counters)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 UUID (java.util.UUID)2 Choice (mage.choices.Choice)2 ChoiceImpl (mage.choices.ChoiceImpl)2 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)2 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)2 TargetPermanentOrPlayer (mage.target.common.TargetPermanentOrPlayer)2 Collection (java.util.Collection)1 SpellAbility (mage.abilities.SpellAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 InfoEffect (mage.abilities.effects.common.InfoEffect)1 EscapeAbility (mage.abilities.keyword.EscapeAbility)1 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)1 Card (mage.cards.Card)1