diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index 0875a5c5b..600549628 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -32,8 +32,9 @@ class GameObserver{ int currentRound; - int targetListIsSet(MTGCardInstance * card); + public: + int targetListIsSet(MTGCardInstance * card); PhaseRing * phaseRing; int cancelCurrentAction(); int currentGamePhase; diff --git a/projects/mtg/include/MTGRules.h b/projects/mtg/include/MTGRules.h index 03db93fcb..99971281f 100644 --- a/projects/mtg/include/MTGRules.h +++ b/projects/mtg/include/MTGRules.h @@ -8,6 +8,16 @@ #include "../include/Counters.h" +class MTGPutInPlayRule:public MTGAbility{ + public: + int isReactingToClick(MTGCardInstance * card); + int reactToClick(MTGCardInstance * card); + int testDestroy(); + MTGPutInPlayRule(int _id); + const char * getMenuText(){return "Put into play";} + +}; + class MTGAttackRule:public MTGAbility{ public: int isReactingToClick(MTGCardInstance * card); diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index fe854625c..ff16aaf6a 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -152,7 +152,9 @@ int ActionLayer::reactToClick(MTGCardInstance * card){ for (int i=0;igetMenuText()); result += currentAction->reactToClick(card); + if (result) return result; } return result; } diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 295ff99e6..099f7e416 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -19,6 +19,7 @@ void DuelLayers::init(){ MTGGamePhase * phaseManager = NEW MTGGamePhase(actionLayer->getMaxId()); actionLayer->Add(phaseManager); //Add Magic Specific Rules + actionLayer->Add(NEW MTGPutInPlayRule(-1)); actionLayer->Add(NEW MTGAttackRule(-1)); actionLayer->Add(NEW MTGBlockRule(-1)); actionLayer->Add(NEW MTGLegendRule(-1)); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 6a6bab569..327000bb5 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -307,26 +307,17 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){ if (reaction != -1){ if (!card) return; - if (currentlyActing()->game->hand->hasCard(card)){ - //Current player's hand - if (canPutInPlay(card)){ - putInPlay(card); - if (card->hasType("land")){ - currentPlayer->canPutLandsIntoPlay--; - } - }else if (currentPlayer->game->hand->hasCard(card)){ //Current player's hand - if (currentGamePhase == Constants::MTG_PHASE_CLEANUP && currentPlayer->game->hand->nb_cards > 7){ - currentPlayer->game->putInGraveyard(card); - } - } - }else if (reaction){ + //Current player's hand + if (currentPlayer->game->hand->hasCard(card) && currentGamePhase == Constants::MTG_PHASE_CLEANUP && currentPlayer->game->hand->nb_cards > 7){ + currentPlayer->game->putInGraveyard(card); + }else if (reaction){ if (reaction == 1){ mLayers->actionLayer()->reactToClick(card); }else{ mLayers->actionLayer()->setMenuObject(object); } }else if (card->isTapped() && card->controller() == currentPlayer){ - // int a = ConstraintResolver::untap(this, card); + ConstraintResolver::untap(this, card); } } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 644656241..088610a33 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1712,18 +1712,20 @@ int TargetAbility::reactToClick(MTGCardInstance * card){ if (isReactingToClick(card)){ waitingForAnswer = 1; tc->initTargets(); + return 1; } }else{ if (card == source){ if (tc->targetsReadyCheck() == TARGET_OK){ - waitingForAnswer = 0; - ActivatedAbility::reactToClick(source); + waitingForAnswer = 0; + return ActivatedAbility::reactToClick(source); } }else{ tc->toggleTarget(card); + return 1; } } - return 1; + return 0; } void TargetAbility::Render(){ diff --git a/projects/mtg/src/MTGGuiPlay.cpp b/projects/mtg/src/MTGGuiPlay.cpp index 303946063..1a769180c 100644 Binary files a/projects/mtg/src/MTGGuiPlay.cpp and b/projects/mtg/src/MTGGuiPlay.cpp differ diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 86a33908b..726268d28 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -1,6 +1,76 @@ #include "../include/config.h" #include "../include/MTGRules.h" +MTGPutInPlayRule::MTGPutInPlayRule(int _id):MTGAbility(_id, NULL){ + +} + +int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card){ + Player * player = game->currentlyActing(); + Player * currentPlayer = game->currentPlayer; + LOG("CANPUTINPLAY- check if card belongs to current player\n"); + if (!player->game->hand->hasCard(card)) return 0; + LOG("CANPUTINPLAY- check if card is land or can be played\n"); + if (card->hasType("land")){ + LOG("CANPUTINPLAY- card is land - check if can be played\n"); + if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)){ + LOG("CANPUTINPLAY- Land, ok\n"); + return 1; + } + }else if ((card->hasType("instant")) || card->has(Constants::FLASH) || (player == currentPlayer && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN))){ + LOG("CANPUTINPLAY- correct time to play\n"); + ManaCost * playerMana = player->getManaPool(); + ManaCost * cost = card->getManaCost(); + if (playerMana->canAfford(cost)){ + LOG("CANPUTINPLAY- ManaCost ok\n"); + if (game->targetListIsSet(card)){ +#ifdef LOG + LOG("CANPUTINPLAY- Targets chosen -> OK\n"); +#endif + return 1; + }else{ +#ifdef LOG + LOG("CANPUTINPLAY- Targets not chosen yet\n"); +#endif + return 0; + } + } + } + return 0; +} + +int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){ + if (!isReactingToClick(card)) return 0; + Player * player = game->currentlyActing(); + ManaCost * previousManaPool = NEW ManaCost(player->getManaPool()); + player->getManaPool()->pay(card->getManaCost()); + ManaCost * spellCost = previousManaPool->Diff(player->getManaPool()); + delete previousManaPool; + if (card->hasType("land")){ + Spell * spell = NEW Spell(card); + player->game->putInZone(card, player->game->hand, player->game->stack); + spell->resolve(); + delete spellCost; + delete spell; + player->canPutLandsIntoPlay--; + }else{ + if (game->targetChooser){ + game->mLayers->stackLayer()->addSpell(card,game->targetChooser->targets,game->targetChooser->cursor, spellCost); + SAFE_DELETE(game->targetChooser); + }else{ + game->mLayers->stackLayer()->addSpell(card,NULL,0, spellCost); + } + player->game->putInZone(card, player->game->hand, player->game->stack); + + } + return 1; +} + +//The Put into play rule is never destroyed +int MTGPutInPlayRule::testDestroy(){ + return 0; +} + MTGAttackRule::MTGAttackRule(int _id):MTGAbility(_id,NULL){ }