added functionality to may and choice ability so that it can check a "restriction{}" like a activated ability with cost, that can keep a menu option from appearing if the restriction is not met

auto=choice damage:1 target(creature) restriction{type(creature[blue])~morethan~1}

this choice menu will only appear is there is more than one blue creature inplay
This commit is contained in:
omegablast2002@yahoo.com
2013-01-28 03:49:24 +00:00
parent a32a58f621
commit 2b9cae8950
3 changed files with 20 additions and 4 deletions

View File

@@ -1074,11 +1074,12 @@ class MayAbility: public MTGAbility, public NestedAbility
public:
int triggered;
bool must;
string Cond;
Player * previousInterrupter;
MTGAbility * mClone;
ManaCost * optionalCost;
MayAbility(GameObserver* observer, int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must = false);
MayAbility(GameObserver* observer, int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must = false, string restriction = "");
void Update(float dt);

View File

@@ -3077,8 +3077,8 @@ IfThenAbility::~IfThenAbility()
//
//May Abilities
MayAbility::MayAbility(GameObserver* observer, int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must) :
MTGAbility(observer, _id, _source), NestedAbility(_ability), must(must)
MayAbility::MayAbility(GameObserver* observer, int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must,string _cond) :
MTGAbility(observer, _id, _source), NestedAbility(_ability), must(must), Cond(_cond)
{
triggered = 0;
mClone = NULL;
@@ -3093,6 +3093,15 @@ void MayAbility::Update(float dt)
triggered = 1;
if(optionalCost && !source->controller()->getManaPool()->canAfford(optionalCost))
return;
if(Cond.size())
{
AbilityFactory af(game);
int checkCond = af.parseCastRestrictions(source,source->controller(),Cond);
if(!checkCond)
{
return;
}
}
if (TargetAbility * ta = dynamic_cast<TargetAbility *>(ability))
{
if (!ta->getActionTc()->validTargetsExist())

View File

@@ -1164,6 +1164,12 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
if (splitRest.size())
castRestriction = splitRest[1];
}
if (s.find("restriction{{") != string::npos)
{
vector<string> splitRest = parseBetween(s,"restriction{{","}}");
if (splitRest.size())
castRestriction = splitRest[1];
}
string newName = "";
vector<string> splitName = parseBetween(s, "name(", ")");
if (splitName.size())
@@ -1364,7 +1370,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
a1 = NEW GenericTargetAbility(observer, newName,castRestriction,id, card, tc, a1);
else
a1 = NEW GenericActivatedAbility(observer, newName,castRestriction,id, card, a1, NULL);
MayAbility * mainAbility = NEW MayAbility(observer, id, a1, card,mayMust[i]);
MayAbility * mainAbility = NEW MayAbility(observer, id, a1, card,mayMust[i],castRestriction);
if(mayCost)
mainAbility->optionalCost = mayCost;
return mainAbility;