use of mage.abilities.Ability in project mage by magefree.
the class ComeuppanceEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
if (preventionData.getPreventedDamage() > 0) {
MageObject damageDealingObject = game.getObject(event.getSourceId());
UUID objectControllerId = null;
if (damageDealingObject instanceof Permanent) {
if (damageDealingObject.isCreature(game)) {
((Permanent) damageDealingObject).damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
} else {
objectControllerId = ((Permanent) damageDealingObject).getControllerId();
}
} else if (damageDealingObject instanceof Ability) {
objectControllerId = ((Ability) damageDealingObject).getControllerId();
} else if (damageDealingObject instanceof Spell) {
objectControllerId = ((Spell) damageDealingObject).getControllerId();
}
if (objectControllerId != null) {
Player objectController = game.getPlayer(objectControllerId);
if (objectController != null) {
objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
}
}
}
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class FaithsShieldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
if (FatefulHourCondition.instance.apply(game, source)) {
ChoiceColor choice = new ChoiceColor();
if (!controller.choose(Outcome.Protect, choice, game)) {
return false;
}
if (choice.getColor() != null) {
game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
FilterCard filter = new FilterCard();
filter.add(new ColorPredicate(choice.getColor()));
filter.setMessage(choice.getChoice());
Ability ability = new ProtectionAbility(filter);
game.addEffect(new GainAbilityControlledEffect(ability, Duration.EndOfTurn), source);
game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
return true;
}
} else {
game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source);
return true;
}
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class GigantoplasmCopyApplier method apply.
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
DynamicValue variableMana = ManacostVariableValue.REGULAR;
Effect effect = new SetPowerToughnessSourceEffect(variableMana, Duration.WhileOnBattlefield, SubLayer.SetPT_7b);
effect.setText("This creature has base power and toughness X/X");
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{X}"));
blueprint.getAbilities().add(ability);
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class GisaGloriousResurrectorReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Ability exiledWithSource = (Ability) game.getState().getValue("GisaGloriousResurrectorExile" + source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()));
if (exiledWithSource == null) {
return false;
}
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, exiledWithSource));
if (player == null || exileZone == null || exileZone.isEmpty()) {
return false;
}
Cards cards = new CardsImpl(exileZone.getCards(StaticFilters.FILTER_CARD_CREATURE, game));
if (cards.isEmpty()) {
return false;
}
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
cards.retainZone(Zone.BATTLEFIELD, game);
if (cards.isEmpty()) {
return false;
}
game.addEffect(new GainAbilityTargetEffect(new DecayedAbility(), Duration.Custom).setTargetPointer(new FixedTargets(cards, game)), source);
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class HeliodsPunishmentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourceEnchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourceEnchantment != null && sourceEnchantment.getAttachedTo() != null) {
Permanent attachedTo = game.getPermanent(sourceEnchantment.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAllAbilities(source.getSourceId(), game);
HeliodsPunishmentEffect effect = new HeliodsPunishmentEffect(sourceEnchantment.getName());
Ability ability = new SimpleActivatedAbility(effect, new TapSourceCost());
effect.setSourceEnchantment(sourceEnchantment.getId());
attachedTo.addAbility(ability, source.getSourceId(), game);
}
}
return true;
}
Aggregations