Search in sources :

Example 1 with AttackedLastTurnWatcher

use of mage.watchers.common.AttackedLastTurnWatcher in project mage by magefree.

the class CantAttackIfAttackedLastTurnEffect method canAttack.

@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
    AttackedLastTurnWatcher watcher = game.getState().getWatcher(AttackedLastTurnWatcher.class);
    if (watcher != null) {
        Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(attacker.getControllerId());
        MageObjectReference mor = new MageObjectReference(attacker, game);
        return !attackingCreatures.contains(mor);
    }
    return true;
}
Also used : AttackedLastTurnWatcher(mage.watchers.common.AttackedLastTurnWatcher) MageObjectReference(mage.MageObjectReference)

Example 2 with AttackedLastTurnWatcher

use of mage.watchers.common.AttackedLastTurnWatcher in project mage by magefree.

the class DontUntapIfAttackedLastTurnEnchantedEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (game.getTurn().getStepType() == PhaseStep.UNTAP) {
        Permanent enchantment = game.getPermanent(source.getSourceId());
        if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) {
            Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
            if (permanent != null && permanent.isControlledBy(game.getActivePlayerId())) {
                AttackedLastTurnWatcher watcher = game.getState().getWatcher(AttackedLastTurnWatcher.class);
                if (watcher != null) {
                    Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(permanent.getControllerId());
                    MageObjectReference mor = new MageObjectReference(permanent, game);
                    if (attackingCreatures.contains(mor)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : AttackedLastTurnWatcher(mage.watchers.common.AttackedLastTurnWatcher) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference)

Example 3 with AttackedLastTurnWatcher

use of mage.watchers.common.AttackedLastTurnWatcher in project mage by magefree.

the class DontUntapIfAttackedLastTurnSourceEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getTargetId().equals(source.getSourceId())) {
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null && permanent.isControlledBy(game.getActivePlayerId())) {
            AttackedLastTurnWatcher watcher = game.getState().getWatcher(AttackedLastTurnWatcher.class);
            if (watcher != null) {
                Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(permanent.getControllerId());
                MageObjectReference mor = new MageObjectReference(permanent, game);
                if (attackingCreatures.contains(mor)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AttackedLastTurnWatcher(mage.watchers.common.AttackedLastTurnWatcher) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) CantAttackUnlessDefenderControllsPermanent(mage.abilities.effects.common.combat.CantAttackUnlessDefenderControllsPermanent) MageObjectReference(mage.MageObjectReference)

Example 4 with AttackedLastTurnWatcher

use of mage.watchers.common.AttackedLastTurnWatcher in project mage by magefree.

the class CantAttackIfAttackedLastTurnAllEffect method canAttack.

@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
    AttackedLastTurnWatcher watcher = game.getState().getWatcher(AttackedLastTurnWatcher.class);
    if (watcher != null) {
        Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(attacker.getControllerId());
        MageObjectReference mor = new MageObjectReference(attacker, game);
        return !attackingCreatures.contains(mor);
    }
    return true;
}
Also used : AttackedLastTurnWatcher(mage.watchers.common.AttackedLastTurnWatcher) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)4 AttackedLastTurnWatcher (mage.watchers.common.AttackedLastTurnWatcher)4 Permanent (mage.game.permanent.Permanent)2 CantAttackUnlessDefenderControllsPermanent (mage.abilities.effects.common.combat.CantAttackUnlessDefenderControllsPermanent)1 FilterLandPermanent (mage.filter.common.FilterLandPermanent)1 TargetPermanent (mage.target.TargetPermanent)1 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)1