From 962f05bbcb44d2eaf28420df99747ecd03f16b37 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 12 Mar 2017 11:29:53 +0100 Subject: [PATCH] * Offering - Fixed that offering could not be activated as instant, cancel during offering mana payment now restores also the sacrificed permanent. --- .../abilities/keyword/OfferingAbility.java | 102 ++++++++++-------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/keyword/OfferingAbility.java b/Mage/src/main/java/mage/abilities/keyword/OfferingAbility.java index 15d4747d699..47e6b5e1335 100644 --- a/Mage/src/main/java/mage/abilities/keyword/OfferingAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/OfferingAbility.java @@ -24,25 +24,22 @@ * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. -*/ - + */ package mage.abilities.keyword; import java.util.UUID; - -import mage.constants.AsThoughEffectType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.StaticAbility; -import mage.abilities.costs.mana.ManaCost; -import mage.abilities.costs.mana.ManaCosts; import mage.abilities.effects.AsThoughEffectImpl; import mage.abilities.effects.common.cost.CostModificationEffectImpl; import mage.cards.Card; +import mage.constants.AsThoughEffectType; import mage.constants.CostModificationType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Zone; import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; @@ -54,21 +51,23 @@ import mage.util.CardUtil; /** * - * 702.46. Offering # - * 702.46a Offering is a static ability of a card that functions in any zone from which - * the card can be cast. "[Subtype] offering" means "You may cast this card any time you - * could cast an instant by sacrificing a [subtype] permanent. If you do, the total cost - * to cast this card is reduced by the sacrificed permanent's mana cost." # + * 702.46. Offering # 702.46a Offering is a static ability of a card that + * functions in any zone from which the card can be cast. "[Subtype] offering" + * means "You may cast this card any time you could cast an instant by + * sacrificing a [subtype] permanent. If you do, the total cost to cast this + * card is reduced by the sacrificed permanent's mana cost." # * - * 702.46b The permanent is sacrificed at the same time the spell is announced (see rule 601.2a). - * The total cost of the spell is reduced by the sacrificed permanent's mana cost (see rule 601.2e). # + * 702.46b The permanent is sacrificed at the same time the spell is announced + * (see rule 601.2a). The total cost of the spell is reduced by the sacrificed + * permanent's mana cost (see rule 601.2e). # * - * 702.46c Generic mana in the sacrificed permanent's mana cost reduces generic mana - * in the total cost to cast the card with offering. Colored mana in the sacrificed - * permanent's mana cost reduces mana of the same color in the total cost to cast the - * card with offering. Colored mana in the sacrificed permanent's mana cost that doesn't - * match colored mana in the colored mana cost of the card with offering, or is in excess - * of the card's colored mana cost, reduces that much generic mana in the total cost. # + * 702.46c Generic mana in the sacrificed permanent's mana cost reduces generic + * mana in the total cost to cast the card with offering. Colored mana in the + * sacrificed permanent's mana cost reduces mana of the same color in the total + * cost to cast the card with offering. Colored mana in the sacrificed + * permanent's mana cost that doesn't match colored mana in the colored mana + * cost of the card with offering, or is in excess of the card's colored mana + * cost, reduces that much generic mana in the total cost. # * * * @author LevelX2 @@ -76,11 +75,11 @@ import mage.util.CardUtil; public class OfferingAbility extends StaticAbility { private FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); - + /** - * - * @param subtype name of the subtype that can be offered - */ + * + * @param subtype name of the subtype that can be offered + */ public OfferingAbility(String subtype) { super(Zone.ALL, null); filter.add(new SubtypePredicate(subtype)); @@ -155,12 +154,15 @@ class OfferingAsThoughEffect extends AsThoughEffectImpl { if (game.getBattlefield().count(((OfferingAbility) source).getFilter(), source.getSourceId(), source.getControllerId(), game) > 0) { + if (CardUtil.isCheckPlayableMode(affectedAbility)) { + return true; + } FilterControlledCreaturePermanent filter = ((OfferingAbility) source).getFilter(); Card spellToCast = game.getCard(source.getSourceId()); Player player = game.getPlayer(source.getControllerId()); - if (player != null && !CardUtil.isCheckPlayableMode(affectedAbility) && - player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) { - Target target = new TargetControlledCreaturePermanent(1,1,filter,true); + if (player != null && !CardUtil.isCheckPlayableMode(affectedAbility) + && player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) { + Target target = new TargetControlledCreaturePermanent(1, 1, filter, true); player.chooseTarget(Outcome.Sacrifice, target, source, game); if (!target.isChosen()) { return false; @@ -169,18 +171,15 @@ class OfferingAsThoughEffect extends AsThoughEffectImpl { Permanent offer = game.getPermanent(target.getFirstTarget()); if (offer != null) { UUID activationId = UUID.randomUUID(); - OfferingCostReductionEffect effect = new OfferingCostReductionEffect(spellToCast.getSpellAbility().getId(), offer.getSpellAbility().getManaCosts(), activationId); + OfferingCostReductionEffect effect = new OfferingCostReductionEffect(spellToCast.getSpellAbility().getId(), new MageObjectReference(offer, game), activationId); game.addEffect(effect, source); - offer.sacrifice(source.getSourceId(), game); game.getState().setValue("offering_ok_" + card.getId(), true); game.getState().setValue("offering_Id_" + card.getId(), activationId); return true; - + } } else { - if (game.canPlaySorcery(source.getControllerId())) { - game.getState().setValue("offering_" + card.getId(), true); - } + game.getState().setValue("offering_" + card.getId(), true); } } } @@ -188,17 +187,17 @@ class OfferingAsThoughEffect extends AsThoughEffectImpl { } } - class OfferingCostReductionEffect extends CostModificationEffectImpl { private final UUID spellAbilityId; private final UUID activationId; - private final ManaCosts manaCostsToReduce; + private final MageObjectReference offeredPermanent; + // private final ManaCosts manaCostsToReduce; - OfferingCostReductionEffect (UUID spellAbilityId, ManaCosts manaCostsToReduce, UUID activationId) { + OfferingCostReductionEffect(UUID spellAbilityId, MageObjectReference offeredPermanent, UUID activationId) { super(Duration.OneUse, Outcome.Benefit, CostModificationType.REDUCE_COST); this.spellAbilityId = spellAbilityId; - this.manaCostsToReduce = manaCostsToReduce; + this.offeredPermanent = offeredPermanent; this.activationId = activationId; staticText = "mana costs reduction from offering"; } @@ -206,29 +205,38 @@ class OfferingCostReductionEffect extends CostModificationEffectImpl { OfferingCostReductionEffect(OfferingCostReductionEffect effect) { super(effect); this.spellAbilityId = effect.spellAbilityId; - this.manaCostsToReduce = effect.manaCostsToReduce; + this.offeredPermanent = effect.offeredPermanent; this.activationId = effect.activationId; } @Override public boolean apply(Game game, Ability source, Ability abilityToModify) { - CardUtil.reduceCost((SpellAbility) abilityToModify, manaCostsToReduce); - this.used = true; + Permanent toOffer = offeredPermanent.getPermanent(game); + if (toOffer != null) { + toOffer.sacrifice(source.getSourceId(), game); + CardUtil.reduceCost((SpellAbility) abilityToModify, toOffer.getSpellAbility().getManaCosts()); + } + game.getState().setValue("offering_" + source.getSourceId(), null); + game.getState().setValue("offering_ok_" + source.getSourceId(), null); + this.discard(); return true; } @Override public boolean applies(Ability abilityToModify, Ability source, Game game) { + if (CardUtil.isCheckPlayableMode(abilityToModify)) { // Cost modifaction does not work correctly for checking available spells + return false; + } if (abilityToModify.getId().equals(spellAbilityId) && abilityToModify instanceof SpellAbility) { Card card = game.getCard(source.getSourceId()); if (card != null) { - Object object = game.getState().getValue("offering_Id_" + card.getId()); - if (object != null && ((UUID) object).equals(this.activationId)) { - return true; - } + Object object = game.getState().getValue("offering_Id_" + card.getId()); + if (object != null && ((UUID) object).equals(this.activationId) && offeredPermanent.getPermanent(game) != null) { + return true; + } } // no or other id, this effect is no longer valid - this.used = true; + this.discard(); } return false; }