use of mage.abilities.SpellAbility in project mage by magefree.
the class ManaUtilTest method testManaReduction.
/**
* Checks if a given mana reduction left the expected amount of mana costs
*
* @param manaCostsToPay
* @param availablyAny
* @param available
* @param expected
*/
private void testManaReduction(String manaCostsToPay, String manaToReduce, String restMana) {
SpellAbility spellAbility = new SpellAbility(new ManaCostsImpl(manaCostsToPay), "Test");
CardUtil.adjustCost(spellAbility, new ManaCostsImpl(manaToReduce), true);
Assert.assertTrue("The mana cost to pay " + manaCostsToPay + " reduced by " + manaToReduce + " should left " + restMana + " but the rest was " + spellAbility.getManaCostsToPay().getText(), spellAbility.getManaCostsToPay().getText().equals(restMana));
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class ConspireTriggeredAbility method addOptionalAdditionalCosts.
@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
if (!(ability instanceof SpellAbility)) {
return;
}
Player player = game.getPlayer(getControllerId());
if (player == null) {
return;
}
// AI supports conspire
if (!conspireCost.canPay(ability, this, getControllerId(), game) || !player.chooseUse(Outcome.Benefit, "Pay " + conspireCost.getText(false) + " ?", ability, game)) {
return;
}
ability.getEffects().setValue("ConspireActivation" + conspireId + addedById, true);
for (Iterator<Cost> it = ((Costs<Cost>) conspireCost).iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCostsImpl) {
ability.getManaCostsToPay().add((ManaCostsImpl<?>) cost.copy());
} else {
ability.getCosts().add(cost.copy());
}
}
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class EntwineAbility method addOptionalAdditionalCosts.
@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
if (!(ability instanceof SpellAbility)) {
return;
}
Player player = game.getPlayer(ability.getControllerId());
if (player == null) {
return;
}
this.resetEntwine(game, ability);
if (entwineCost == null) {
return;
}
// AI can use it
if (entwineCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, "Pay " + entwineCost.getText(false) + " ?", ability, game)) {
for (Iterator it = ((Costs) entwineCost).iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCostsImpl) {
ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
} else {
ability.getCosts().add(cost.copy());
}
}
activateEntwine(game, ability);
}
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class FlashbackReplacementEffect method getSpellAbilityToResolve.
@Override
public SpellAbility getSpellAbilityToResolve(Game game) {
Card card = game.getCard(getSourceId());
if (card != null) {
if (spellAbilityToResolve == null) {
SpellAbility spellAbilityCopy = null;
if (card instanceof SplitCard) {
if (((SplitCard) card).getLeftHalfCard().getName().equals(abilityName)) {
spellAbilityCopy = ((SplitCard) card).getLeftHalfCard().getSpellAbility().copy();
} else if (((SplitCard) card).getRightHalfCard().getName().equals(abilityName)) {
spellAbilityCopy = ((SplitCard) card).getRightHalfCard().getSpellAbility().copy();
}
} else if (card instanceof ModalDoubleFacesCard) {
if (((ModalDoubleFacesCard) card).getLeftHalfCard().getName().equals(abilityName)) {
spellAbilityCopy = ((ModalDoubleFacesCard) card).getLeftHalfCard().getSpellAbility().copy();
} else if (((ModalDoubleFacesCard) card).getRightHalfCard().getName().equals(abilityName)) {
spellAbilityCopy = ((ModalDoubleFacesCard) card).getRightHalfCard().getSpellAbility().copy();
}
} else {
spellAbilityCopy = card.getSpellAbility().copy();
}
if (spellAbilityCopy == null) {
return null;
}
spellAbilityCopy.setId(this.getId());
spellAbilityCopy.getManaCosts().clear();
spellAbilityCopy.getManaCostsToPay().clear();
spellAbilityCopy.getCosts().addAll(this.getCosts().copy());
spellAbilityCopy.addCost(this.getManaCosts().copy());
spellAbilityCopy.setSpellAbilityCastMode(this.getSpellAbilityCastMode());
spellAbilityToResolve = spellAbilityCopy;
ContinuousEffect effect = new FlashbackReplacementEffect();
effect.setTargetPointer(new FixedTarget(getSourceId(), game.getState().getZoneChangeCounter(getSourceId())));
game.addEffect(effect, this);
}
}
return spellAbilityToResolve;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class OldGrowthTrollContinuousEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
if (game.getState().getZoneChangeCounter(source.getSourceId()) > zoneChangeCounter) {
discard();
return false;
}
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject == null) {
sourceObject = game.getPermanentEntering(source.getSourceId());
}
if (sourceObject == null) {
return false;
}
Permanent troll = sourceObject;
switch(layer) {
case TypeChangingEffects_4:
troll.removeAllCardTypes(game);
troll.addCardType(game, CardType.ENCHANTMENT);
troll.removeAllSubTypes(game);
troll.addSubType(game, SubType.AURA);
break;
case AbilityAddingRemovingEffects_6:
// Spell Ability can be null with clone effects (ex. Moritte)
if (troll.getSpellAbility() == null) {
troll.addAbility(new SpellAbility(null, null), source.getSourceId(), game);
}
troll.getSpellAbility().getTargets().clear();
troll.getSpellAbility().getEffects().clear();
TargetPermanent auraTarget = new TargetPermanent(filter);
troll.getSpellAbility().addTarget(auraTarget);
troll.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
troll.addAbility(new EnchantAbility(auraTarget.getTargetName()), source.getSourceId(), game);
// add the activated ability
troll.addAbility(makeAbility(), source.getSourceId(), game);
}
return true;
}
Aggregations