From e7fc20bd4c807f9e433da9c42c524089b47e06ed Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Wed, 2 Feb 2011 18:22:08 +0000 Subject: [PATCH] added this(damaged) added targetchooser [damaged] status added targetchooser [controllerdamager] targetchooser [opponentdamager] basically checks for whos doing damage to who in a match per turn. --- projects/mtg/include/CardDescriptor.h | 2 ++ projects/mtg/include/MTGCardInstance.h | 22 +++++++++------ projects/mtg/include/ThisDescriptor.h | 7 +++++ projects/mtg/src/CardDescriptor.cpp | 17 ++++++++++++ projects/mtg/src/Damage.cpp | 10 +++++++ projects/mtg/src/GameObserver.cpp | 6 +++- projects/mtg/src/MTGCardInstance.cpp | 6 +++- projects/mtg/src/TargetChooser.cpp | 38 +++++++++++++++++++++++++- projects/mtg/src/ThisDescriptor.cpp | 27 ++++++++++++++++++ 9 files changed, 123 insertions(+), 12 deletions(-) diff --git a/projects/mtg/include/CardDescriptor.h b/projects/mtg/include/CardDescriptor.h index 36cb3ab3f..648647a3f 100644 --- a/projects/mtg/include/CardDescriptor.h +++ b/projects/mtg/include/CardDescriptor.h @@ -59,6 +59,8 @@ class CardDescriptor: public MTGCardInstance{ int nameComparisonMode; int colorComparisonMode; string compareName; + int CDopponentDamaged; + int CDcontrollerDamaged; }; #endif diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index e12bca948..fc9905430 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -50,8 +50,11 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { int sunburst; int equipment; int auras; + bool wasDealtDamage; + bool damageToOpponent; + bool damageToController; int reduxamount; - int flanked; + int flanked; int regenerateTokens; int isToken; int origpower; @@ -65,6 +68,7 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { int isLeveler; bool enchanted; int CDenchanted; + int CDdamaged; bool blinked; bool isExtraCostTarget; bool morphed; @@ -75,14 +79,14 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { int phasedTurn; bool graveEffects; bool exileEffects; - - int stillInUse(); - int didattacked; - int didblocked; - int notblocked; - int fresh; - int MaxLevelUp; - Player * lastController; + + int stillInUse(); + int didattacked; + int didblocked; + int notblocked; + int fresh; + int MaxLevelUp; + Player * lastController; MTGGameZone * getCurrentZone(); MTGGameZone * previousZone; MTGCardInstance * previous; diff --git a/projects/mtg/include/ThisDescriptor.h b/projects/mtg/include/ThisDescriptor.h index 7483ea3b6..c58caaaa7 100644 --- a/projects/mtg/include/ThisDescriptor.h +++ b/projects/mtg/include/ThisDescriptor.h @@ -105,6 +105,13 @@ class ThisNotBlocked:public ThisDescriptor{ ThisNotBlocked(int unblocked); }; +class ThisDamaged:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisDamaged(int wasDealtDamage); +}; + class ThisPower:public ThisDescriptor{ public: virtual int match(MTGCardInstance * card); diff --git a/projects/mtg/src/CardDescriptor.cpp b/projects/mtg/src/CardDescriptor.cpp index 7ec433fe3..46d243ffc 100644 --- a/projects/mtg/src/CardDescriptor.cpp +++ b/projects/mtg/src/CardDescriptor.cpp @@ -20,6 +20,8 @@ CardDescriptor::CardDescriptor() : MTGCardInstance() compareName =""; nameComparisonMode = COMPARISON_NONE; colorComparisonMode = COMPARISON_NONE; + CDopponentDamaged = 0; + CDcontrollerDamaged = 0; } int CardDescriptor::init() @@ -281,6 +283,21 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card) { match = NULL; } + if ((CDdamaged == -1 && card->wasDealtDamage) || (CDdamaged == 1 && !card->wasDealtDamage)) + { + match = NULL; + } + Player * p = controller()->opponent(); + if ((CDopponentDamaged == -1 && card->damageToOpponent && card->controller() == p) || (CDopponentDamaged == 1 && !card->damageToOpponent && card->controller() == p) + || (CDopponentDamaged == -1 && card->damageToController && card->controller() == p->opponent()) || (CDopponentDamaged == 1 && !card->damageToController && card->controller() == p->opponent())) + { + match = NULL; + } + if ((CDcontrollerDamaged == -1 && card->damageToController && card->controller() == p) || (CDcontrollerDamaged == 1 && !card->damageToController && card->controller() == p) + || (CDcontrollerDamaged == -1 && card->damageToOpponent && card->controller() == p->opponent()) || (CDcontrollerDamaged == 1 && !card->damageToOpponent && card->controller() == p->opponent())) + { + match = NULL; + } if ((isToken == -1 && card->isToken) || (isToken == 1 && !card->isToken)) { match = NULL; diff --git a/projects/mtg/src/Damage.cpp b/projects/mtg/src/Damage.cpp index f70e8d1c7..220003abe 100644 --- a/projects/mtg/src/Damage.cpp +++ b/projects/mtg/src/Damage.cpp @@ -171,8 +171,18 @@ int Damage::resolve() //return the left over amount after effects have been applied to them. a = target->dealDamage(damage); target->damageCount += 1; + if (target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE) + ((MTGCardInstance*)target)->wasDealtDamage = true; if (target->type_as_damageable == DAMAGEABLE_PLAYER) { + if(target == source->controller()) + { + ((MTGCardInstance*)source)->damageToController = true; + } + else + { + ((MTGCardInstance*)source)->damageToOpponent = true; + } target->lifeLostThisTurn += damage; WEvent * lifed = NEW WEventLife((Player*)target,-damage); GameObserver * game = GameObserver::GetInstance(); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 7055c336a..be483813b 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -620,7 +620,7 @@ void GameObserver::gameStateBasedEffects() ///////////////////////////////////////////////// //handle end of turn effects while we're at it.// ///////////////////////////////////////////////// - if (currentGamePhase == Constants::MTG_PHASE_ENDOFTURN) + if (currentGamePhase == Constants::MTG_PHASE_ENDOFTURN+1) { for (int j = 0; j < nbcards; ++j) { @@ -637,6 +637,10 @@ void GameObserver::gameStateBasedEffects() c->flanked -= 1; } if (c->fresh) c->fresh = 0; + if(c->wasDealtDamage && c->isInPlay()) + c->wasDealtDamage = false; + c->damageToController = false; + c->damageToOpponent = false; if (c->has(Constants::ONLYONEBOTH)) { c->controller()->castcount = 0; diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index 0a2516bdd..513225a1b 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -127,6 +127,7 @@ void MTGCardInstance::initMTGCI() isLeveler = 0; enchanted = false; CDenchanted = NULL; + CDdamaged = 0; blinked = false; isExtraCostTarget = false; morphed = false; @@ -141,7 +142,10 @@ void MTGCardInstance::initMTGCI() sunburst = NULL; equipment = 0; auras = 0; - + damageToOpponent = false; + damageToController = false; + wasDealtDamage = false; + for (int i = 0; i < ManaCost::MANA_PAID_WITH_RETRACE +1; i++) alternateCostPaid[i] = 0; diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index 11059d5ff..3692466c7 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -337,7 +337,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta cd->isLeveler = 1; } } - //creature is a level up creature + //creature is enchanted else if (attribute.find("enchanted") != string::npos) { if (minus) @@ -349,6 +349,42 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta cd->CDenchanted = 1; } } + //creature was damaged + else if (attribute.find("damaged") != string::npos) + { + if (minus) + { + cd->CDdamaged = -1; + } + else + { + cd->CDdamaged = 1; + } + } + //creature dealt damage to opponent + else if (attribute.find("opponentdamager") != string::npos) + { + if (minus) + { + cd->CDopponentDamaged = -1; + } + else + { + cd->CDopponentDamaged = 1; + } + } + //creature dealt damage to controller + else if (attribute.find("controllerdamager") != string::npos) + { + if (minus) + { + cd->CDcontrollerDamaged = -1; + } + else + { + cd->CDcontrollerDamaged = 1; + } + } else if (attribute.find("multicolor") != string::npos) { //card is multicolored? diff --git a/projects/mtg/src/ThisDescriptor.cpp b/projects/mtg/src/ThisDescriptor.cpp index 4057e21fa..570de788e 100644 --- a/projects/mtg/src/ThisDescriptor.cpp +++ b/projects/mtg/src/ThisDescriptor.cpp @@ -228,6 +228,19 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s) return NULL; } + //this creature was dealt damage this turn + found = s.find("damaged"); + if (found != string::npos) + { + ThisDamaged * td = NEW ThisDamaged(criterion); + if (td) + { + td->comparisonMode = mode; + return td; + } + return NULL; + } + //controller life found = s.find("opponentlife"); if (found != string::npos) @@ -443,6 +456,20 @@ int ThisNotBlocked::match(MTGCardInstance * card) return matchValue(card->notblocked); } +ThisDamaged::ThisDamaged(int wasDealtDamage) +{ + + comparisonCriterion = wasDealtDamage; +} + +int ThisDamaged::match(MTGCardInstance * card) +{ +int result = 0; +if(card->wasDealtDamage) +result = 1; + return matchValue(result); +} + ThisToughness::ThisToughness(int toughness) { comparisonCriterion = toughness;