Search in sources :

Example 1 with PlayerDamagedBySourceWatcher

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

the class GiltspireAvengerTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    Set<UUID> possibleTargets = new HashSet<>();
    PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, sourceControllerId);
    for (UUID targetId : availablePossibleTargets) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent != null && watcher != null && watcher.hasSourceDoneDamage(targetId, game)) {
            possibleTargets.add(targetId);
        }
    }
    return possibleTargets;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PlayerDamagedBySourceWatcher(mage.watchers.common.PlayerDamagedBySourceWatcher) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 2 with PlayerDamagedBySourceWatcher

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

the class GiltspireAvengerTarget method canChoose.

@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
    int remainingTargets = this.minNumberOfTargets - targets.size();
    if (remainingTargets == 0) {
        return true;
    }
    int count = 0;
    MageObject targetSource = game.getObject(sourceId);
    PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, sourceControllerId);
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
        if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && watcher != null && watcher.hasSourceDoneDamage(permanent.getId(), game)) {
            count++;
            if (count >= remainingTargets) {
                return true;
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) PlayerDamagedBySourceWatcher(mage.watchers.common.PlayerDamagedBySourceWatcher)

Example 3 with PlayerDamagedBySourceWatcher

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

the class DamagedPlayerThisTurnPredicate method apply.

@Override
public boolean apply(ObjectSourcePlayer<Controllable> input, Game game) {
    Controllable object = input.getObject();
    UUID playerId = input.getPlayerId();
    switch(controller) {
        case YOU:
            PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, playerId);
            if (watcher != null) {
                return watcher.hasSourceDoneDamage(object.getId(), game);
            }
            break;
        case OPPONENT:
            for (UUID opponentId : game.getOpponents(playerId)) {
                watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, opponentId);
                if (watcher != null) {
                    return watcher.hasSourceDoneDamage(object.getId(), game);
                }
            }
            break;
        case NOT_YOU:
            for (UUID notYouId : game.getState().getPlayersInRange(playerId, game)) {
                if (!notYouId.equals(playerId)) {
                    watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, notYouId);
                    if (watcher != null) {
                        return watcher.hasSourceDoneDamage(object.getId(), game);
                    }
                }
            }
            break;
        case ANY:
            for (UUID anyId : game.getState().getPlayersInRange(playerId, game)) {
                watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, anyId);
                if (watcher != null) {
                    return watcher.hasSourceDoneDamage(object.getId(), game);
                }
            }
            return true;
    }
    return false;
}
Also used : Controllable(mage.game.Controllable) PlayerDamagedBySourceWatcher(mage.watchers.common.PlayerDamagedBySourceWatcher) UUID(java.util.UUID)

Example 4 with PlayerDamagedBySourceWatcher

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

the class ReciprocateTarget method canChoose.

@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
    int remainingTargets = this.minNumberOfTargets - targets.size();
    if (remainingTargets == 0) {
        return true;
    }
    int count = 0;
    MageObject targetSource = game.getObject(sourceId);
    if (targetSource != null) {
        PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, sourceControllerId);
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
            if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && watcher != null && watcher.hasSourceDoneDamage(permanent.getId(), game)) {
                count++;
                if (count >= remainingTargets) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) PlayerDamagedBySourceWatcher(mage.watchers.common.PlayerDamagedBySourceWatcher)

Example 5 with PlayerDamagedBySourceWatcher

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

the class ReciprocateTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    Set<UUID> possibleTargets = new HashSet<>();
    PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, sourceControllerId);
    for (UUID targetId : availablePossibleTargets) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent != null && watcher != null && watcher.hasSourceDoneDamage(targetId, game)) {
            possibleTargets.add(targetId);
        }
    }
    return possibleTargets;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PlayerDamagedBySourceWatcher(mage.watchers.common.PlayerDamagedBySourceWatcher) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

PlayerDamagedBySourceWatcher (mage.watchers.common.PlayerDamagedBySourceWatcher)5 Permanent (mage.game.permanent.Permanent)4 TargetPermanent (mage.target.TargetPermanent)4 UUID (java.util.UUID)3 HashSet (java.util.HashSet)2 MageObject (mage.MageObject)2 Controllable (mage.game.Controllable)1