Search in sources :

Example 66 with Game

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

the class MindlinkMechApplier method watch.

@Override
public void watch(GameEvent event, Game game) {
    Permanent vehicle;
    Permanent crewer;
    switch(event.getType()) {
        case VEHICLE_CREWED:
            vehicle = game.getPermanent(event.getTargetId());
            crewer = null;
            break;
        case CREWED_VEHICLE:
            vehicle = game.getPermanent(event.getSourceId());
            crewer = game.getPermanent(event.getTargetId());
            break;
        default:
            return;
    }
    if (vehicle == null) {
        return;
    }
    if (crewer == null) {
        crewCount.compute(new MageObjectReference(vehicle, game), (m, i) -> i == null ? 1 : Integer.sum(i, 1));
        return;
    }
    crewMap.computeIfAbsent(new MageObjectReference(vehicle, game), x -> new HashSet<>()).add(new MageObjectReference(crewer, game));
}
Also used : java.util(java.util) CopyApplier(mage.util.functions.CopyApplier) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) CrewAbility(mage.abilities.keyword.CrewAbility) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference)

Example 67 with Game

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

the class MindreaverExileEffect method canTarget.

@Override
public boolean canTarget(UUID id, Ability source, Game game) {
    Spell spell = game.getSpell(id);
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
    return super.canTarget(id, source, game) && spell != null && exileZone != null && !exileZone.isEmpty() && exileZone.getCards(game).stream().filter(Objects::nonNull).anyMatch(card -> CardUtil.haveSameNames(spell, card));
}
Also used : CounterTargetEffect(mage.abilities.effects.common.CounterTargetEffect) SubType(mage.constants.SubType) Player(mage.players.Player) CardType(mage.constants.CardType) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) HeroicAbility(mage.abilities.keyword.HeroicAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) CardSetInfo(mage.cards.CardSetInfo) FilterSpell(mage.filter.FilterSpell) Objects(java.util.Objects) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) ExileZone(mage.game.ExileZone) CardImpl(mage.cards.CardImpl) Ability(mage.abilities.Ability) Objects(java.util.Objects) ExileZone(mage.game.ExileZone) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell)

Example 68 with Game

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

the class MindleecherLookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    game.getOpponents(controller.getId()).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
    if (cards.isEmpty()) {
        return false;
    }
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    if (cards.isEmpty()) {
        return false;
    }
    cards.getCards(game).stream().forEach(card -> card.setFaceDown(true, game));
    for (Card card : cards.getCards(game)) {
        game.addEffect(new MindleecherCastFromExileEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
        game.addEffect(new MindleecherLookEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
    }
    return true;
}
Also used : mage.cards(mage.cards) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) MutateAbility(mage.abilities.keyword.MutateAbility) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) Game(mage.game.Game) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) MutatesSourceTriggeredAbility(mage.abilities.common.MutatesSourceTriggeredAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) mage.cards(mage.cards)

Example 69 with Game

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

the class PakoArcaneRetrieverWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    PakoArcaneRetrieverWatcher watcher = game.getState().getWatcher(PakoArcaneRetrieverWatcher.class);
    if (controller == null || watcher == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    game.getState().getPlayersInRange(controller.getId(), game).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(cardId -> game.getState().getZone(cardId) != Zone.EXILED);
    int counters = cards.count(StaticFilters.FILTER_CARD_NON_CREATURE, game);
    if (cards.isEmpty()) {
        return true;
    }
    cards.getCards(game).stream().filter(card -> card.addCounters(CounterType.FETCH.createInstance(), source.getControllerId(), source, game)).filter(card -> !card.isCreature(game)).forEach(card -> watcher.addCard(controller.getId(), card, game));
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null || counters == 0) {
        return true;
    }
    return permanent.addCounters(CounterType.P1P1.createInstance(counters), source.getControllerId(), source, game);
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) mage.cards(mage.cards) AttacksTriggeredAbility(mage.abilities.common.AttacksTriggeredAbility) HasteAbility(mage.abilities.keyword.HasteAbility) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Permanent(mage.game.permanent.Permanent) mage.constants(mage.constants) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) mage.cards(mage.cards) Permanent(mage.game.permanent.Permanent)

Example 70 with Game

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

the class SerpentsSoulJarWatcher method addPlayable.

static void addPlayable(Ability source, Game game) {
    MageObjectReference mor = new MageObjectReference(source);
    game.getState().getWatcher(SerpentsSoulJarWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
Also used : DiesCreatureTriggeredAbility(mage.abilities.common.DiesCreatureTriggeredAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) PayLifeCost(mage.abilities.costs.common.PayLifeCost) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) HashMap(java.util.HashMap) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) Watcher(mage.watchers.Watcher) TapSourceCost(mage.abilities.costs.common.TapSourceCost) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) ExileZone(mage.game.ExileZone) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) Map(java.util.Map) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) HashMap(java.util.HashMap) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil)

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