Search in sources :

Example 61 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FreeRangeChickenWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Integer> results = controller.rollDice(outcome, source, game, 6, 2, 0);
        int firstRoll = results.get(0);
        int secondRoll = results.get(1);
        if (firstRoll == secondRoll) {
            game.addEffect(new BoostSourceEffect(firstRoll, firstRoll, Duration.EndOfTurn), source);
        }
        FreeRangeChickenWatcher watcher = game.getState().getWatcher(FreeRangeChickenWatcher.class);
        if (watcher != null) {
            int totalRoll = firstRoll + secondRoll;
            Permanent sourcePermanent = game.getPermanent(source.getSourceId());
            if (sourcePermanent != null) {
                if (watcher.rolledThisTurn(sourcePermanent.getId(), totalRoll)) {
                    sourcePermanent.sacrifice(source, game);
                } else {
                    watcher.addRoll(sourcePermanent.getId(), totalRoll);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 62 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FracturingGustDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int destroyedPermanents = 0;
        for (Permanent permanent : game.getState().getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            if (permanent.destroy(source, game, false)) {
                ++destroyedPermanents;
            }
        }
        // needed in case a destroyed permanent did prevent life gain
        game.getState().processAction(game);
        if (destroyedPermanents > 0) {
            controller.gainLife(2 * destroyedPermanents, game, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent)

Example 63 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FractalHarnessDoubleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Token token = new FractalToken();
    token.putOntoBattlefield(1, game, source, source.getControllerId());
    int xValue = ManacostVariableValue.ETB.calculate(game, source, this);
    boolean flag = true;
    for (UUID tokenId : token.getLastAddedTokenIds()) {
        Permanent permanent = game.getPermanent(tokenId);
        if (permanent == null) {
            continue;
        }
        if (flag && permanent.addAttachment(source.getSourceId(), source, game)) {
            flag = false;
        }
        permanent.addCounters(CounterType.P1P1.createInstance(xValue), source.getControllerId(), source, game);
    }
    return true;
}
Also used : FractalToken(mage.game.permanent.token.FractalToken) Permanent(mage.game.permanent.Permanent) FractalToken(mage.game.permanent.token.FractalToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID)

Example 64 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class GlyphOfDelusionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (source.getTargets().get(1) != null) {
        Permanent targetPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
        if (targetPermanent != null) {
            targetPermanent.addCounters(CounterType.GLYPH.createInstance(targetPermanent.getPower().getValue()), source.getControllerId(), source, game);
            SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousRuleModifyingEffect(new DontUntapInControllersUntapStepSourceEffect(), new SourceHasCounterCondition(CounterType.GLYPH)).setText("This creature doesn't untap during your untap step if it has a glyph counter on it"));
            GainAbilityTargetEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom);
            effect.setTargetPointer(new FixedTarget(targetPermanent.getId(), game));
            game.addEffect(effect, source);
            BeginningOfUpkeepTriggeredAbility ability2 = new BeginningOfUpkeepTriggeredAbility(new RemoveCounterSourceEffect(CounterType.GLYPH.createInstance()), TargetController.YOU, false);
            GainAbilityTargetEffect effect2 = new GainAbilityTargetEffect(ability2, Duration.Custom);
            effect2.setTargetPointer(new FixedTarget(targetPermanent.getId(), game));
            game.addEffect(effect2, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) DontUntapInControllersUntapStepSourceEffect(mage.abilities.effects.common.DontUntapInControllersUntapStepSourceEffect) SourceHasCounterCondition(mage.abilities.condition.common.SourceHasCounterCondition) ConditionalContinuousRuleModifyingEffect(mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect)

Example 65 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class GlyphOfReincarnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetWall = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && targetWall != null) {
        BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
        if (watcher != null) {
            Map<UUID, Player> destroyed = new HashMap<>();
            for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                if (!creature.getId().equals(targetWall.getId())) {
                    if (watcher.creatureHasBlockedAttacker(new MageObjectReference(creature, game), new MageObjectReference(targetWall, game), game)) {
                        if (creature.destroy(source, game, true) && game.getState().getZone(creature.getId()) == Zone.GRAVEYARD) {
                            // If a commander is replaced to command zone, the creature does not die
                            Player permController = game.getPlayer(creature.getControllerId());
                            if (permController != null) {
                                destroyed.put(creature.getId(), permController);
                            }
                        }
                    }
                }
            }
            // onto the battlefield under its owner’s control
            for (Map.Entry<UUID, Player> entry : destroyed.entrySet()) {
                Permanent permanent = (Permanent) game.getLastKnownInformation(entry.getKey(), Zone.BATTLEFIELD);
                Player player = entry.getValue();
                if (permanent != null && player != null) {
                    FilterCreatureCard filter = new FilterCreatureCard("a creature card from " + player.getName() + "'s graveyard");
                    filter.add(new OwnerIdPredicate(player.getId()));
                    Target targetCreature = new TargetCardInGraveyard(filter);
                    targetCreature.setNotTarget(true);
                    if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) {
                        Card card = game.getCard(targetCreature.getFirstTarget());
                        if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
                            controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) BlockedAttackerWatcher(mage.watchers.common.BlockedAttackerWatcher) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) MageObjectReference(mage.MageObjectReference)

Aggregations

Permanent (mage.game.permanent.Permanent)3269 Player (mage.players.Player)1706 UUID (java.util.UUID)665 TargetPermanent (mage.target.TargetPermanent)571 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)541 FixedTarget (mage.target.targetpointer.FixedTarget)496 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)467 FilterPermanent (mage.filter.FilterPermanent)466 Card (mage.cards.Card)425 MageObject (mage.MageObject)246 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)226 Target (mage.target.Target)225 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)217 ContinuousEffect (mage.abilities.effects.ContinuousEffect)207 Effect (mage.abilities.effects.Effect)183 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)179 Test (org.junit.Test)179 OneShotEffect (mage.abilities.effects.OneShotEffect)175 FilterCard (mage.filter.FilterCard)158 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)153