Search in sources :

Example 1 with AttackedThisTurnWatcher

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

the class MetzaliTowerOfTriumphEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Watcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    if (watcher instanceof AttackedThisTurnWatcher) {
        Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
        List<Permanent> available = new ArrayList<>();
        for (MageObjectReference mor : attackedThisTurn) {
            Permanent permanent = mor.getPermanent(game);
            if (permanent != null && permanent.isCreature(game)) {
                available.add(permanent);
            }
        }
        if (!available.isEmpty()) {
            Permanent permanent = available.get(RandomUtil.nextInt(available.size()));
            if (permanent != null) {
                permanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) ArrayList(java.util.ArrayList) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) Watcher(mage.watchers.Watcher) MageObjectReference(mage.MageObjectReference)

Example 2 with AttackedThisTurnWatcher

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

the class AttacksFirstTimeTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(this.getSourceId())) {
        return false;
    }
    AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    if (watcher == null) {
        return false;
    }
    Permanent sourcePerm = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (sourcePerm == null) {
        return false;
    }
    for (MageObjectReference mor : watcher.getAttackedThisTurnCreaturesCounts().keySet()) {
        if (mor.refersTo(sourcePerm, game) && watcher.getAttackedThisTurnCreaturesCounts().get(mor) > 1) {
            return false;
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Example 3 with AttackedThisTurnWatcher

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

the class VizierOfDefermentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    AttackedThisTurnWatcher watcherAttacked = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    BlockedThisTurnWatcher watcherBlocked = game.getState().getWatcher(BlockedThisTurnWatcher.class);
    boolean attackedOrBlocked = false;
    if (watcherAttacked != null && watcherAttacked.checkIfAttacked(permanent, game)) {
        attackedOrBlocked = true;
    }
    if (watcherBlocked != null && watcherBlocked.checkIfBlocked(permanent, game)) {
        attackedOrBlocked = true;
    }
    if (controller != null && attackedOrBlocked && sourcePermanent != null) {
        if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourcePermanent.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
            Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
            effect.setText("Return that card to the battlefield under its owner's control at the beginning of the next end step");
            effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) BlockedThisTurnWatcher(mage.watchers.common.BlockedThisTurnWatcher)

Example 4 with AttackedThisTurnWatcher

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

the class NoMoreThanOneCreatureCanBlockEachTurnEffect method canAttack.

@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
    if (!game.getCombat().getAttackers().isEmpty()) {
        return false;
    }
    AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    if (watcher == null) {
        return false;
    }
    Set<MageObjectReference> attackedThisTurnCreatures = watcher.getAttackedThisTurnCreatures();
    return attackedThisTurnCreatures.isEmpty() || (attackedThisTurnCreatures.size() == 1 && attackedThisTurnCreatures.contains(new MageObjectReference(attacker, game)));
}
Also used : AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Example 5 with AttackedThisTurnWatcher

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

the class ErgRaidersCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent raiders = game.getPermanentOrLKIBattlefield(source.getSourceId());
    AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    // wasControlledFromStartOfControllerTurn should be checked during resolution I guess, but shouldn't be relevant
    return raiders != null && raiders.wasControlledFromStartOfControllerTurn() && watcher != null && !watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(raiders, game));
}
Also used : Permanent(mage.game.permanent.Permanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) MageObjectReference(mage.MageObjectReference)

Aggregations

AttackedThisTurnWatcher (mage.watchers.common.AttackedThisTurnWatcher)11 MageObjectReference (mage.MageObjectReference)9 Permanent (mage.game.permanent.Permanent)9 Player (mage.players.Player)5 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Ability (mage.abilities.Ability)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 RequirementEffect (mage.abilities.effects.RequirementEffect)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 DestroyTargetEffect (mage.abilities.effects.common.DestroyTargetEffect)1 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)1 AttacksIfAbleAllEffect (mage.abilities.effects.common.combat.AttacksIfAbleAllEffect)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1