Search in sources :

Example 36 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class SwitchPowerToughnessAllEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        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 creature = it.next().getPermanent(game);
                if (creature != null) {
                    int power = creature.getPower().getValue();
                    creature.getPower().setValue(creature.getToughness().getValue());
                    creature.getToughness().setValue(power);
                } else {
                    it.remove();
                }
            }
        } else {
            for (Permanent creature : game.getState().getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
                int power = creature.getPower().getValue();
                creature.getPower().setValue(creature.getToughness().getValue());
                creature.getToughness().setValue(power);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Example 37 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class LoseAbilityAllEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    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
            // LKI is neccessary for "dies triggered abilities" to work given to permanets  (e.g. Showstopper)
            Permanent perm = it.next().getPermanentOrLKIBattlefield(game);
            if (perm != null) {
                perm.removeAbilities(ability, source.getSourceId(), game);
            } else {
                it.remove();
                if (affectedObjectList.isEmpty()) {
                    discard();
                }
            }
        }
    } else {
        for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
                System.out.println(game.getTurn() + ", " + game.getPhase() + ": " + "remove from size " + perm.getAbilities().size());
                perm.removeAbilities(ability, source.getSourceId(), game);
            }
        }
    }
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 38 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GainAbilityTargetEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    if (durationPhaseStep != null) {
        durationPlayerId = source.getControllerId();
        sameStep = true;
    }
    // must support dynamic targets from static ability and static targets from activated abilities
    if (this.affectedObjectsSet) {
        // target permanents (by default)
        targetPointer.getTargets(game, source).stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> {
            this.affectedObjectList.add(new MageObjectReference(permanent, game));
        });
        // target cards with linked permanents
        if (this.useOnCard) {
            targetPointer.getTargets(game, source).stream().map(game::getCard).filter(Objects::nonNull).forEach(card -> {
                this.affectedObjectList.add(new MageObjectReference(card, game));
            });
            waitingCardPermanent = true;
            if (this.affectedObjectList.size() > 1) {
                throw new IllegalArgumentException("Gain ability can't target a multiple cards (unsupported)");
            }
        }
    }
}
Also used : MageObjectReference(mage.MageObjectReference)

Example 39 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class FireGiantsFuryMayPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    game.addDelayedTriggeredAbility(new FireGiantsFuryDelayedTriggeredAbility(new MageObjectReference(permanent, game)), source);
    return true;
}
Also used : FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference)

Example 40 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class HopeOfGhirapurCombatDamageWatcher method playerGotCombatDamage.

/**
 * Checks if the current object has damaged the player during the current
 * turn.
 *
 * @param objectId
 * @param playerId
 * @return
 */
public boolean playerGotCombatDamage(UUID objectId, UUID playerId, Game game) {
    StackObject stackObject = game.getState().getStack().getStackObject(objectId);
    MageObjectReference mor;
    if (stackObject instanceof StackAbility) {
        // This is neccessary because the source object was sacrificed as cost and the correct zone change counter for target calid check can only be get from stack
        mor = new MageObjectReference(objectId, ((StackAbility) stackObject).getSourceObjectZoneChangeCounter(), game);
    } else {
        mor = new MageObjectReference(objectId, game);
    }
    if (combatDamagedPlayers.containsKey(mor)) {
        return combatDamagedPlayers.get(mor).contains(playerId);
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) MageObjectReference(mage.MageObjectReference) StackAbility(mage.game.stack.StackAbility)

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