Search in sources :

Example 11 with Counter

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

the class AddRemoveAllTimeSuspentCountersEffect method execute.

private void execute(final Game game, final Player controller, final MageObject sourceObject, Ability source, final List<Card> cards, final boolean removeCounter) {
    for (Card card : cards) {
        if (filter.match(card, game)) {
            final String counterName = counter.getName();
            if (removeCounter) {
                final Counter existingCounterOfSameType = card.getCounters(game).get(counterName);
                final int countersToRemove = Math.min(existingCounterOfSameType.getCount(), counter.getCount());
                final Counter modifiedCounter = new Counter(counterName, countersToRemove);
                card.removeCounters(modifiedCounter, source, game);
            } else {
                card.addCounters(counter, source.getControllerId(), source, game);
            }
            if (!game.isSimulation()) {
                game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ").append(controller.getLogName()).append(actionStr).append(counter.getCount()).append(' ').append(counterName.toLowerCase(Locale.ENGLISH)).append(" counter on ").append(card.getName()).toString());
            }
        }
    }
}
Also used : Counter(mage.counters.Counter) Card(mage.cards.Card)

Example 12 with Counter

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

the class RemoveCounterTargetEffect method selectCounterType.

private Counter selectCounterType(Game game, Ability source, Permanent permanent) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && !permanent.getCounters(game).isEmpty()) {
        String counterName = null;
        if (permanent.getCounters(game).size() > 1) {
            Choice choice = new ChoiceImpl(true);
            Set<String> choices = new HashSet<>();
            for (Counter counterOnPermanent : permanent.getCounters(game).values()) {
                if (permanent.getCounters(game).getCount(counterOnPermanent.getName()) > 0) {
                    choices.add(counterOnPermanent.getName());
                }
            }
            choice.setChoices(choices);
            choice.setMessage("Choose a counter type to remove from " + permanent.getName());
            if (controller.choose(Outcome.Detriment, choice, game)) {
                counterName = choice.getChoice();
            } else {
                return null;
            }
        } else {
            for (Counter counterOnPermanent : permanent.getCounters(game).values()) {
                if (counterOnPermanent.getCount() > 0) {
                    counterName = counterOnPermanent.getName();
                }
            }
        }
        return new Counter(counterName);
    }
    return null;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 13 with Counter

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

the class AddCountersTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null && counter != null) {
        int affectedTargets = 0;
        for (UUID uuid : targetPointer.getTargets(game, source)) {
            Counter newCounter = counter.copy();
            // 0 -- you must use default couner
            int calculated = amount.calculate(game, source, this);
            if (calculated < 0) {
                continue;
            } else if (calculated == 0) {
            // use original counter
            } else {
                // increase to calculated value
                newCounter.remove(newCounter.getCount());
                newCounter.add(calculated);
            }
            Permanent permanent = game.getPermanent(uuid);
            Player player = game.getPlayer(uuid);
            Card card = game.getCard(targetPointer.getFirst(game, source));
            if (permanent != null) {
                permanent.addCounters(newCounter, source.getControllerId(), source, game);
                affectedTargets++;
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counters on " + permanent.getLogName());
            } else if (player != null) {
                player.addCounters(newCounter, source.getControllerId(), source, game);
                affectedTargets++;
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counters on " + player.getLogName());
            } else if (card != null) {
                card.addCounters(newCounter, source.getControllerId(), source, game);
                affectedTargets++;
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counters on " + card.getLogName());
            }
        }
        return affectedTargets > 0;
    }
    return false;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) UUID(java.util.UUID) Card(mage.cards.Card)

Example 14 with Counter

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

the class PlayerPanelExt method updateAvatar.

/**
 * Updates the avatar image and tooltip text
 */
private void updateAvatar() {
    if (flagName == null) {
        // do only once
        avatar.setText(this.player.getName());
        if (!player.getUserData().getFlagName().equals(flagName)) {
            flagName = player.getUserData().getFlagName();
            this.avatar.setTopTextImage(CountryUtil.getCountryFlagIconSize(flagName, 11).getImage());
        }
        // TODO: Add the wins to the tooltiptext of the avatar
        String countryname = CountryUtil.getCountryName(flagName);
        if (countryname == null) {
            countryname = "Unknown";
        }
        basicTooltipText = "<HTML>Name: " + player.getName() + "<br/>Country: " + countryname + "<br/>Constructed rating: " + player.getUserData().getConstructedRating() + "<br/>Limited rating: " + player.getUserData().getLimitedRating() + "<br/>Deck hash code: " + player.getDeckHashCode() + "<br/>This match wins: " + player.getWins() + " of " + player.getWinsNeeded() + " (to win the match)" + (player.getUserData() == null ? "" : "<br/>History: " + player.getUserData().getHistory());
    }
    // Extend tooltip
    StringBuilder tooltipText = new StringBuilder(basicTooltipText);
    this.avatar.setTopTextImageRight(null);
    for (String name : player.getDesignationNames()) {
        tooltipText.append("<br/>").append(name);
        if (DesignationType.CITYS_BLESSING.toString().equals(name)) {
            this.avatar.setTopTextImageRight(ImageHelper.getImageFromResources("/info/city_blessing.png"));
        }
    }
    if (player.isMonarch()) {
        this.avatar.setTopTextImageRight(ImageHelper.getImageFromResources("/info/crown.png"));
    }
    for (Counter counter : player.getCounters().values()) {
        tooltipText.append("<br/>").append(counter.getName()).append(" counters: ").append(counter.getCount());
    }
    avatar.setToolTipText(tooltipText.toString());
    avatar.repaint();
    // used if avatar image can't be used
    this.btnPlayer.setText(player.getName());
    this.btnPlayer.setToolTipText(tooltipText.toString());
}
Also used : Counter(mage.counters.Counter)

Example 15 with Counter

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

the class DramatistsPuppetEffect 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) {
        return false;
    }
    List<String> counterNames = permanent.getCounters(game).values().stream().map(Counter::getName).collect(Collectors.toList());
    for (String counterName : counterNames) {
        Counter newCounter = CounterType.findByName(counterName).createInstance();
        if (controller.chooseUse(Outcome.BoostCreature, "Add or remove a " + counterName + " counter?", null, "Add", "Remove", source, game)) {
            permanent.addCounters(newCounter, source.getControllerId(), source, game);
        } else {
            permanent.removeCounters(newCounter, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent)

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