diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 5736643a5..125614e6a 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -886,12 +886,13 @@ class AACounter: public ActivatedAbility public: string counterstring; int nb; + int maxNb; int power; int toughness; string name; string menu; - AACounter(int id, MTGCardInstance * source, MTGCardInstance * target,string counterstring, const char * _name, int power, int toughness, int nb, + AACounter(int id, MTGCardInstance * source, MTGCardInstance * target,string counterstring, const char * _name, int power, int toughness, int nb,int maxNb = 0, ManaCost * cost = NULL, int doTap = 0); int resolve(); diff --git a/projects/mtg/include/Counters.h b/projects/mtg/include/Counters.h index 3bf58e142..a2365b3ee 100644 --- a/projects/mtg/include/Counters.h +++ b/projects/mtg/include/Counters.h @@ -11,6 +11,7 @@ class Counter public: string name; int nb; + int maxNb; int power, toughness; MTGCardInstance * target; Counter(MTGCardInstance * _target, int _power, int _toughness); diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 218ab8fe4..7af332dc5 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -287,8 +287,8 @@ AAPhaseOut * AAPhaseOut::clone() const //Counters AACounter::AACounter(int id, MTGCardInstance * source, MTGCardInstance * target,string counterstring, const char * _name, int power, int toughness, - int nb, ManaCost * cost, int doTap) : - ActivatedAbility(id, source, cost, 0, doTap),counterstring(counterstring), nb(nb), power(power), toughness(toughness), name(_name) + int nb,int maxNb, ManaCost * cost, int doTap) : + ActivatedAbility(id, source, cost, 0, doTap),counterstring(counterstring), nb(nb),maxNb(maxNb), power(power), toughness(toughness), name(_name) { this->target = target; if (name.find("Level")) @@ -307,13 +307,22 @@ AACounter::AACounter(int id, MTGCardInstance * source, MTGCardInstance * target, delete checkcounter; if (nb > 0) { - for (int i = 0; i < nb; i++) - { - while (_target->next) - _target = _target->next; - _target->counters->addCounter(name.c_str(), power, toughness); + for (int i = 0; i < nb; i++) + { + while (_target->next) + _target = _target->next; + + Counter * targetCounter = NULL; + int currentAmount = 0; + if (_target->counters && _target->counters->hasCounter(name.c_str(), power, toughness)) + { + targetCounter = _target->counters->hasCounter(name.c_str(), power, toughness); + currentAmount = targetCounter->nb; + } + if(!maxNb || (maxNb && currentAmount < maxNb)) + _target->counters->addCounter(name.c_str(), power, toughness); + } } - } else { for (int i = 0; i < -nb; i++) diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 20a8db5ee..1747591c9 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -214,6 +214,7 @@ int AbilityFactory::countCards(TargetChooser * tc, Player * player, int option) Counter * AbilityFactory::parseCounter(string s, MTGCardInstance * target, Spell * spell) { int nb = 1; + int maxNb = 0; string name = ""; size_t start = 0; size_t end = s.length(); @@ -225,9 +226,15 @@ Counter * AbilityFactory::parseCounter(string s, MTGCardInstance * target, Spell size_t separator2 = s.find(",", separator + 1); if (separator2 == string::npos) separator2 = s.find(".", separator + 1); + size_t separator3 = string::npos; if (separator2 != string::npos) { name = s.substr(separator2 + 1, end - separator2 - 1); + separator3 = s.find(",", separator2 + 1); + if (separator3 != string::npos) + { + name = s.substr(separator2 + 1,separator3 - separator2 - 1); + } } string nbstr = s.substr(separator + 1, separator2 - separator - 1); WParsedInt * wpi; @@ -241,6 +248,22 @@ Counter * AbilityFactory::parseCounter(string s, MTGCardInstance * target, Spell } nb = wpi->getValue(); delete (wpi); + string maxNbstr; + if (separator3 != string::npos) + { + maxNbstr = s.substr(separator3 + 1, end - separator3 - 1); + WParsedInt * wpinb; + if (target) + { + wpinb = NEW WParsedInt(maxNbstr, spell, target); + } + else + { + wpinb = NEW WParsedInt(atoi(maxNbstr.c_str())); + } + maxNb = wpinb->getValue(); + delete(wpinb); + } end = separator; } @@ -250,6 +273,7 @@ Counter * AbilityFactory::parseCounter(string s, MTGCardInstance * target, Spell { Counter * counter = NEW Counter(target, name.c_str(), power, toughness); counter->nb = nb; + counter->maxNb = maxNb; return counter; } return NULL; @@ -2330,7 +2354,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (counter) { MTGAbility * a = - NEW AACounter(id, card, target,counterString, counter->name.c_str(), counter->power, counter->toughness, counter->nb); + NEW AACounter(id, card, target,counterString, counter->name.c_str(), counter->power, counter->toughness, counter->nb,counter->maxNb); delete (counter); a->oneShot = 1; return a;