From 4960969640b5f4ec60738f6f01aef758f6d526bb Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Sat, 5 Jan 2013 03:05:53 +0000 Subject: [PATCH] added {unattach} cost this can also be used for "equipped creature has unattach and blah" cards using auto=teach(creature) {unattach}:blah also corrected a long standing guiupdating issue. a long long time ago a replace was removed from GuiPlay::Update in hopes to increase performance no amount of performance increase is worth having cards not updating thier position after an event recieve happens. this means curse will finally go to the correctly choosen players battlefield, equipment will no longer just linger after its target dies, auras won't stay on battlefield after a card is exiled. ect. no preformance decrease noticed, if anyone else notices one let me know. --- projects/mtg/include/ExtraCost.h | 11 +++++++ projects/mtg/src/ExtraCost.cpp | 50 ++++++++++++++++++++++++++++++++ projects/mtg/src/GuiPlay.cpp | 4 ++- projects/mtg/src/ManaCost.cpp | 7 ++++- 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/projects/mtg/include/ExtraCost.h b/projects/mtg/include/ExtraCost.h index 432b01c63..c0db8f3f4 100644 --- a/projects/mtg/include/ExtraCost.h +++ b/projects/mtg/include/ExtraCost.h @@ -142,6 +142,17 @@ public: virtual int doPay(); }; +//unattach cost +class unattachCost : public ExtraCost +{ +public: + unattachCost(MTGCardInstance * realSource = NULL); + MTGCardInstance * rSource; + virtual int isPaymentSet(); + virtual int canPay(); + virtual int doPay(); + virtual unattachCost * clone() const; +}; //tap cost class TapCost : public ExtraCost { diff --git a/projects/mtg/src/ExtraCost.cpp b/projects/mtg/src/ExtraCost.cpp index 2cb204bce..07912812d 100644 --- a/projects/mtg/src/ExtraCost.cpp +++ b/projects/mtg/src/ExtraCost.cpp @@ -6,6 +6,7 @@ #include "Translate.h" #include "Player.h" #include "Counters.h" +#include "AllAbilities.h" SUPPORT_OBJECT_ANALYTICS(ExtraCost) @@ -329,6 +330,7 @@ int MillCost::doPay() return 0; } + MillExileCost::MillExileCost(TargetChooser *_tc) : MillCost(_tc) { @@ -352,6 +354,54 @@ int MillExileCost::doPay() } return 0; } +//unattach cost + +unattachCost * unattachCost::clone() const +{ + unattachCost * ec = NEW unattachCost(*this); + return ec; +} + +unattachCost::unattachCost(MTGCardInstance * realSource) + : ExtraCost("Unattach"),rSource(realSource) +{ +} + +int unattachCost::isPaymentSet() +{ + if (rSource && !rSource->target) + { + return 0; + } + return 1; +} + +int unattachCost::canPay() +{ + return isPaymentSet(); +} + +int unattachCost::doPay() +{ + MTGCardInstance * _source = (MTGCardInstance *) source; + if(_source != rSource) + _source = rSource;//for debugging purposes I let it set what it thinks is the source. + if (_source) + { + GameObserver * game = _source->getObserver(); + for (size_t i = 1; i < game->mLayers->actionLayer()->mObjects.size(); i++) + { + MTGAbility * a = ((MTGAbility *) game->mLayers->actionLayer()->mObjects[i]); + AEquip * eq = dynamic_cast (a); + if (eq && eq->source == _source) + { + ((AEquip*)a)->unequip(); + } + } + return 1; + } + return 0; +} //Tap cost TapCost * TapCost::clone() const diff --git a/projects/mtg/src/GuiPlay.cpp b/projects/mtg/src/GuiPlay.cpp index ffd00a833..471f96735 100644 --- a/projects/mtg/src/GuiPlay.cpp +++ b/projects/mtg/src/GuiPlay.cpp @@ -284,6 +284,7 @@ void GuiPlay::Render() battleField.Render(); for (iterator it = cards.begin(); it != cards.end(); ++it) + { if ((*it)->card->isLand()) { if (observer->players[0] == (*it)->card->controller()) @@ -318,7 +319,7 @@ void GuiPlay::Render() opponentPlaneswalker.Render(*it, cards.begin(), end_spells); } } - + } } void GuiPlay::Update(float dt) { @@ -404,6 +405,7 @@ int GuiPlay::receiveEventPlus(WEvent * e) } else if (dynamic_cast (e)) Replace(); + Replace(); return 0; } diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index c0596278d..388d8d73b 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -229,8 +229,13 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan } break; } - default: //uncolored cost and hybrid costs + default: //uncolored cost and hybrid costs and special cost { + if(value == "unattach") + { + manaCost->addExtraCost(NEW unattachCost(c)); + break; + } int intvalue = atoi(value.c_str()); int colors[2]; int values[2];