Search in sources :

Example 61 with Game

use of mage.game.Game in project mage by magefree.

the class ExpropriateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    // Outcome.Detriment - AI will gain control all the time (Money choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Money (gain control)", Outcome.Detriment);
    vote.doVotes(source, game);
    // extra turn
    int timeCount = vote.getVoteCount(true);
    for (int i = 0; i < timeCount; i++) {
        game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
    }
    // gain control
    if (vote.getVoteCount(false) < 1) {
        return true;
    }
    List<Permanent> toSteal = new ArrayList<>();
    for (UUID playerId : vote.getVotedFor(false)) {
        int moneyCount = vote.getVotes(playerId).stream().mapToInt(x -> x ? 0 : 1).sum();
        FilterPermanent filter = new FilterPermanent();
        filter.add(new ControllerIdPredicate(playerId));
        moneyCount = Math.min(game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game), moneyCount);
        if (moneyCount == 0) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(moneyCount, filter);
        target.setNotTarget(true);
        player.choose(Outcome.GainControl, target, source.getSourceId(), game);
        target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(toSteal::add);
    }
    game.addEffect(new GainControlTargetEffect(Duration.Custom, true, source.getControllerId()).setTargetPointer(new FixedTargets(toSteal, game)), source);
    return true;
}
Also used : GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) ArrayList(java.util.ArrayList) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FixedTargets(mage.target.targetpointer.FixedTargets) TurnMod(mage.game.turn.TurnMod) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) TurnMod(mage.game.turn.TurnMod) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 62 with Game

use of mage.game.Game in project mage by magefree.

the class FacelessAgentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getLibrary().count(filterAnyType, game) < 1) {
        return false;
    }
    Map<SubType, Integer> typeMap = player.getLibrary().getCards(game).stream().filter(card -> !card.isAllCreatureTypes(game)).map(card -> card.getSubtype(game)).flatMap(Collection::stream).filter(subType -> subType.getSubTypeSet() == SubTypeSet.CreatureType).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
    if (typeMap.isEmpty()) {
        return player.seekCard(filterAnyType, source, game);
    }
    int max = typeMap.values().stream().mapToInt(x -> x).max().orElse(0);
    FilterCard filter = new FilterCreatureCard();
    filter.add(Predicates.or(typeMap.entrySet().stream().filter(entry -> entry.getValue() == max).map(Map.Entry::getKey).map(SubType::getPredicate).collect(Collectors.toSet())));
    return player.seekCard(filter, source, game);
}
Also used : FilterCard(mage.filter.FilterCard) Predicate(mage.filter.predicate.Predicate) SubTypeSet(mage.constants.SubTypeSet) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Collection(java.util.Collection) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Map(java.util.Map) ChangelingAbility(mage.abilities.keyword.ChangelingAbility) CardType(mage.constants.CardType) Card(mage.cards.Card) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) SubType(mage.constants.SubType) Collection(java.util.Collection)

Example 63 with Game

use of mage.game.Game in project mage by magefree.

the class GorgingVultureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int lifeToGain = player.millCards(4, source, game).getCards(game).stream().filter(card1 -> card1.isCreature(game)).mapToInt(card -> game.getState().getZone(card.getId()) == Zone.GRAVEYARD ? 1 : 0).sum();
    return player.gainLife(lifeToGain, game, source) > 0;
}
Also used : Zone(mage.constants.Zone) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) Player(mage.players.Player)

Example 64 with Game

use of mage.game.Game in project mage by magefree.

the class HandOfVecnaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getHand().size() < 1) {
        return false;
    }
    Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
    Permanent equipped = game.getPermanent(sourcePermanent != null ? sourcePermanent.getAttachedTo() : null);
    List<Permanent> chooseable = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    if (equipped != null) {
        chooseable.add(equipped);
    }
    Permanent toBoost;
    switch(chooseable.size()) {
        case 0:
            return false;
        case 1:
            toBoost = chooseable.get(0);
            break;
        default:
            FilterPermanent filter = new FilterPermanent("a creature to give +X/+X to");
            filter.add(Predicates.or(chooseable.stream().map(permanent -> new MageObjectReferencePredicate(permanent, game)).collect(Collectors.toList())));
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            player.choose(outcome, target, source.getSourceId(), game);
            toBoost = game.getPermanent(target.getFirstTarget());
    }
    int xValue = player.getHand().size();
    game.addEffect(new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn).setTargetPointer(new FixedTarget(toBoost, game)), source);
    return true;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) CardsInControllerHandCount(mage.abilities.dynamicvalue.common.CardsInControllerHandCount) PayLifeCost(mage.abilities.costs.common.PayLifeCost) EquipAbility(mage.abilities.keyword.EquipAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) TargetPermanent(mage.target.TargetPermanent)

Example 65 with Game

use of mage.game.Game in project mage by magefree.

the class KethisTheHiddenHandGraveyardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    controller.getGraveyard().getCards(game).stream().filter(card -> affectedObjectList.stream().anyMatch(mor -> mor.refersTo(card, game))).forEach(card -> {
        Ability ability = new SimpleStaticAbility(Zone.GRAVEYARD, new KethisTheHiddenHandGraveyardEffect());
        ability.setSourceId(card.getId());
        ability.setControllerId(card.getOwnerId());
        game.getState().addOtherAbility(card, ability);
    });
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) MageObjectReference(mage.MageObjectReference) UUID(java.util.UUID) MageInt(mage.MageInt) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) CardImpl(mage.cards.CardImpl) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) Card(mage.cards.Card) mage.constants(mage.constants) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) Ability(mage.abilities.Ability) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility)

Aggregations

Game (mage.game.Game)212 Ability (mage.abilities.Ability)139 Player (mage.players.Player)126 UUID (java.util.UUID)117 OneShotEffect (mage.abilities.effects.OneShotEffect)104 CardSetInfo (mage.cards.CardSetInfo)102 CardImpl (mage.cards.CardImpl)100 CardType (mage.constants.CardType)82 Outcome (mage.constants.Outcome)78 Permanent (mage.game.permanent.Permanent)66 MageInt (mage.MageInt)60 mage.constants (mage.constants)47 Zone (mage.constants.Zone)46 GameEvent (mage.game.events.GameEvent)44 Objects (java.util.Objects)41 StaticFilters (mage.filter.StaticFilters)40 Collectors (java.util.stream.Collectors)35 SubType (mage.constants.SubType)34 Card (mage.cards.Card)32 MageObjectReference (mage.MageObjectReference)30