use of mage.abilities.SpellAbility in project mage by magefree.
the class HydroidKrasisEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
if (!(obj instanceof SpellAbility)) {
return false;
}
int halfCost = Math.floorDiv(((SpellAbility) obj).getManaCostsToPay().getX(), 2);
player.drawCards(halfCost, source, game);
player.gainLife(halfCost, game, source);
return true;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class EntersBattlefieldWithXCountersEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
if (source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
}
if (permanent != null) {
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility != null && spellAbility.getSourceId().equals(source.getSourceId()) && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
if (spellAbility.getSourceId().equals(source.getSourceId())) {
// put into play by normal cast
int amount = spellAbility.getManaCostsToPay().getX();
if (amount > 0) {
Counter counterToAdd = counter.copy();
counterToAdd.add(amount - counter.getCount());
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
permanent.addCounters(counterToAdd, source.getControllerId(), source, game, appliedEffects);
}
}
}
}
return true;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class SpellsCostIncreasingAllEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Player abilityController = game.getPlayer(abilityToModify.getControllerId());
Player sourceController = game.getPlayer(source.getControllerId());
if (abilityController == null || sourceController == null) {
return false;
}
switch(this.targetController) {
case YOU:
if (!sourceController.getId().equals(abilityController.getId())) {
return false;
}
break;
case OPPONENT:
if (!sourceController.hasOpponent(abilityController.getId(), game)) {
return false;
}
break;
case ANY:
break;
default:
throw new IllegalArgumentException("Unsupported TargetController " + this.targetController);
}
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
// real cast with put on stack
return this.filter.match(spell, game);
} else {
// get playable and other staff without put on stack
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return this.filter.match(sourceCard, game);
}
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class SplitCard method getAbilities.
@Override
public Abilities<Ability> getAbilities(Game game) {
Abilities<Ability> allAbilites = new AbilitiesImpl<>();
for (Ability ability : super.getAbilities(game)) {
// TODO: why it here, for GUI's cleanup in card texts? Maybe it can be removed, see mdf cards
if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT || ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH)) {
continue;
}
allAbilites.add(ability);
}
allAbilites.addAll(leftHalfCard.getAbilities(game));
allAbilites.addAll(rightHalfCard.getAbilities(game));
return allAbilites;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class SplitCard method getAbilities.
@Override
public Abilities<Ability> getAbilities() {
Abilities<Ability> allAbilites = new AbilitiesImpl<>();
for (Ability ability : super.getAbilities()) {
// TODO: why it here, for GUI's cleanup in card texts? Maybe it can be removed, see mdf cards
if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT || ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH)) {
continue;
}
allAbilites.add(ability);
}
allAbilites.addAll(leftHalfCard.getAbilities());
allAbilites.addAll(rightHalfCard.getAbilities());
return allAbilites;
}
Aggregations