use of mage.abilities.SpellAbility in project mage by magefree.
the class MonasterySiegeCostIncreaseEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (!modeDragons.apply(game, source)) {
return false;
}
if (!(abilityToModify instanceof SpellAbility)) {
return false;
}
if (!game.getOpponents(source.getControllerId()).contains(abilityToModify.getControllerId())) {
return false;
}
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
Set<UUID> allTargets;
if (spell != null) {
// real cast
allTargets = CardUtil.getAllSelectedTargets(abilityToModify, game);
} else {
// playable
allTargets = CardUtil.getAllPossibleTargets(abilityToModify, game);
// can target without cost increase
if (allTargets.stream().anyMatch(target -> !isTargetCompatible(target, source, game))) {
return false;
}
;
}
return allTargets.stream().anyMatch(target -> isTargetCompatible(target, source, game));
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class TargetsHaveToTargetPermanentIfAbleEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
Player targetingPlayer = game.getPlayer(event.getPlayerId());
if (controller != null && // TODO: This target handling does only work for non AI players so AI logic
targetingPlayer.isHuman() && controller.hasOpponent(event.getPlayerId(), game)) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject.isCopy()) {
return false;
}
Ability stackAbility = stackObject.getStackAbility();
// Ensure that this ability is activated or a cast spell, because Flag Bearer effects don't require triggered abilities to choose a Standard Bearer
if (!(stackAbility instanceof ActivatedAbility) && !(stackAbility instanceof SpellAbility)) {
return false;
}
// Also check that targeting player controls the ability
if (!stackAbility.isControlledBy(targetingPlayer.getId())) {
return false;
}
Ability ability = (Ability) getValue("targetAbility");
if (ability != null) {
// Get all the allowed permanents on the battlefield in range of the abilities controller
List<Permanent> allowedPermanents = game.getBattlefield().getActivePermanents(filter, event.getPlayerId(), event.getSourceId(), game);
if (!allowedPermanents.isEmpty()) {
boolean canTargetAllowedPermanent = false;
for (UUID modeId : ability.getModes().getSelectedModes()) {
ability.getModes().setActiveMode(modeId);
for (Target target : ability.getTargets()) {
// Check if already targeted
for (Permanent allowedPermanent : allowedPermanents) {
if (target.getTargets().contains(allowedPermanent.getId())) {
return false;
}
if (target.canTarget(stackObject.getControllerId(), allowedPermanent.getId(), source, game)) {
canTargetAllowedPermanent = true;
}
}
}
}
return canTargetAllowedPermanent;
}
}
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class ComputerPlayer6 method checkForRepeatedAction.
private boolean checkForRepeatedAction(Game sim, SimulationNode2 node, Ability action, UUID playerId) {
// pass or casting two times a spell multiple times on hand is ok
if (action instanceof PassAbility || action instanceof SpellAbility || action.getAbilityType() == AbilityType.MANA) {
return false;
}
int newVal = GameStateEvaluator2.evaluate(playerId, sim).getTotalScore();
SimulationNode2 test = node.getParent();
while (test != null) {
if (test.getPlayerId().equals(playerId)) {
if (test.getAbilities() != null && test.getAbilities().size() == 1) {
if (action.toString().equals(test.getAbilities().get(0).toString())) {
if (test.getParent() != null) {
Game prevGame = node.getGame();
if (prevGame != null) {
int oldVal = GameStateEvaluator2.evaluate(playerId, prevGame).getTotalScore();
if (oldVal >= newVal) {
return true;
}
}
}
}
}
}
test = test.getParent();
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class CurseOfSilenceTriggeredAbility method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Permanent enchantment = source.getSourcePermanentIfItStillExists(game);
if (enchantment != null && abilityToModify.isControlledBy(enchantment.getAttachedTo())) {
Card card = game.getCard(abilityToModify.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (card != null && cardName != null && !cardName.isEmpty()) {
return CardUtil.haveSameNames(card, cardName, game);
}
}
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class ExplosiveSingularityEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
SpellAbility spellAbility = (SpellAbility) abilityToModify;
int reduction;
if (game.inCheckPlayableState()) {
reduction = game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_UNTAPPED_CREATURES, source.getSourceId(), source.getControllerId(), game);
} else {
reduction = ((List<Permanent>) spellAbility.getEffects().get(0).getValue("tappedPermanents")).size();
}
CardUtil.adjustCost(spellAbility, reduction);
return true;
}
Aggregations