use of mage.abilities.SpellAbility in project mage by magefree.
the class MiracleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
// use target pointer here, so it's the same card that triggered the event (not gone back to library e.g.)
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (controller != null && card != null) {
SpellAbility abilityToCast = card.getSpellAbility().copy();
ManaCosts<ManaCost> costRef = abilityToCast.getManaCostsToPay();
// replace with the new cost
costRef.clear();
costRef.add(miracleCosts);
controller.cast(abilityToCast, game, false, new ApprovingObject(source, game));
return true;
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class SpliceOntoArcaneEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
Player controller = game.getPlayer(source.getControllerId());
Card spliceCard = game.getCard(source.getSourceId());
if (spliceCard != null && controller != null) {
Spell spell = game.getStack().getSpell(abilityToModify.getId());
if (spell != null) {
SpellAbility splicedAbility = spliceCard.getSpellAbility().copy();
splicedAbility.setSpellAbilityType(SpellAbilityType.SPLICE);
splicedAbility.setSourceId(abilityToModify.getSourceId());
spell.addSpellAbility(splicedAbility);
for (Iterator it = ((SpliceOntoArcaneAbility) source).getSpliceCosts().iterator(); it.hasNext(); ) {
spell.getSpellAbility().getCosts().add(((Cost) it.next()).copy());
}
}
return true;
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class TurriIslandEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Plane cPlane = game.getState().getCurrentPlane();
if (cPlane == null) {
return false;
}
if (!cPlane.getPlaneType().equals(Planes.PLANE_TURRI_ISLAND)) {
return false;
}
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
return filter.match(spellCard, game) && selectedByRuntimeData(spellCard, source, game);
}
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class PlayableObjectRecord method load.
public void load(List<ActivatedAbility> activatedAbilities) {
this.basicManaAbilities.clear();
this.basicPlayAbilities.clear();
this.basicCastAbilities.clear();
this.other.clear();
// split abilities to types (it allows to enable or disable playable icon)
for (ActivatedAbility ability : activatedAbilities) {
List<PlayableObjectRecord> dest;
if (ability instanceof BasicManaAbility) {
dest = this.basicManaAbilities;
} else if (ability instanceof PlayLandAbility) {
dest = this.basicPlayAbilities;
} else if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.BASE)) {
dest = this.basicCastAbilities;
} else {
dest = this.other;
}
// collect info about abilities for card icons popup, must be simple online text (html symbols are possible)
// some long html tags can be miss (example: ability extra hint) -- that's ok
String shortInfo = ability.toString();
if (shortInfo.length() > 50) {
shortInfo = shortInfo.substring(0, 50 - 1) + "...";
}
shortInfo = shortInfo.replace("<br>", " ");
shortInfo = shortInfo.replace("\n", " ");
dest.add(new PlayableObjectRecord(ability.getId(), shortInfo));
}
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class SimulatedPlayer method simulateVariableCosts.
// protected void simulateAction(Game game, SimulatedAction previousActions, Ability action) {
// List<Ability> actions = new ArrayList<Ability>(previousActions.getAbilities());
// actions.add(action);
// Game sim = game.copy();
// if (sim.getPlayer(playerId).activateAbility((ActivatedAbility) action.copy(), sim)) {
// sim.applyEffects();
// sim.getPlayers().resetPassed();
// allActions.add(new SimulatedAction(sim, actions));
// }
// }
// add a generic mana cost for each amount possible
protected void simulateVariableCosts(Ability ability, Game game) {
int numAvailable = getAvailableManaProducers(game).size() - ability.getManaCosts().manaValue();
int start = 0;
if (!(ability instanceof SpellAbility)) {
// only use x=0 on spell abilities
if (numAvailable == 0)
return;
else
start = 1;
}
for (int i = start; i < numAvailable; i++) {
Ability newAbility = ability.copy();
newAbility.getManaCostsToPay().add(new GenericManaCost(i));
allActions.add(newAbility);
}
}
Aggregations