use of mage.abilities.SpellAbility in project mage by magefree.
the class PermanentImpl method applyDamage.
@Override
public int applyDamage(Game game) {
if (markedLifelink > 0) {
Player player = game.getPlayer(this.getControllerId());
player.gainLife(markedLifelink, game, null);
markedLifelink = 0;
}
if (markedDamage == null) {
return 0;
}
for (MarkedDamageInfo mdi : markedDamage) {
Ability source = null;
if (mdi.sourceObject instanceof PermanentToken) {
/* Tokens dont have a spellAbility. We must make a phony one as the source so the events in addCounters
* can trace the source back to an object/controller.
*/
source = new SpellAbility(null, ((PermanentToken) mdi.sourceObject).name);
source.setSourceId(((PermanentToken) mdi.sourceObject).objectId);
} else if (mdi.sourceObject instanceof Permanent) {
source = ((Permanent) mdi.sourceObject).getSpellAbility();
}
if (mdi.addCounters) {
addCounters(mdi.counter, game.getControllerId(mdi.sourceObject.getId()), source, game);
} else {
removeCounters(mdi.counter, source, game);
}
}
markedDamage.clear();
return 0;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class GenesisHydraPutOntoBattlefieldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
if (controller != null && obj instanceof SpellAbility) {
int count = ((SpellAbility) obj).getManaCostsToPay().getX();
if (count > 0) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, count));
controller.revealCards(source, cards, game);
FilterCard filter = new FilterPermanentCard("a nonland permanent card with mana value " + count + " or less to put onto the battlefield");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count + 1));
TargetCard target1 = new TargetCard(Zone.LIBRARY, filter);
target1.setRequired(false);
if (cards.count(filter, controller.getId(), source.getSourceId(), game) > 0) {
if (controller.choose(Outcome.PutCardInPlay, cards, target1, game)) {
Card card = cards.get(target1.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
target1.clearChosen();
} else {
game.informPlayers(controller.getLogName() + " didn't choose anything");
}
} else {
game.informPlayers("No nonland permanent card with mana value " + count + " or less to choose.");
}
if (!cards.isEmpty()) {
controller.moveCards(cards, Zone.LIBRARY, source, game);
controller.shuffleLibrary(source, game);
}
}
return true;
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class InfectiousCurseCostReductionEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (!(abilityToModify instanceof SpellAbility)) {
return false;
}
if (!source.isControlledBy(abilityToModify.getControllerId())) {
return false;
}
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment == null || enchantment.getAttachedTo() == null) {
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);
}
// try to reduce all the time (if it possible to target)
return allTargets.stream().anyMatch(target -> Objects.equals(target, enchantment.getAttachedTo()));
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class MinamosMeddlingCounterTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject == null) {
return false;
}
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Spell spell = game.getStack().getSpell(targetId);
if (spell == null) {
continue;
}
game.getStack().counter(targetId, source, game);
Player spellController = game.getPlayer(spell.getControllerId());
if (spellController == null) {
continue;
}
spellController.revealCards(sourceObject.getName(), spellController.getHand(), game);
Cards cardsToDiscard = new CardsImpl();
for (SpellAbility spellAbility : spell.getSpellAbilities()) {
if (spellAbility.getSpellAbilityType() == SpellAbilityType.SPLICE) {
for (Card card : spellController.getHand().getCards(game)) {
if (card.getName().equals(spellAbility.getCardName())) {
cardsToDiscard.add(card);
}
}
}
}
if (!cardsToDiscard.isEmpty()) {
spellController.discard(cardsToDiscard, false, source, game);
}
}
return true;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class NeverwinterHydraEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentEntering(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return true;
}
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility == null || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
return true;
}
if (!spellAbility.getSourceId().equals(source.getSourceId())) {
return true;
}
// put into play by normal cast
int xValue = spellAbility.getManaCostsToPay().getX();
if (xValue < 1) {
return false;
}
int amount = player.rollDice(outcome, source, game, 6, xValue, 0).stream().mapToInt(x -> x).sum();
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game, appliedEffects);
return true;
}
Aggregations