Search in sources :

Example 96 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BecomesFaceDownCreatureAllEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
        if (!perm.isFaceDown(game) && !perm.isTransformable()) {
            affectedObjectList.add(new MageObjectReference(perm, game));
            perm.setFaceDown(true, game);
            // check for Morph
            Card card = game.getCard(perm.getId());
            if (card != null) {
                for (Ability ability : card.getAbilities(game)) {
                    if (ability instanceof MorphAbility) {
                        this.turnFaceUpAbilityMap.put(card.getId(), new TurnFaceUpAbility(((MorphAbility) ability).getMorphCosts()));
                    }
                }
            }
        }
    }
}
Also used : TurnFaceUpAbility(mage.abilities.common.TurnFaceUpAbility) MorphAbility(mage.abilities.keyword.MorphAbility) Ability(mage.abilities.Ability) MorphAbility(mage.abilities.keyword.MorphAbility) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) TurnFaceUpAbility(mage.abilities.common.TurnFaceUpAbility) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 97 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BoostOpponentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (this.affectedObjectsSet) {
        for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
            // filter may not be used again, because object can have changed filter relevant attributes but still geets boost
            Permanent perm = it.next().getPermanent(game);
            if (perm != null) {
                if (opponents.contains(perm.getControllerId())) {
                    perm.addPower(power);
                    perm.addToughness(toughness);
                }
            } else {
                it.remove();
            }
        }
    } else {
        for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            if (opponents.contains(perm.getControllerId())) {
                perm.addPower(power);
                perm.addToughness(toughness);
            }
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 98 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BoostSourceEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    if (affectedObjectsSet) {
        try {
            affectedObjectList.add(new MageObjectReference(source.getSourceId(), game));
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(BoostSourceEffect.class).error("Could not get sourceId reference: " + source.getRule());
        }
    }
    if (lockedIn) {
        power = StaticValue.get(power.calculate(game, source, this));
        toughness = StaticValue.get(toughness.calculate(game, source, this));
    }
}
Also used : MageObjectReference(mage.MageObjectReference)

Example 99 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class AegarTheFreezingFlameWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.DAMAGED_PERMANENT) {
        return;
    }
    DamagedEvent dEvent = (DamagedEvent) event;
    MageObject sourceObject = game.getObject(event.getSourceId());
    if (sourceObject == null) {
        return;
    }
    if (game.getSpellOrLKIStack(event.getSourceId()) == null && !sourceObject.hasSubtype(SubType.GIANT, game) && !sourceObject.hasSubtype(SubType.WIZARD, game)) {
        return;
    }
    playerMap.computeIfAbsent(game.getControllerId(event.getSourceId()), x -> new HashSet<>()).add(new MageObjectReference(event.getTargetId(), game));
}
Also used : java.util(java.util) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) MageObjectReference(mage.MageObjectReference) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) DamagedEvent(mage.game.events.DamagedEvent) MageObject(mage.MageObject) mage.constants(mage.constants) DamagedEvent(mage.game.events.DamagedEvent) MageObject(mage.MageObject) MageObjectReference(mage.MageObjectReference)

Example 100 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BlazingEffigyWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.DAMAGED_PERMANENT) {
        if (!event.getSourceId().equals(event.getTargetId())) {
            MageObjectReference damageSourceRef = new MageObjectReference(event.getSourceId(), game);
            MageObjectReference damageTargetRef = new MageObjectReference(event.getTargetId(), game);
            if (game.getPermanentOrLKIBattlefield(event.getSourceId()) != null && game.getPermanentOrLKIBattlefield(event.getSourceId()).getName().equals("Blazing Effigy")) {
                damagedObjects.putIfAbsent(damageTargetRef, 0);
                damagedObjects.compute(damageTargetRef, (k, damage) -> damage + event.getAmount());
            }
        }
    }
}
Also used : MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)250 Permanent (mage.game.permanent.Permanent)147 Player (mage.players.Player)76 UUID (java.util.UUID)47 Card (mage.cards.Card)45 Ability (mage.abilities.Ability)34 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)33 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)26 OneShotEffect (mage.abilities.effects.OneShotEffect)24 FilterPermanent (mage.filter.FilterPermanent)23 Game (mage.game.Game)22 Spell (mage.game.stack.Spell)21 TargetPermanent (mage.target.TargetPermanent)20 CardImpl (mage.cards.CardImpl)18 CardSetInfo (mage.cards.CardSetInfo)18 MageObject (mage.MageObject)17 Effect (mage.abilities.effects.Effect)16 HashSet (java.util.HashSet)15 mage.constants (mage.constants)14 GameEvent (mage.game.events.GameEvent)13