From 78bfa604e239a469dc5e0a11599833c8498476fe Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Thu, 2 Mar 2017 21:46:29 +0800 Subject: [PATCH 1/2] tidy up attack menu --- projects/mtg/include/MTGCardInstance.h | 4 +- projects/mtg/include/MTGRules.h | 14 ++----- projects/mtg/src/MTGCardInstance.cpp | 14 ++++++- projects/mtg/src/MTGRules.cpp | 51 ++++++++++++++++++++++---- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 82cd9c42a..689ca4e61 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -161,12 +161,14 @@ public: MTGCardInstance * defenser; listblockers; int attacker; + int willattackplayer; + int willattackpw; int toggleDefenser(MTGCardInstance * opponent); int raiseBlockerRankOrder(MTGCardInstance * blocker); //Returns rank of the card in blockers if it is a blocker of this (starting at 1), 0 otherwise int getDefenserRank(MTGCardInstance * blocker); - int toggleAttacker(); + int toggleAttacker(bool pw = false); MTGCardInstance * banding; // If belongs to a band when attacking int canBlock(); int canBlock(MTGCardInstance * opponent); diff --git a/projects/mtg/include/MTGRules.h b/projects/mtg/include/MTGRules.h index 45cd82c56..913417a60 100644 --- a/projects/mtg/include/MTGRules.h +++ b/projects/mtg/include/MTGRules.h @@ -270,17 +270,14 @@ public: class MTGAttackRule: public PermanentAbility, public Limitor { public: - + string attackmenu; virtual bool select(Target*); virtual bool greyout(Target*); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); int reactToClick(MTGCardInstance * card); virtual ostream& toString(ostream& out) const; MTGAttackRule(GameObserver* observer, int _id); - const string getMenuText() - { - return "Attacker"; - } + const string getMenuText(); int receiveEvent(WEvent * event); virtual MTGAttackRule * clone() const; }; @@ -289,16 +286,13 @@ public: class MTGPlaneswalkerAttackRule: public PermanentAbility, public Limitor { public: - + string attackpwmenu; virtual bool select(Target*); virtual bool greyout(Target*); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); int reactToClick(MTGCardInstance * card); MTGPlaneswalkerAttackRule(GameObserver* observer, int _id); - const string getMenuText() - { - return "Attack Planeswalker"; - } + const string getMenuText(); virtual MTGPlaneswalkerAttackRule * clone() const; }; class AAPlaneswalkerAttacked: public InstantAbility diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index 62294f983..4313dbd62 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -37,6 +37,8 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to initMTGCI(); model = card; attacker = 0; + willattackplayer = 0; + willattackpw = 0; lifeOrig = life; origpower = power; basepower = origpower; @@ -1338,17 +1340,27 @@ int MTGCardInstance::setAttacker(int value) return 1; } -int MTGCardInstance::toggleAttacker() +int MTGCardInstance::toggleAttacker(bool pw) { if (!attacker) { //if (!basicAbilities[Constants::VIGILANCE]) tap(); + if(pw) + { + willattackpw = 1; + } + else + { + willattackplayer = 1; + } setAttacker(1); return 1; } else { //untap(); + willattackpw = 0; + willattackplayer = 0; setAttacker(0); isAttacking = NULL; return 1; diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 92a8c0dda..dbd79172e 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -1814,6 +1814,7 @@ MTGAttackRule::MTGAttackRule(GameObserver* observer, int _id) : PermanentAbility(observer, _id) { aType = MTGAbility::MTG_ATTACK_RULE; + attackmenu = ""; } int MTGAttackRule::isReactingToClick(MTGCardInstance * card, ManaCost *) @@ -1822,10 +1823,18 @@ int MTGAttackRule::isReactingToClick(MTGCardInstance * card, ManaCost *) { if(card->isPhased) return 0; - if (card->isAttacker()) - return 1; - if (card->canAttack() && card->attackCost < 1) + if ((card->isAttacker()) || (card->canAttack() && card->attackCost < 1)) + { + if(!card->isAttacker()) + attackmenu = "Attack Player"; + else + attackmenu = "Remove Attacker"; + + if(card->willattackpw) + return 0; + return 1; + } } return 0; } @@ -1904,10 +1913,16 @@ int MTGAttackRule::reactToClick(MTGCardInstance * card) game->getCardSelector()->Limit(NULL, CardView::playZone); game->getCardSelector()->PopLimitor(); } + card->toggleAttacker(); return 1; } +const string MTGAttackRule::getMenuText() +{ + return attackmenu; +} + ostream& MTGAttackRule::toString(ostream& out) const { out << "MTGAttackRule ::: ("; @@ -1923,6 +1938,7 @@ MTGPlaneswalkerAttackRule::MTGPlaneswalkerAttackRule(GameObserver* observer, int PermanentAbility(observer, _id) { aType = MTGAbility::MTG_ATTACK_RULE; + attackpwmenu = ""; } int MTGPlaneswalkerAttackRule::isReactingToClick(MTGCardInstance * card, ManaCost *) @@ -1933,10 +1949,18 @@ int MTGPlaneswalkerAttackRule::isReactingToClick(MTGCardInstance * card, ManaCos return 0; if(card->isPhased) return 0; - if (card->isAttacker()) - return 1; - if (card->canAttack(true) && card->attackPlaneswalkerCost < 1) + if ((card->isAttacker()) || (card->canAttack(true) && card->attackPlaneswalkerCost < 1)) + { + if(!card->isAttacker()) + attackpwmenu = "Attack Planeswalker"; + else + attackpwmenu = "Remove Attacker"; + + if(card->willattackplayer) + return 0; + return 1; + } } return 0; } @@ -1955,6 +1979,12 @@ int MTGPlaneswalkerAttackRule::reactToClick(MTGCardInstance * card) game->getCardSelector()->PopLimitor(); } + if(card->willattackpw) + { + card->toggleAttacker(true); + return 1; + } + vectorselection; MTGCardInstance * check = NULL; int checkWalkers = card->controller()->opponent()->game->battlefield->cards.size(); @@ -1978,10 +2008,15 @@ int MTGPlaneswalkerAttackRule::reactToClick(MTGCardInstance * card) game->mLayers->actionLayer()->currentActionCard = card; a1->resolve(); } - + return 1; } +const string MTGPlaneswalkerAttackRule::getMenuText() +{ + return attackpwmenu; +} + MTGPlaneswalkerAttackRule * MTGPlaneswalkerAttackRule::clone() const { return NEW MTGPlaneswalkerAttackRule(*this); @@ -2016,7 +2051,7 @@ int AAPlaneswalkerAttacked::resolve() if(!attacker) return 0; attacker->isAttacking = this->target; - attacker->toggleAttacker(); + attacker->toggleAttacker(true); return 1; } From e0f58e1916919a9c9d5cbea28fc05b5db6fa8197 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Fri, 3 Mar 2017 00:39:23 +0800 Subject: [PATCH 2/2] attack/block cost value --- projects/mtg/src/MTGRules.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index dbd79172e..ff6f334a9 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -1663,6 +1663,13 @@ int MTGAttackCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * aiCh return 0; if(card->attackCost < 1) return 0; + if(card->attackCost) + { + int number = card->attackCost; + WParsedInt parsedNum(number); + scost = _("Pay " + parsedNum.getStringValue() + " to attack").c_str(); + } + ManaCost * playerMana = card->controller()->getManaPool(); ManaCost * attackcost = NEW ManaCost(ManaCost::parseManaCost("{0}",NULL,NULL)); attackcost->add(0,card->attackCostBackup); @@ -1671,7 +1678,6 @@ int MTGAttackCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * aiCh { attackcost->extraCosts->costs[i]->setSource(card); } - scost = attackcost->getConvertedCost(); if ((aiCheck && aiCheck->canAfford(attackcost)) || playerMana->canAfford(attackcost)) { SAFE_DELETE(attackcost); @@ -1711,7 +1717,7 @@ ostream& MTGAttackCostRule::toString(ostream& out) const const string MTGAttackCostRule::getMenuText() { - sprintf(menuText, "Pay to attack"); + sprintf(menuText, "%s", scost.c_str()); return menuText; } @@ -1737,7 +1743,13 @@ int MTGBlockCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * aiChe return 0; if(card->blockCost < 1) return 0; - + if(card->blockCost) + { + int number = card->blockCost; + WParsedInt parsedNum(number); + scost = _("Pay " + parsedNum.getStringValue() + " to block").c_str(); + } + ManaCost * playerMana = card->controller()->getManaPool(); ManaCost * blockcost = NEW ManaCost(ManaCost::parseManaCost("{0}",NULL,NULL)); blockcost->add(0,card->blockCostBackup); @@ -1746,7 +1758,6 @@ int MTGBlockCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * aiChe { blockcost->extraCosts->costs[i]->setSource(card); } - scost = blockcost->getConvertedCost(); if ((aiCheck && aiCheck->canAfford(blockcost)) || playerMana->canAfford(blockcost)) { SAFE_DELETE(blockcost); @@ -1785,7 +1796,7 @@ ostream& MTGBlockCostRule::toString(ostream& out) const const string MTGBlockCostRule::getMenuText() { - sprintf(menuText, "Pay to block"); + sprintf(menuText, "%s", scost.c_str()); return menuText; }