Search in sources :

Example 1 with AbilityImpl

use of mage.abilities.AbilityImpl in project mage by magefree.

the class BeamsplitterMageApplier method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!isControlledBy(event.getPlayerId())) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    if (spell.getSpellAbilities().stream().map(AbilityImpl::getModes).flatMap(m -> m.getSelectedModes().stream().map(m::get)).filter(Objects::nonNull).map(Mode::getTargets).flatMap(Collection::stream).filter(t -> !t.isNotTarget()).map(Target::getTargets).flatMap(Collection::stream).anyMatch(uuid -> !getSourceId().equals(uuid) && uuid != null)) {
        return false;
    }
    this.getEffects().setValue("spellCast", spell);
    return true;
}
Also used : Target(mage.target.Target) java.util(java.util) Zone(mage.constants.Zone) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) SubType(mage.constants.SubType) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) Player(mage.players.Player) StackObjectCopyApplier(mage.util.functions.StackObjectCopyApplier) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) Spell(mage.game.stack.Spell)

Example 2 with AbilityImpl

use of mage.abilities.AbilityImpl in project mage by magefree.

the class RadiateEffect method prepareCopiesWithTargets.

@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
    List<MageObjectReferencePredicate> predicates = new ArrayList<>();
    UUID targeted = ((Spell) stackObject).getSpellAbilities().stream().map(AbilityImpl::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    return predicates;
}
Also used : Target(mage.target.Target) StaticFilters(mage.filter.StaticFilters) java.util(java.util) CopySpellForEachItCouldTargetEffect(mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect) TargetAddress(mage.util.TargetAddress) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) FilterInstantOrSorcerySpell(mage.filter.common.FilterInstantOrSorcerySpell) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) FilterSpell(mage.filter.FilterSpell) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) ObjectSourcePlayerPredicate(mage.filter.predicate.ObjectSourcePlayerPredicate) Ability(mage.abilities.Ability) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetSpell(mage.target.TargetSpell) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) FilterInstantOrSorcerySpell(mage.filter.common.FilterInstantOrSorcerySpell) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) MageObjectReference(mage.MageObjectReference)

Example 3 with AbilityImpl

use of mage.abilities.AbilityImpl in project mage by magefree.

the class ReflectiveGolemTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!isControlledBy(event.getPlayerId())) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    if (spell.getSpellAbilities().stream().map(AbilityImpl::getModes).flatMap(m -> m.getSelectedModes().stream().map(m::get)).filter(Objects::nonNull).map(Mode::getTargets).flatMap(Collection::stream).filter(t -> !t.isNotTarget()).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).distinct().filter(getSourceId()::equals).count() != 1) {
        return false;
    }
    this.getEffects().setTargetPointer(new FixedTarget(spell, game));
    return true;
}
Also used : Target(mage.target.Target) Zone(mage.constants.Zone) CopyTargetSpellEffect(mage.abilities.effects.common.CopyTargetSpellEffect) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) Collection(java.util.Collection) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Mode(mage.abilities.Mode) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Spell(mage.game.stack.Spell) FixedTarget(mage.target.targetpointer.FixedTarget) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Objects(java.util.Objects) Collection(java.util.Collection) Spell(mage.game.stack.Spell)

Example 4 with AbilityImpl

use of mage.abilities.AbilityImpl in project mage by magefree.

the class SimulatedPlayer2 method addVariableXOptions.

@Override
protected void addVariableXOptions(List<Ability> options, Ability ability, int targetNum, Game game) {
    // calculate the mana that can be used for the x part
    int numAvailable = getAvailableManaProducers(game).size() - ability.getManaCosts().manaValue();
    Card card = game.getCard(ability.getSourceId());
    if (card != null && numAvailable > 0) {
        // check if variable mana costs is included and get the multiplier
        VariableManaCost variableManaCost = null;
        for (ManaCost cost : ability.getManaCostsToPay()) {
            if (cost instanceof VariableManaCost && !cost.isPaid()) {
                variableManaCost = (VariableManaCost) cost;
                // only one VariableManCost per spell (or is it possible to have more?)
                break;
            }
        }
        if (variableManaCost != null) {
            int xInstancesCount = variableManaCost.getXInstancesCount();
            for (int mana = variableManaCost.getMinX(); mana <= numAvailable; mana++) {
                if (mana % xInstancesCount == 0) {
                    // use only values dependant from multiplier
                    // find possible X value to pay
                    int xAnnounceValue = mana / xInstancesCount;
                    Ability newAbility = ability.copy();
                    VariableManaCost varCost = null;
                    for (ManaCost cost : newAbility.getManaCostsToPay()) {
                        if (cost instanceof VariableManaCost && !cost.isPaid()) {
                            varCost = (VariableManaCost) cost;
                            // only one VariableManCost per spell (or is it possible to have more?)
                            break;
                        }
                    }
                    // find real X value after replace events
                    int xMultiplier = 1;
                    if (newAbility instanceof AbilityImpl) {
                        xMultiplier = ((AbilityImpl) newAbility).handleManaXMultiplier(game, xMultiplier);
                    }
                    newAbility.getManaCostsToPay().add(new ManaCostsImpl(new StringBuilder("{").append(xAnnounceValue).append('}').toString()));
                    newAbility.getManaCostsToPay().setX(xAnnounceValue * xMultiplier, xAnnounceValue * xInstancesCount);
                    if (varCost != null) {
                        varCost.setPaid();
                    }
                    card.adjustTargets(newAbility, game);
                    // add the different possible target option for the specific X value
                    if (!newAbility.getTargets().getUnchosen().isEmpty()) {
                        addTargetOptions(options, newAbility, targetNum, game);
                    }
                }
            }
        }
    }
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) AbilityImpl(mage.abilities.AbilityImpl) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Card(mage.cards.Card) VariableManaCost(mage.abilities.costs.mana.VariableManaCost)

Aggregations

AbilityImpl (mage.abilities.AbilityImpl)4 Ability (mage.abilities.Ability)3 CardImpl (mage.cards.CardImpl)3 CardSetInfo (mage.cards.CardSetInfo)3 CardType (mage.constants.CardType)3 Game (mage.game.Game)3 Spell (mage.game.stack.Spell)3 Target (mage.target.Target)3 java.util (java.util)2 MageInt (mage.MageInt)2 MageObjectReference (mage.MageObjectReference)2 Mode (mage.abilities.Mode)2 TriggeredAbilityImpl (mage.abilities.TriggeredAbilityImpl)2 SubType (mage.constants.SubType)2 Zone (mage.constants.Zone)2 StaticFilters (mage.filter.StaticFilters)2 MageObjectReferencePredicate (mage.filter.predicate.mageobject.MageObjectReferencePredicate)2 GameEvent (mage.game.events.GameEvent)2 StackObject (mage.game.stack.StackObject)2 Player (mage.players.Player)2