use of mage.game.stack.StackAbility in project mage by magefree.
the class ValiantRescuerWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.ACTIVATED_ABILITY || game.getState().getStack().isEmpty()) {
return;
}
StackObject item = game.getState().getStack().getFirst();
if (item instanceof StackAbility && item.getStackAbility() instanceof CyclingAbility) {
playerMap.computeIfAbsent(event.getPlayerId(), u -> new HashMap<>());
playerMap.get(event.getPlayerId()).compute(event.getSourceId(), CardUtil::setOrIncrementValue);
}
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class ValiantRescuerWatcher method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ValiantRescuerWatcher watcher = game.getState().getWatcher(ValiantRescuerWatcher.class);
if (watcher == null || !watcher.checkSpell(event.getPlayerId(), event.getSourceId()) || game.getState().getStack().isEmpty() || !event.getPlayerId().equals(this.getControllerId()) || event.getSourceId().equals(this.getSourceId())) {
return false;
}
StackObject item = game.getState().getStack().getFirst();
return item instanceof StackAbility && item.getStackAbility() instanceof CyclingAbility;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class KurkeshOnakkeAncientTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getPlayerId().equals(getControllerId())) {
return false;
}
Card source = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (source == null || !source.isArtifact(game)) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
return false;
}
this.getEffects().setValue("stackAbility", stackAbility);
return true;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class RadiantPerformerEffect method prepareCopiesWithTargets.
@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
List<MageObjectReferencePredicate> predicates = new ArrayList<>();
Ability ability = stackObject instanceof Spell ? ((Spell) stackObject).getSpellAbility() : (StackAbility) stackObject;
UUID targeted = ability == null ? null : ability.getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
return predicates;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class RepeatedReverberationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (stackAbility == null) {
return false;
}
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(stackAbility.getStackAbility().getSourceId());
if (controller == null || sourcePermanent == null) {
return false;
}
stackAbility.createCopyOnStack(game, source, source.getControllerId(), true, 2);
return true;
}
Aggregations