Search in sources :

Example 96 with MageObject

use of mage.MageObject in project mage by magefree.

the class RaidersKarveEffect 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) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return true;
    }
    controller.lookAtCards(sourceObject.getIdName(), new CardsImpl(card), game);
    if (!card.isLand(game)) {
        return true;
    }
    String message = "Put " + card.getLogName() + " onto the battlefield tapped?";
    if (controller.chooseUse(Outcome.PutLandInPlay, message, source, game)) {
        controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
    }
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 97 with MageObject

use of mage.MageObject in project mage by magefree.

the class RhysticScryingEffect 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) {
        boolean result = true;
        boolean doEffect = false;
        Cost cost = ManaUtil.createManaCost(2, false);
        // check if any player is willing to pay
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.canRespond() && cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " for " + sourceObject.getLogName() + "?", source, game)) {
                cost.clearPaid();
                if (cost.pay(source, game, source, player.getId(), false, null)) {
                    if (!game.isSimulation()) {
                        game.informPlayers(player.getLogName() + " pays the cost for " + sourceObject.getLogName());
                    }
                    doEffect = true;
                    break;
                }
            }
        }
        // do the effects if anybody paid
        if (doEffect) {
            controller.discard(3, false, false, source, game);
        }
        return result;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost)

Example 98 with MageObject

use of mage.MageObject in project mage by magefree.

the class RhysticStudyDrawEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && opponent != null && sourceObject != null) {
        if (controller.chooseUse(Outcome.DrawCard, "Draw a card (" + sourceObject.getLogName() + ')', source, game)) {
            Cost cost = ManaUtil.createManaCost(1, false);
            if (opponent.chooseUse(Outcome.Benefit, "Pay {1}?", source, game) && cost.pay(source, game, source, opponent.getId(), false, null)) {
                return true;
            }
            controller.drawCards(1, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Cost(mage.abilities.costs.Cost)

Example 99 with MageObject

use of mage.MageObject in project mage by magefree.

the class RicochetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        Targets targets = new Targets();
        Ability sourceAbility = spell.getSpellAbility();
        for (UUID modeId : sourceAbility.getModes().getSelectedModes()) {
            Mode mode = sourceAbility.getModes().get(modeId);
            targets.addAll(mode.getTargets());
        }
        if (targets.size() != 1 || targets.get(0).getTargets().size() != 1) {
            return false;
        }
        Map<Player, Integer> playerRolls = new HashMap<>();
        for (UUID playerId : game.getPlayerList().copy()) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                playerRolls.put(player, 7);
            }
        }
        do {
            for (Player player : playerRolls.keySet()) {
                // bad outcome - ai must choose lowest value
                playerRolls.put(player, player.rollDice(Outcome.Detriment, source, game, 6));
            }
            int minValueInMap = Collections.min(playerRolls.values());
            for (Map.Entry<Player, Integer> mapEntry : new HashSet<>(playerRolls.entrySet())) {
                if (mapEntry.getValue() > minValueInMap) {
                    playerRolls.remove(mapEntry.getKey());
                }
            }
        } while (playerRolls.size() > 1);
        if (playerRolls.size() == 1) {
            Player loser = (Player) playerRolls.keySet().toArray()[0];
            UUID loserId = loser.getId();
            Target target = targets.get(0);
            if (target.getFirstTarget().equals(loserId)) {
                return true;
            }
            String oldTargetName = null;
            if (target.canTarget(spell.getControllerId(), loserId, sourceAbility, game)) {
                Player oldPlayer = game.getPlayer(targets.getFirstTarget());
                if (oldPlayer != null) {
                    oldTargetName = oldPlayer.getLogName();
                }
                target.clearChosen();
                target.addTarget(loserId, sourceAbility, game);
            }
            MageObject sourceObject = game.getObject(source.getSourceId());
            if (oldTargetName != null && sourceObject != null) {
                game.informPlayers(sourceObject.getLogName() + ": Changed target of " + spell.getLogName() + " from " + oldTargetName + " to " + loser.getLogName());
            }
        }
        return true;
    }
    return false;
}
Also used : SpellCastAllTriggeredAbility(mage.abilities.common.SpellCastAllTriggeredAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) HashMap(java.util.HashMap) Mode(mage.abilities.Mode) MageObject(mage.MageObject) Targets(mage.target.Targets) Spell(mage.game.stack.Spell) FilterSpell(mage.filter.FilterSpell) Target(mage.target.Target) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 100 with MageObject

use of mage.MageObject in project mage by magefree.

the class ReweaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (permanent != null && sourceObject != null) {
        if (permanent.sacrifice(source, game)) {
            Player permanentController = game.getPlayer(permanent.getControllerId());
            if (permanentController != null) {
                Library library = permanentController.getLibrary();
                if (library.hasCards()) {
                    Cards cards = new CardsImpl();
                    Card permanentCard = null;
                    for (Card card : permanentController.getLibrary().getCards(game)) {
                        cards.add(card);
                        if (card.isPermanent(game)) {
                            for (CardType cardType : permanent.getCardType(game)) {
                                if (card.getCardType(game).contains(cardType)) {
                                    permanentCard = card;
                                    break;
                                }
                            }
                        }
                    }
                    permanentController.revealCards(source, cards, game);
                    if (permanentCard != null) {
                        permanentController.moveCards(permanentCard, Zone.BATTLEFIELD, source, game);
                    }
                    permanentController.shuffleLibrary(source, game);
                }
                return true;
            }
            return false;
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) MageObject(mage.MageObject) Library(mage.players.Library) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Aggregations

MageObject (mage.MageObject)738 Player (mage.players.Player)554 Permanent (mage.game.permanent.Permanent)239 UUID (java.util.UUID)224 Card (mage.cards.Card)210 FilterCard (mage.filter.FilterCard)113 CardsImpl (mage.cards.CardsImpl)106 TargetCard (mage.target.TargetCard)91 Cards (mage.cards.Cards)73 Spell (mage.game.stack.Spell)68 FixedTarget (mage.target.targetpointer.FixedTarget)66 HashSet (java.util.HashSet)56 Ability (mage.abilities.Ability)52 ContinuousEffect (mage.abilities.effects.ContinuousEffect)51 TargetPermanent (mage.target.TargetPermanent)48 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)48 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)46 Target (mage.target.Target)44 Effect (mage.abilities.effects.Effect)42 OneShotEffect (mage.abilities.effects.OneShotEffect)41