diff --git a/projects/mtg/include/ExtraCost.h b/projects/mtg/include/ExtraCost.h index 9d3690e99..c6a8e1438 100644 --- a/projects/mtg/include/ExtraCost.h +++ b/projects/mtg/include/ExtraCost.h @@ -299,7 +299,8 @@ public: class Offering : public ExtraCost { public: - Offering(TargetChooser *_tc = NULL); + bool emerge; + Offering(TargetChooser *_tc = NULL, bool emerge = false); virtual int canPay(); virtual int isPaymentSet(); virtual int doPay(); diff --git a/projects/mtg/src/ExtraCost.cpp b/projects/mtg/src/ExtraCost.cpp index 33efc8d53..98609951b 100644 --- a/projects/mtg/src/ExtraCost.cpp +++ b/projects/mtg/src/ExtraCost.cpp @@ -1128,8 +1128,8 @@ Offering * Offering::clone() const return ec; } -Offering::Offering(TargetChooser *_tc) : -ExtraCost("Select creature to offer", _tc) +Offering::Offering(TargetChooser *_tc,bool emerge) : +ExtraCost("Select creature to offer", _tc), emerge(emerge) { } @@ -1137,28 +1137,77 @@ int Offering::canPay() { if (target && target->has(Constants::CANTBESACRIFIED)) return 0; - - if (target && (!source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) + if (emerge) { - tc->removeTarget(target); - target = NULL; - return 0; + if (target) + { + ManaCost * reduced = NEW ManaCost(source->getManaCost()); + reduced->remove(Constants::MTG_COLOR_ARTIFACT, target->getManaCost()->getConvertedCost()); + + if (target && (!source->controller()->getManaPool()->canAfford(reduced))) + { + tc->removeTarget(target); + target = NULL; + SAFE_DELETE(reduced); + return 0; + } + if (target && source->controller()->getManaPool()->canAfford(reduced)) + { + SAFE_DELETE(reduced); + return 1; + } + } + + } + else + { + if (target && (!source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) + { + tc->removeTarget(target); + target = NULL; + return 0; + } + if (target && (source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) + return 1; } - if (target && (source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) - return 1; return 0; } int Offering::isPaymentSet() { - if (target && (!source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) + if (emerge) { - tc->removeTarget(target); - target = NULL; - return 0; + if (target) + { + ManaCost * reduced = NEW ManaCost(source->getManaCost()); + reduced->remove(Constants::MTG_COLOR_ARTIFACT, target->getManaCost()->getConvertedCost()); + + if (target && (!source->controller()->getManaPool()->canAfford(reduced))) + { + tc->removeTarget(target); + target = NULL; + SAFE_DELETE(reduced); + return 0; + } + if (target && source->controller()->getManaPool()->canAfford(reduced)) + { + SAFE_DELETE(reduced); + return 1; + } + } + + } + else + { + if (target && (!source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) + { + tc->removeTarget(target); + target = NULL; + return 0; + } + if (target && (source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) + return 1; } - if (target && (source->controller()->getManaPool()->canAfford(source->getManaCost()->Diff(target->getManaCost())))) - return 1; return 0; } @@ -1166,6 +1215,14 @@ int Offering::doPay() { if (target) { + if (emerge) + { + ManaCost * reduced = NEW ManaCost(source->getManaCost()); + reduced->remove(Constants::MTG_COLOR_ARTIFACT, target->getManaCost()->getConvertedCost()); + target->controller()->getManaPool()->pay(reduced); + SAFE_DELETE(reduced); + } + else target->controller()->getManaPool()->pay(source->getManaCost()->Diff(target->getManaCost())); MTGCardInstance * beforeCard = target; source->storedCard = target->createSnapShot(); diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index b2c1c3521..c33f1cf17 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -153,6 +153,13 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan } break; case 'e': + if (value == "emerge") + { + if (!tc) + tc = tcf.createTargetChooser("creature|mybattlefield", c); + manaCost->addExtraCost(NEW Offering(tc,true)); + } + else //Exile manaCost->addExtraCost(NEW ExileTargetCost(tc)); break;