Search in sources :

Example 16 with Game

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

the class KotoseTheSilentSpiderWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.CLEANUP_STEP_POST) {
        morMap.entrySet().removeIf(e -> !e.getKey().zoneCounterIsCurrent(game));
        morMap.values().stream().flatMap(Collection::stream).map(set -> set.removeIf(mor -> !mor.zoneCounterIsCurrent(game)));
        morMap.values().removeIf(Set::isEmpty);
        return;
    }
    if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
        return;
    }
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null) {
        return;
    }
    morMap.getOrDefault(event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()).removeIf(set -> set.stream().anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId()) && mor.getZoneChangeCounter() + 1 == spell.getZoneChangeCounter(game)));
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Spell(mage.game.stack.Spell) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) Ability(mage.abilities.Ability) Spell(mage.game.stack.Spell)

Example 17 with Game

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

the class PsychicTheftWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.SPELL_CAST) {
        return;
    }
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null || spell.getCard() == null || spell.getCard().getMainCard() == null) {
        return;
    }
    map.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>()).add(new MageObjectReference(spell.getCard().getMainCard(), game));
}
Also used : java.util(java.util) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) Spell(mage.game.stack.Spell) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 18 with Game

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

the class TestOfTalentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    MageObject targetObject = game.getObject(stackObject.getSourceId());
    String cardName;
    if (targetObject instanceof Card) {
        cardName = targetObject.getName();
    } else {
        cardName = "";
    }
    UUID searchPlayerId = stackObject.getControllerId();
    Player player = game.getPlayer(searchPlayerId);
    if (player == null) {
        return false;
    }
    int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    game.getStack().counter(source.getFirstTarget(), source, game);
    this.applySearchAndExile(game, source, cardName, searchPlayerId);
    int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    if (previousCount > newCount) {
        player.drawCards(previousCount - newCount, source, game);
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card) Ability(mage.abilities.Ability) TargetSpell(mage.target.TargetSpell) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Objects(java.util.Objects) UUID(java.util.UUID) Card(mage.cards.Card)

Example 19 with Game

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

the class NassariDeanOfExpressionTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getLibrary).map(p -> p.getFromTop(game)).forEach(cards::add);
    player.moveCards(cards, Zone.EXILED, source, game);
    cards.retainZone(Zone.EXILED, game);
    if (cards.isEmpty()) {
        return false;
    }
    for (Card card : cards.getCards(game)) {
        CardUtil.makeCardPlayable(game, source, card, Duration.EndOfTurn, true);
    }
    return true;
}
Also used : TargetCardInHand(mage.target.common.TargetCardInHand) SpellCastControllerTriggeredAbility(mage.abilities.common.SpellCastControllerTriggeredAbility) MageObjectReference(mage.MageObjectReference) Player(mage.players.Player) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetCard(mage.target.TargetCard) MageObject(mage.MageObject) mage.constants(mage.constants) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) StaticFilters(mage.filter.StaticFilters) ApprovingObject(mage.ApprovingObject) mage.cards(mage.cards) Condition(mage.abilities.condition.Condition) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Objects(java.util.Objects) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) SpellAbility(mage.abilities.SpellAbility) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect) Player(mage.players.Player) mage.cards(mage.cards) TargetCard(mage.target.TargetCard)

Example 20 with Game

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

the class WallOfStolenIdentityCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    final Permanent sourcePermanent = permanent;
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
    target.setRequired(true);
    if (source instanceof SimpleStaticAbility) {
        target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
        target.setRequired(false);
        target.setNotTarget(true);
    }
    if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
        return false;
    }
    controller.choose(Outcome.Copy, target, source.getSourceId(), game);
    Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
    if (copyFromPermanent == null) {
        return false;
    }
    game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {

        @Override
        public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
            blueprint.addSubType(SubType.WALL);
            blueprint.getAbilities().add(DefenderAbility.getInstance());
            return true;
        }
    });
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new TapTargetEffect(), false, "tap the copied creature " + "and it doesn't untap during its controller's untap step for as long as you control {this}");
    ability.addEffect(new DontUntapInControllersUntapStepTargetEffect(Duration.WhileControlled));
    ability.getEffects().setTargetPointer(new FixedTarget(copyFromPermanent, game));
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DefenderAbility(mage.abilities.keyword.DefenderAbility) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) MageObject(mage.MageObject) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Game(mage.game.Game) CopyApplier(mage.util.functions.CopyApplier) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TapTargetEffect(mage.abilities.effects.common.TapTargetEffect) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) DontUntapInControllersUntapStepTargetEffect(mage.abilities.effects.common.DontUntapInControllersUntapStepTargetEffect)

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