diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index b04eed4a1..82824567d 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -82,6 +82,7 @@ class MTGAbility: public ActionElement{ PUT_INTO_PLAY = 5, MOMIR = 6, MTG_BLOCK_RULE = 7, + ALTERNATIVE_COST = 8, }; }; diff --git a/projects/mtg/include/MTGRules.h b/projects/mtg/include/MTGRules.h index 3d613b6a7..b6c0005da 100644 --- a/projects/mtg/include/MTGRules.h +++ b/projects/mtg/include/MTGRules.h @@ -24,10 +24,21 @@ class MTGPutInPlayRule:public MTGAbility{ int testDestroy(); virtual ostream& toString(ostream& out) const; MTGPutInPlayRule(int _id); - const char * getMenuText(){return "Put into play";} + const char * getMenuText(){return "Play Card Normally";} virtual MTGPutInPlayRule * clone() const; }; +class MTGAlternativeCostRule:public MTGAbility{ + public: + int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); + int reactToClick(MTGCardInstance * card); + int testDestroy(); + virtual ostream& toString(ostream& out) const; + MTGAlternativeCostRule(int _id); + const char * getMenuText(){return "Pay Alternative Cost";} + virtual MTGAlternativeCostRule * clone() const; +}; + class MTGAttackRule:public MTGAbility, public Limitor{ public: virtual bool select(Target*); diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index ffcc528e1..cbe6a2119 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -21,6 +21,7 @@ void DuelLayers::init(){ action->Add(NEW MTGGamePhase(action->getMaxId())); //Add Magic Specific Rules action->Add(NEW MTGPutInPlayRule(-1)); + action->Add(NEW MTGAlternativeCostRule(-1)); action->Add(NEW MTGAttackRule(-1)); action->Add(NEW MTGBlockRule(-1)); action->Add(NEW MTGLegendRule(-1)); diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index ed99fc747..8f14fa0ae 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -44,9 +44,6 @@ int cardsinhand = game->players[0]->game->hand->nb_cards; if(player->castrestrictedcreature > 0 && card->hasType("creature")){return 0;} //cost of card. - if(alternative && playerMana->canAfford(alternative)){ - return 1; - } if (playerMana->canAfford(cost)){ return 1;//play if you can afford too. } @@ -57,23 +54,9 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){ if (!isReactingToClick(card)) return 0; Player * player = game->currentlyActing(); ManaCost * cost = card->getManaCost(); - ManaCost * alternative = card->getManaCost()->alternative; ManaCost * playerMana = player->getManaPool(); //this handles extra cost payments at the moment a card is played. -//as long as you dont have enough mana to pay the real cost, and the alternative contains extra cost, add extras - if(!playerMana->canAfford(cost) && playerMana->canAfford(alternative)){ - if (cost->alternative->isExtraPaymentSet()){ - if (!game->targetListIsSet(card)){ - return 0; - } - }else{ - cost->alternative->setExtraCostsAction(this, card); - game->waitForExtraPayment = cost->alternative->extraCosts; - return 0; - } - } -//------------------------------------------------------------------------ if (cost->isExtraPaymentSet()){ if (!game->targetListIsSet(card)){ return 0; @@ -88,13 +71,6 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){ int payResult = player->getManaPool()->pay(card->getManaCost()); card->getManaCost()->doPayExtra(); - -//if alternative has a extra payment thats set, this code pays it.the if statement is 100% needed as it would cause a crash on cards that dont have the alternative cost. - if(alternative){ - card->getManaCost()->alternative->doPayExtra();} -//--------------------------------------------------------------------------- - - ManaCost * spellCost = previousManaPool->Diff(player->getManaPool()); delete previousManaPool; @@ -153,6 +129,143 @@ ostream& MTGPutInPlayRule::toString(ostream& out) const //cast from anywhere possible with this?? +//Alternative cost rules + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + +MTGAlternativeCostRule::MTGAlternativeCostRule(int _id):MTGAbility(_id, NULL){ + aType=MTGAbility::ALTERNATIVE_COST; +} +int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana){ +int cardsinhand = game->players[0]->game->hand->nb_cards; + Player * player = game->currentlyActing(); + Player * currentPlayer = game->currentPlayer; + if (!player->game->hand->hasCard(card)) return 0; + if (!card->getManaCost()->alternative) return 0; + if (card->hasType("land")){ + if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)){ + return 1; + } + }else if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && !game->isInterrupting && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))){ + ManaCost * playerMana = player->getManaPool(); + ManaCost * cost = card->getManaCost(); + ManaCost * alternative = card->getManaCost()->alternative; + +#ifdef WIN32 + cost->Dump(); +#endif + if(player->castrestrictedspell > 0 && !card->hasType("land")){ return 0;} + if(player->onlyonecast > 0 && player->castcount >= 1){return 0;} + if(player->nospellinstant > 0){return 0;} + if(player->onlyoneinstant > 0){ if(player->castcount >= 1){return 0;}} + if(player->nocreatureinstant > 0 && card->hasType("creature")){return 0;} + if(player->castrestrictedcreature > 0 && card->hasType("creature")){return 0;} + //cost of card. + if(alternative && playerMana->canAfford(alternative)){ + return 1; + } + } + return 0;//dont play if you cant afford it. +} +int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card){ + if (!isReactingToClick(card)) return 0; + Player * player = game->currentlyActing(); + ManaCost * cost = card->getManaCost(); + ManaCost * alternative = card->getManaCost()->alternative; + ManaCost * playerMana = player->getManaPool(); +//this handles extra cost payments at the moment a card is played. + if(playerMana->canAfford(alternative)){ + if (cost->alternative->isExtraPaymentSet()){ + if (!game->targetListIsSet(card)){ + return 0; + } + }else{ + cost->alternative->setExtraCostsAction(this, card); + game->waitForExtraPayment = cost->alternative->extraCosts; + return 0; + } + } +//------------------------------------------------------------------------ + ManaCost * previousManaPool = NEW ManaCost(player->getManaPool()); + int payResult = player->getManaPool()->pay(card->getManaCost()->alternative); + card->getManaCost()->doPayExtra(); + payResult = ManaCost::MANA_PAID_WITH_ALTERNATIVE; +//if alternative has a extra payment thats set, this code pays it.the if statement is 100% needed as it would cause a crash on cards that dont have the alternative cost. + if(alternative){ + card->getManaCost()->alternative->doPayExtra(); + } +//--------------------------------------------------------------------------- + ManaCost * spellCost = previousManaPool->Diff(player->getManaPool()); + delete previousManaPool; + if (card->hasType("land")){ + MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->temp); + Spell * spell = NEW Spell(copy); + spell->resolve(); + delete spellCost; + delete spell; + player->canPutLandsIntoPlay--; + payResult = ManaCost::MANA_PAID_WITH_ALTERNATIVE; + spell = game->mLayers->stackLayer()->addSpell(copy,NULL, spellCost, payResult,1); + }else{ + Spell * spell = NULL; + MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->stack); + if (game->targetChooser){ + spell = game->mLayers->stackLayer()->addSpell(copy,game->targetChooser, spellCost,payResult,0); + game->targetChooser = NULL; + player->castedspellsthisturn += 1; + if(player->onlyonecast > 0 || player->onlyoneinstant > 0){player->castcount += 1;} + }else{ + spell = game->mLayers->stackLayer()->addSpell(copy,NULL, spellCost, payResult,0); + player->castedspellsthisturn += 1; + if(player->onlyonecast > 0 || player->onlyoneinstant > 0){player->castcount += 1; + } + } + if(card->has(Constants::STORM)){ + int storm = player->castedspellsthisturn; + ManaCost * spellCost = player->getManaPool(); + for(int i = storm; i > 1; i--){ + spell = game->mLayers->stackLayer()->addSpell(copy,NULL, spellCost, payResult,1); + } + }//end of storm + if(!card->has(Constants::STORM)){ + copy->X = spell->computeX(copy); + } + } + + return 1; +} + +//The Put into play rule is never destroyed +int MTGAlternativeCostRule::testDestroy(){ + return 0; +} + +ostream& MTGAlternativeCostRule::toString(ostream& out) const +{ + out << "MTGAlternativeCostRule ::: ("; + return MTGAbility::toString(out) << ")"; +} + MTGAlternativeCostRule * MTGAlternativeCostRule::clone() const{ + MTGAlternativeCostRule * a = NEW MTGAlternativeCostRule(*this); + a->isClone = 1; + return a; + } + + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + //------------------------------------------------------------------------- + + + + + + + + bool MTGAttackRule::select(Target* t) { if (CardView* c = dynamic_cast(t)) { diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index 0d75ae292..8673ebf01 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -371,19 +371,6 @@ int ManaCost::pay(ManaCost * _cost){ ManaCost * toPay = NEW ManaCost(); toPay->copy(_cost); - -//---if you can pay the cards real cost, it is paided instead and alternative is not used. - if (toPay->alternative && canAfford(toPay->alternative) && !canAfford(_cost)){ - //const char * getMenuText(){return "Put into play";} - toPay = toPay->alternative; - if (!canAfford(toPay) || canAfford(_cost)){ - toPay->copy(_cost); - } - result = MANA_PAID_WITH_ALTERNATIVE; - } - - - if (toPay->kicker){ toPay->add(toPay->kicker); if (!canAfford(toPay)){