use of mage.abilities.SpellAbility in project mage by magefree.
the class MCTSPlayer method simulateVariableCosts.
protected void simulateVariableCosts(Ability ability, List<Ability> options, 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));
options.add(newAbility);
}
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class ApocalypseHydraEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (permanent == null) {
return false;
}
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility == null || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
return false;
}
int amount = spellAbility.getManaCostsToPay().getX();
if (amount > 0) {
if (amount < 5) {
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
} else {
permanent.addCounters(CounterType.P1P1.createInstance(amount * 2), source.getControllerId(), source, game);
}
}
return true;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class DefenseGridCostModificationEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
SpellAbility spellAbility = (SpellAbility) abilityToModify;
spellAbility.getManaCostsToPay().add(new GenericManaCost(3));
return true;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class AnimarCostReductionEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
Ability spellAbility = abilityToModify;
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null && spellAbility != null) {
int amount = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
CardUtil.reduceCost(spellAbility, amount);
return true;
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class CemeteryProwlerCostReductionEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
if (abilityToModify instanceof SpellAbility) {
// sourceObjectZoneChangeCounter is not working here. Getting it from GameState works.
UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()));
ExileZone exileZone = game.getExile().getExileZone(exileId);
Card castCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (exileZone != null && castCard != null) {
HashSet<CardType> cardTypes = new HashSet<>();
for (UUID cardId : exileZone) {
Card card = game.getCard(cardId);
if (card != null) {
cardTypes.addAll(card.getCardType(game));
}
}
int sharedTypes = 0;
for (CardType type : castCard.getCardType(game)) {
if (cardTypes.contains(type)) {
sharedTypes++;
}
}
if (sharedTypes > 0) {
CardUtil.reduceCost(abilityToModify, sharedTypes);
return true;
}
}
}
return false;
}
Aggregations