Search in sources :

Example 6 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class PetrifiedWoodKinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    DamageDoneWatcher watcher = game.getState().getWatcher(DamageDoneWatcher.class);
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (player == null || watcher == null || permanent == null) {
        return false;
    }
    // the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
    int amount = 0;
    for (UUID opponentId : game.getOpponents(player.getId())) {
        MageObjectReference mor = new MageObjectReference(opponentId, game);
        amount += watcher.getDamagedObjects().getOrDefault(mor, 0);
    }
    permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game, appliedEffects);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) DamageDoneWatcher(mage.watchers.common.DamageDoneWatcher) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 7 with MageObjectReference

use of mage.MageObjectReference 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 8 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class RepercussionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Integer playerDamage = (Integer) this.getValue(RepercussionTriggeredAbility.PLAYER_DAMAGE_AMOUNT_KEY);
    MageObjectReference mor = (MageObjectReference) this.getValue(RepercussionTriggeredAbility.TRIGGERING_CREATURE_KEY);
    if (playerDamage != null && mor != null) {
        Permanent creature = mor.getPermanentOrLKIBattlefield(game);
        if (creature != null) {
            Player player = game.getPlayer(creature.getControllerId());
            if (player != null) {
                player.damage(playerDamage, source.getSourceId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 9 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class RepercussionEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent == null || !permanent.isCreature(game)) {
        return false;
    }
    getEffects().setValue(PLAYER_DAMAGE_AMOUNT_KEY, event.getAmount());
    getEffects().setValue(TRIGGERING_CREATURE_KEY, new MageObjectReference(event.getTargetId(), game));
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 10 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class AttackIfAbleTargetRandoOpponentSourceEffect method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE) {
        // Remove previous attacking creatures of the current combat's player if info exists
        attackedLastCombatPlayers.remove(game.getCombat().getAttackingPlayerId());
    }
    if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
        // remember which attacker attacked which player
        Map<MageObjectReference, UUID> attackedPlayers = new HashMap<>();
        for (UUID attackerId : game.getCombat().getAttackers()) {
            Permanent attacker = game.getPermanent(attackerId);
            if (attacker != null) {
                attackedPlayers.put(new MageObjectReference(attacker, game), game.getCombat().getDefenderId(attackerId));
            }
        }
        attackedLastCombatPlayers.put(game.getCombat().getAttackingPlayerId(), attackedPlayers);
    }
}
Also used : Permanent(mage.game.permanent.Permanent) HashMap(java.util.HashMap) UUID(java.util.UUID) 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