Search in sources :

Example 1 with Counter

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

the class GameStateEvaluator method evaluatePermanent.

public static int evaluatePermanent(Permanent permanent, Game game, boolean ignoreTapped) {
    int value = 0;
    if (ignoreTapped) {
        value = 5;
    } else {
        value = permanent.isTapped() ? 4 : 5;
    }
    if (permanent.getCardType(game).contains(CardType.CREATURE)) {
        value += evaluateCreature(permanent, game) * CREATURE_FACTOR;
    }
    value += permanent.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD).size();
    for (ActivatedAbility ability : permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
        if (!(ability instanceof ActivatedManaAbilityImpl) && ability.canActivate(ability.getControllerId(), game).canActivate()) {
            value += ability.getEffects().size();
        }
    }
    for (Counter counter : permanent.getCounters(game).values()) {
        if (!(counter instanceof BoostCounter)) {
            value += counter.getCount();
        }
    }
    value += permanent.getAbilities().getStaticAbilities(Zone.BATTLEFIELD).size();
    value += permanent.getAbilities().getTriggeredAbilities(Zone.BATTLEFIELD).size();
    value += permanent.getManaCost().manaValue();
    // TODO: add a difficulty to calculation to ManaCost - sort permanents by difficulty for casting when evaluating game states
    return value;
}
Also used : BoostCounter(mage.counters.BoostCounter) Counter(mage.counters.Counter) ActivatedAbility(mage.abilities.ActivatedAbility) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) BoostCounter(mage.counters.BoostCounter)

Example 2 with Counter

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

the class DeepglowSkateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean didOne = false;
    for (Target target : source.getTargets()) {
        for (UUID targetID : target.getTargets()) {
            Permanent permanent = game.getPermanent(targetID);
            if (permanent != null) {
                for (Counter counter : permanent.getCounters(game).values()) {
                    Counter newCounter = new Counter(counter.getName(), counter.getCount());
                    permanent.addCounters(newCounter, source.getControllerId(), source, game);
                    didOne = true;
                }
            }
        }
    }
    return didOne;
}
Also used : Target(mage.target.Target) Counter(mage.counters.Counter) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 3 with Counter

use of mage.counters.Counter 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 4 with Counter

use of mage.counters.Counter 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 5 with Counter

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

the class SuncleanserPreventCountersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (permanent != null) {
        for (Counter counter : permanent.getCounters(game).copy().values()) {
            // copy to prevent ConcurrentModificationException
            permanent.removeCounters(counter, source, game);
        }
        return true;
    }
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (player != null) {
        for (Counter counter : player.getCounters().copy().values()) {
            // copy to prevent ConcurrentModificationException
            player.removeCounters(counter.getName(), counter.getCount(), source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Aggregations

Counter (mage.counters.Counter)49 Permanent (mage.game.permanent.Permanent)38 Player (mage.players.Player)28 Choice (mage.choices.Choice)10 ChoiceImpl (mage.choices.ChoiceImpl)10 TargetPermanent (mage.target.TargetPermanent)10 UUID (java.util.UUID)9 HashSet (java.util.HashSet)8 Counters (mage.counters.Counters)8 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)8 Card (mage.cards.Card)6 CounterType (mage.counters.CounterType)5 FilterPermanent (mage.filter.FilterPermanent)5 Target (mage.target.Target)4 TargetPermanentOrPlayer (mage.target.common.TargetPermanentOrPlayer)4 ArrayList (java.util.ArrayList)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2