Search in sources :

Example 11 with Player

use of mage.players.Player in project mage by magefree.

the class BeaconOfDestinyEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    // check source
    MageObject object = game.getObject(event.getSourceId());
    if (object == null) {
        game.informPlayers("Couldn't find source of damage");
        return false;
    }
    if (!object.getId().equals(damageSource.getFirstTarget()) && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(damageSource.getFirstTarget()))) {
        return false;
    }
    TargetPermanent target = new TargetPermanent();
    target.add(source.getSourceId(), game);
    this.redirectTarget = target;
    // check player
    Player player = game.getPlayer(event.getTargetId());
    if (player != null) {
        if (player.getId().equals(source.getControllerId())) {
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetPermanent(mage.target.TargetPermanent) Spell(mage.game.stack.Spell)

Example 12 with Player

use of mage.players.Player in project mage by magefree.

the class BazaarTraderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    Permanent permanent = targetPermanentReference.getPermanent(game);
    if (player != null && permanent != null) {
        return permanent.changeControllerId(player.getId(), game, source);
    } else {
        discard();
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent)

Example 13 with Player

use of mage.players.Player in project mage by magefree.

the class ProtectionChosenColorTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (target != null) {
            ChoiceColor colorChoice = new ChoiceColor();
            if (!controller.choose(Outcome.Benefit, colorChoice, game)) {
                return false;
            }
            game.informPlayers(target.getName() + ": " + controller.getLogName() + " has chosen " + colorChoice.getChoice());
            game.getState().setValue(target.getId() + "_color", colorChoice.getColor());
            ObjectColor protectColor = (ObjectColor) game.getState().getValue(target.getId() + "_color");
            if (protectColor != null) {
                ContinuousEffect effect = new ProtectionChosenColorTargetEffect();
                game.addEffect(effect, source);
                ObjectColor color = target.getColor(game);
                for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                    if (!permanent.getId().equals(target.getId()) && permanent.getColor(game).shares(color)) {
                        game.getState().setValue(permanent.getId() + "_color", colorChoice.getColor());
                        effect.setTargetPointer(new FixedTarget(permanent, game));
                        game.addEffect(effect, source);
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ObjectColor(mage.ObjectColor) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ChoiceColor(mage.choices.ChoiceColor)

Example 14 with Player

use of mage.players.Player in project mage by magefree.

the class BorderlandExplorerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        // Store for each player the cards to discard, that's important because all discard shall happen at the same time
        Map<UUID, Cards> cardsToDiscard = new HashMap<>();
        // Store for each player the lands to reveal, that's important because all reveals shall happen at the same time
        Map<UUID, Cards> cardsToReveal = new HashMap<>();
        // choose cards to discard
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Target target = new TargetDiscard(0, 1, new FilterCard(), playerId);
                player.chooseTarget(outcome, target, source, game);
                Cards cards = new CardsImpl(target.getTargets());
                cardsToDiscard.put(playerId, cards);
            }
        }
        // discard all chosen cards
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToDiscard.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        player.discard(card, false, source, game);
                    }
                }
            }
        }
        // search for a land for each player that discarded
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToDiscard.get(playerId);
                if (cardsPlayer != null && !cardsPlayer.isEmpty()) {
                    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
                    if (player.searchLibrary(target, source, game)) {
                        if (!target.getTargets().isEmpty()) {
                            Cards cards = new CardsImpl(target.getTargets());
                            cards.addAll(target.getTargets());
                            cardsToReveal.put(playerId, cards);
                        }
                    }
                }
            }
        }
        // reveal the searched lands, put in hands, and shuffle
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToReveal.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        Cards cards = new CardsImpl(game.getCard(cardId));
                        if (card != null && !cards.isEmpty()) {
                            player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game);
                            player.moveCards(card, Zone.HAND, source, game);
                            player.shuffleLibrary(source, game);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) MageObject(mage.MageObject) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 15 with Player

use of mage.players.Player in project mage by magefree.

the class BondOfPassionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
        permanent.untap(game);
        effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
    }
    Permanent permanent2 = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (permanent2 != null) {
        permanent2.damage(2, source.getSourceId(), source, game);
    } else {
        Player player = game.getPlayer(source.getTargets().get(1).getFirstTarget());
        if (player != null) {
            player.damage(2, source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Aggregations

Player (mage.players.Player)3909 Permanent (mage.game.permanent.Permanent)1705 Card (mage.cards.Card)1099 UUID (java.util.UUID)962 MageObject (mage.MageObject)556 FilterCard (mage.filter.FilterCard)515 CardsImpl (mage.cards.CardsImpl)498 FixedTarget (mage.target.targetpointer.FixedTarget)387 TargetPermanent (mage.target.TargetPermanent)353 Cards (mage.cards.Cards)345 TargetCard (mage.target.TargetCard)328 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)317 TargetPlayer (mage.target.TargetPlayer)312 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)301 FilterPermanent (mage.filter.FilterPermanent)292 Target (mage.target.Target)289 OneShotEffect (mage.abilities.effects.OneShotEffect)230 ContinuousEffect (mage.abilities.effects.ContinuousEffect)227 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)207 Effect (mage.abilities.effects.Effect)170