use of mage.abilities.costs.Cost in project mage by magefree.
the class DralnusPetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
if (controller != null && permanent != null) {
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility != null && spellAbility.getSourceId().equals(source.getSourceId()) && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
int cmc = 0;
for (Cost cost : spellAbility.getCosts()) {
if (cost instanceof DiscardCardCost && !((DiscardCardCost) cost).getCards().isEmpty()) {
cmc = ((DiscardCardCost) cost).getCards().get(0).getManaValue();
}
if (cmc > 0) {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance(cmc), true).apply(game, source);
}
}
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class DragonsFireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetedPermanent = game.getPermanent(targetPointer.getFirst(game, source));
if (targetedPermanent == null) {
return false;
}
DragonsFireCost.DragonZone dragonZone = DragonsFireCost.DragonZone.NONE;
UUID selectedCardId = null;
int damage = 3;
for (Cost cost : source.getCosts()) {
if (cost instanceof DragonsFireCost) {
DragonsFireCost dragonsFireCost = (DragonsFireCost) cost;
dragonZone = dragonsFireCost.getDragonZone();
selectedCardId = dragonsFireCost.getSelectedCardId();
break;
}
}
switch(dragonZone) {
case HAND:
Card card = game.getCard(selectedCardId);
if (card != null) {
damage = card.getPower().getValue();
}
break;
case BATTLEFIELD:
Permanent dragon = game.getPermanentOrLKIBattlefield(selectedCardId);
if (dragon != null) {
damage = dragon.getPower().getValue();
}
break;
}
targetedPermanent.damage(damage, source.getSourceId(), source, game);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class LeylineTyrantDamageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
String manaString;
if (costX == 0) {
manaString = "{0}";
} else {
manaString = "";
for (int i = 0; i < costX; i++) {
manaString += "{R}";
}
}
Cost cost = new ManaCostsImpl<>(manaString);
cost.clearPaid();
if (!cost.pay(source, game, source, source.getControllerId(), false)) {
return false;
}
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(costX), false, "{this} deals " + costX + " damage to any target");
ability.addTarget(new TargetAnyTarget());
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class NashiMoonSagesScionPlayEffect method applies.
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (!super.applies(objectId, source, affectedControllerId, game) || !NashiMoonSagesScionWatcher.checkCard(game, source, mor)) {
return false;
}
Card cardToCheck = mor.getCard(game);
if (cardToCheck.isLand(game)) {
return true;
}
// allows to play/cast with alternative life cost
Player controller = game.getPlayer(source.getControllerId());
PayLifeCost lifeCost = new PayLifeCost(cardToCheck.getSpellAbility().getManaCosts().manaValue());
Costs<Cost> newCosts = new CostsImpl<>();
newCosts.add(lifeCost);
newCosts.addAll(cardToCheck.getSpellAbility().getCosts());
controller.setCastSourceIdWithAlternateMana(cardToCheck.getId(), null, newCosts);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class SpellSyphonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && spell != null) {
Player player = game.getPlayer(spell.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
if (player != null && controller != null) {
int amount = controller.getHand().size();
if (amount > 0) {
Cost cost = ManaUtil.createManaCost(amount, false);
if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
game.informPlayers(sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
return game.getStack().counter(source.getFirstTarget(), source, game);
}
}
return true;
}
}
return false;
}
Aggregations