diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index cd1c0147a..cd1ecd793 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -929,8 +929,9 @@ class GenericActivatedAbility: public ActivatedAbility, public NestedAbility public: MTGGameZone * activeZone; string newName; + string castRestriction; - GenericActivatedAbility(string newName,int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", + GenericActivatedAbility(string newName,string castRestriction,int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", int restrictions = 0, MTGGameZone * dest = NULL); int resolve(); const char * getMenuText(); @@ -1040,8 +1041,9 @@ public: int counters; MTGGameZone * activeZone; string newName; + string castRestriction; - GenericTargetAbility(string newName,int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, ManaCost * _cost = NULL, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", int restrictions = 0, MTGGameZone * dest = NULL); + GenericTargetAbility(string newName, string castRestriction, int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, ManaCost * _cost = NULL, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", int restrictions = 0, MTGGameZone * dest = NULL); const char * getMenuText(); ~GenericTargetAbility(); GenericTargetAbility * clone() const; diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index dd74506f3..23270482e 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -244,6 +244,7 @@ public: virtual int resolve() = 0; virtual TriggeredAbility* clone() const = 0; virtual ostream& toString(ostream& out) const; + string castRestriction; }; @@ -333,8 +334,9 @@ public: MTGAbility* sa; string usesBeforeSideEffects; int uses; + string castRestriction; - ActivatedAbility(int id, MTGCardInstance* card, ManaCost* _cost = NULL, int _restrictions = NO_RESTRICTION, string limit = "", MTGAbility* sideEffect = NULL, string usesBeforeSideEffects = ""); + ActivatedAbility(int id, MTGCardInstance* card, ManaCost* _cost = NULL, int _restrictions = NO_RESTRICTION, string limit = "", MTGAbility* sideEffect = NULL, string usesBeforeSideEffects = "",string castRestriction = ""); virtual ~ActivatedAbility(); virtual void Update(float dt) @@ -358,8 +360,8 @@ public: class TargetAbility : public ActivatedAbility, public NestedAbility { public: - TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0); - TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0); + TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0, string castRestriction = ""); + TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0, string castRestriction = ""); ~TargetAbility(); virtual int reactToClick(MTGCardInstance * card); diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 9cd26fd5b..eb3ff6771 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -6,9 +6,9 @@ //Activated Abilities //Generic Activated Abilities -GenericActivatedAbility::GenericActivatedAbility(string newName,int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, +GenericActivatedAbility::GenericActivatedAbility(string newName, string castRestriction, int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, string limit,MTGAbility * sideEffects,string usesBeforeSideEffects, int restrictions, MTGGameZone * dest) : - ActivatedAbility(_id, card, _cost, restrictions,limit,sideEffects,usesBeforeSideEffects), NestedAbility(a), activeZone(dest),newName(newName) + ActivatedAbility(_id, card, _cost, restrictions,limit,sideEffects,usesBeforeSideEffects,castRestriction), NestedAbility(a), activeZone(dest),newName(newName),castRestriction(castRestriction) { counters = 0; target = ability->target; @@ -2468,9 +2468,9 @@ MultiAbility::~MultiAbility() } //Generic Target Ability -GenericTargetAbility::GenericTargetAbility(string newName,int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, +GenericTargetAbility::GenericTargetAbility(string newName, string castRestriction,int _id, MTGCardInstance * _source, TargetChooser * _tc, MTGAbility * a, ManaCost * _cost, string limit,MTGAbility * sideEffects,string usesBeforeSideEffects, int restrictions, MTGGameZone * dest) : - TargetAbility(_id, _source, _tc, _cost, restrictions), limit(limit), activeZone(dest),newName(newName) + TargetAbility(_id, _source, _tc, _cost, restrictions,castRestriction), limit(limit), activeZone(dest),newName(newName),castRestriction(castRestriction) { ability = a; MTGAbility * core = AbilityFactory::getCoreAbility(a); diff --git a/projects/mtg/src/GameStateAwards.cpp b/projects/mtg/src/GameStateAwards.cpp index 7a17230eb..a12a6b760 100644 --- a/projects/mtg/src/GameStateAwards.cpp +++ b/projects/mtg/src/GameStateAwards.cpp @@ -176,7 +176,6 @@ void GameStateAwards::Update(float dt) else { JButton key = JGE_BTN_NONE; - int x, y; while ((key = JGE::GetInstance()->ReadButton())) { switch (key) diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index d0d92206f..ad075fd9e 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -761,6 +761,12 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitTrigger.size()) { TriggeredAbility * trigger = parseTrigger(splitTrigger[1], s, id, spell, card, target); + if (splitTrigger[1].find("restriction{") != string::npos)//using other/cast restrictions for abilities. + { + vector splitRest = parseBetween(s,"restriction{","}"); + if (splitRest.size()) + trigger->castRestriction = splitRest[1]; + } //Dirty way to remove the trigger text (could get in the way) if (trigger) { @@ -793,7 +799,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } int restrictions = parseRestriction(s); - + string castRestriction = ""; + if (s.find("restriction{") != string::npos)//using other/cast restrictions for abilities. + { + vector splitRest = parseBetween(s,"restriction{","}"); + if (splitRest.size()) + castRestriction = splitRest[1]; + } string newName = ""; vector splitName = parseBetween(s, "name(", ")"); if (splitName.size()) @@ -887,6 +899,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG amp->sideEffect = sideEffect; amp->usesBeforeSideEffects = usesBeforeSideEffect; amp->restrictions = restrictions; + amp->castRestriction = castRestriction; return amp; } @@ -905,9 +918,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (tc) { tc->belongsToAbility = sWithoutTc; - return NEW GenericTargetAbility(newName,id, card, tc, a, cost, limit,sideEffect,usesBeforeSideEffect, restrictions, dest); + return NEW GenericTargetAbility(newName,castRestriction,id, card, tc, a, cost, limit,sideEffect,usesBeforeSideEffect, restrictions, dest); } - return NEW GenericActivatedAbility(newName,id, card, a, cost, limit,sideEffect,usesBeforeSideEffect,restrictions, dest); + return NEW GenericActivatedAbility(newName,castRestriction,id, card, a, cost, limit,sideEffect,usesBeforeSideEffect,restrictions, dest); } SAFE_DELETE(cost); } @@ -963,9 +976,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return NULL; if (tc) - a1 = NEW GenericTargetAbility(newName,id, card, tc, a1); + a1 = NEW GenericTargetAbility(newName,castRestriction,id, card, tc, a1); else - a1 = NEW GenericActivatedAbility(newName,id, card, a1, NULL); + a1 = NEW GenericActivatedAbility(newName,castRestriction,id, card, a1, NULL); return NEW MayAbility(id, a1, card,mayMust[i]); } } @@ -1333,7 +1346,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG DebugTrace("ABILITYFACTORY Error parsing: " << s); return NULL; } - a = NEW GenericTargetAbility(newName,id, card, tc, a); + a = NEW GenericTargetAbility(newName,castRestriction,id, card, tc, a); return NEW MayAbility(id, a, card, true); } @@ -3527,8 +3540,8 @@ NestedAbility::NestedAbility(MTGAbility * _ability) // -ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _cost, int restrictions,string limit,MTGAbility * sideEffect,string usesBeforeSideEffects) : - MTGAbility(id, card), restrictions(restrictions), needsTapping(0),limit(limit),sideEffect(sideEffect),usesBeforeSideEffects(usesBeforeSideEffects) +ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _cost, int restrictions,string limit,MTGAbility * sideEffect,string usesBeforeSideEffects,string castRestriction) : + MTGAbility(id, card), restrictions(restrictions), needsTapping(0),limit(limit),sideEffect(sideEffect),usesBeforeSideEffects(usesBeforeSideEffects),castRestriction(castRestriction) { counters = 0; setCost(_cost); @@ -3595,6 +3608,13 @@ int ActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana) if (limitPerTurn && counters >= limitPerTurn) return 0; } + if(castRestriction.size()) + { + AbilityFactory af; + int checkCond = af.parseCastRestrictions(card,card->controller(),castRestriction); + if(!checkCond) + return 0; + } if (card == source && source->controller() == player && (!needsTapping || (!source->isTapped() && !source->hasSummoningSickness()))) { @@ -3752,14 +3772,14 @@ ostream& ActivatedAbility::toString(ostream& out) const return MTGAbility::toString(out) << ")"; } -TargetAbility::TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc, ManaCost * _cost, int _playerturnonly) : - ActivatedAbility(id, card, _cost, _playerturnonly), NestedAbility(NULL) +TargetAbility::TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc, ManaCost * _cost, int _playerturnonly, string castRestriction) : + ActivatedAbility(id, card, _cost, _playerturnonly, castRestriction), NestedAbility(NULL) { tc = _tc; } -TargetAbility::TargetAbility(int id, MTGCardInstance * card, ManaCost * _cost, int _playerturnonly) : - ActivatedAbility(id, card, _cost, _playerturnonly), NestedAbility(NULL) +TargetAbility::TargetAbility(int id, MTGCardInstance * card, ManaCost * _cost, int _playerturnonly, string castRestriction) : + ActivatedAbility(id, card, _cost, _playerturnonly, castRestriction), NestedAbility(NULL) { tc = NULL; } @@ -3959,6 +3979,15 @@ int Trigger::triggerOnEvent(WEvent * event) { if(mOnce && mActiveTrigger) mActiveTrigger = false; + if(castRestriction.size()) + { + if(!source) + return 1;//can't check these restrictions without a source aka:in a rule.txt + AbilityFactory af; + int checkCond = af.parseCastRestrictions(source,source->controller(),castRestriction); + if(!checkCond) + return 0; + } return 1; }