Search in sources :

Example 31 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CombatDamageToCreatureWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.DAMAGED_PERMANENT || !((DamagedEvent) event).isCombatDamage()) {
        return;
    }
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent == null || !permanent.isCreature(game)) {
        return;
    }
    MageObjectReference damageSource = new MageObjectReference(event.getSourceId(), game);
    dealtCombatDamageToCreature.add(damageSource);
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 32 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class WojekSirenBoostEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (target != null) {
        affectedObjectList.add(new MageObjectReference(target, game));
        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)) {
                affectedObjectList.add(new MageObjectReference(permanent, game));
            }
        }
    }
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ObjectColor(mage.ObjectColor) MageObjectReference(mage.MageObjectReference)

Example 33 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CopyEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    // must copy the default side of the card (example: clone with mdf card)
    if (!(copyFromObject instanceof Permanent) && (copyFromObject instanceof Card)) {
        Card newBluePrint = CardUtil.getDefaultCardSideForBattlefield(game, (Card) copyFromObject);
        this.copyFromObject = new PermanentCard(newBluePrint, source.getControllerId(), game);
    }
    Permanent permanent = game.getPermanent(copyToObjectId);
    if (permanent != null) {
        affectedObjectList.add(new MageObjectReference(permanent, game));
    } else if (source.getAbilityType() == AbilityType.STATIC) {
        // for replacement effects that let a permanent enter the battlefield as a copy of another permanent we need to apply that copy
        // before the permanent is added to the battlefield
        permanent = game.getPermanentEntering(copyToObjectId);
        if (permanent != null) {
            copyToPermanent(permanent, game, source);
            // set reference to the permanent later on the battlefield so we have to add already one (if no token) to the zone change counter
            int ZCCDiff = 1;
            if (permanent instanceof PermanentToken) {
                ZCCDiff = 0;
            }
            affectedObjectList.add(new MageObjectReference(permanent.getId(), game.getState().getZoneChangeCounter(copyToObjectId) + ZCCDiff, game));
        }
    }
}
Also used : Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) MageObjectReference(mage.MageObjectReference) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Example 34 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class DamageMultiEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    this.damagedSet.clear();
    if (source.getTargets().isEmpty()) {
        return true;
    }
    Target multiTarget = source.getTargets().get(0);
    for (UUID target : multiTarget.getTargets()) {
        Permanent permanent = game.getPermanent(target);
        if (permanent != null) {
            if (permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game, false, true) > 0) {
                damagedSet.add(new MageObjectReference(permanent, game));
            }
        } else {
            Player player = game.getPlayer(target);
            if (player != null) {
                player.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 35 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class SetPowerToughnessAllEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    if (affectedObjectsSet) {
        for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            affectedObjectList.add(new MageObjectReference(perm, game));
        }
    }
    if (lockedInPT) {
        power = StaticValue.get(power.calculate(game, source, this));
        toughness = StaticValue.get(toughness.calculate(game, source, this));
    }
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) 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