Search in sources :

Example 91 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class VisionCharmEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceLandType();
        if (!controller.choose(outcome, choice, game)) {
            discard();
            return;
        }
        targetLandType = choice.getChoice();
        choice = new ChoiceBasicLandType();
        if (!controller.choose(outcome, choice, game)) {
            discard();
            return;
        }
        targetBasicLandType = SubType.byDescription(choice.getChoice());
        if (targetLandType == null || targetBasicLandType == null) {
            this.discard();
            return;
        }
    } else {
        this.discard();
        return;
    }
    FilterPermanent filter = new FilterLandPermanent();
    filter.add(SubType.byDescription(targetLandType).getPredicate());
    if (this.affectedObjectsSet) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
            affectedObjectList.add(new MageObjectReference(permanent, game));
        }
    }
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceLandType(mage.choices.ChoiceLandType) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) ChoiceBasicLandType(mage.choices.ChoiceBasicLandType) MageObjectReference(mage.MageObjectReference)

Example 92 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class AddCardSubTypeSourceEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    affectedObjectList.add(new MageObjectReference(source.getSourceId(), game));
}
Also used : MageObjectReference(mage.MageObjectReference)

Example 93 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BoostAllEffect 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
            Permanent permanent = it.next().getPermanent(game);
            if (permanent != null) {
                permanent.addPower(power.calculate(game, source, this));
                permanent.addToughness(toughness.calculate(game, source, this));
            } else {
                // no longer on the battlefield, remove reference to object
                it.remove();
            }
        }
    } else {
        setRuntimeData(source, game);
        for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) {
                perm.addPower(power.calculate(game, source, this));
                perm.addToughness(toughness.calculate(game, source, this));
            }
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Example 94 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BoostControlledEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    if (this.affectedObjectsSet) {
        for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
            if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
                affectedObjectList.add(new MageObjectReference(perm, game));
            }
        }
    }
    if (this.lockedIn) {
        power = StaticValue.get(power.calculate(game, source, this));
        toughness = StaticValue.get(toughness.calculate(game, source, this));
    }
}
Also used : Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Example 95 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BoostControlledEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (this.affectedObjectsSet) {
        for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
            Permanent permanent = it.next().getPermanent(game);
            if (permanent != null) {
                permanent.addPower(power.calculate(game, source, this));
                permanent.addToughness(toughness.calculate(game, source, this));
            } else {
                // no longer on the battlefield, remove reference to object
                it.remove();
            }
        }
    } else {
        for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
            if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
                perm.addPower(power.calculate(game, source, this));
                perm.addToughness(toughness.calculate(game, source, this));
            }
        }
    }
    return true;
}
Also used : 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