Refactored FizzleToZone

Get rid of common code
Better naming of zone (where we put spell after countering)
More generic syntax: fizzleto(X) where X in [hand, exile, librarytop]
which will give more flexibility later
This commit is contained in:
pankdm
2013-10-08 23:18:42 +00:00
parent 4341e23210
commit 0c6d77daa0
6 changed files with 63 additions and 115 deletions
+15 -47
View File
@@ -1314,52 +1314,16 @@ ActivatedAbility(observer, _id, card, _cost, 0)
{
aType = MTGAbility::STANDARD_FIZZLER;
target = _target;
// by default we put the spell to graveyard after fizzling
fizzleMode = ActionStack::PUT_IN_GRAVEARD;
}
int AAFizzler::resolve()
{
ActionStack * stack = game->mLayers->stackLayer();
//the next section helps Ai correctly recieve its targets for this effect
if(!target && source->target)
{
//ai is casting a spell from its hand to fizzle.
target = stack->getActionElementFromCard(source->target);
}
else if(MTGCardInstance * cTarget = dynamic_cast<MTGCardInstance *>(target))
{
//ai targeted using an ability on a card to fizzle.
target = stack->getActionElementFromCard(cTarget);
}
Spell * sTarget = (Spell *) target;
MTGCardInstance* sCard = NULL;
if(sTarget)
sCard = sTarget->source;
if(!sCard || !sTarget || sCard->has(Constants::NOFIZZLE))
return 0;
stack->Fizzle(sTarget);
return 1;
}
const char * AAFizzler::getMenuText()
{
return "Fizzle";
}
AAFizzler* AAFizzler::clone() const
{
return NEW AAFizzler(*this);
}
AAOFizzler::AAOFizzler( GameObserver* observer, int _id, MTGCardInstance * card, Spell * _target, int tgtZone, ManaCost * _cost ) :
AAFizzler( observer, _id, card, _target, _cost )
{
targetZone = tgtZone;
}
int AAOFizzler::resolve()
{
ActionStack * stack = game->mLayers->stackLayer();
//the next section helps Ai correctly recieve its targets for this effect
if(!target && source->target)
if (!target && source->target)
{
//ai is casting a spell from its hand to fizzle.
target = stack->getActionElementFromCard(source->target);
@@ -1371,19 +1335,23 @@ int AAOFizzler::resolve()
}
Spell * sTarget = (Spell *) target;
MTGCardInstance* sCard = NULL;
if(sTarget)
sCard = sTarget->source;
if(!sCard || !sTarget || sCard->has(Constants::NOFIZZLE))
if (sTarget)
sCard = sTarget->source;
if (!sCard || !sTarget || sCard->has(Constants::NOFIZZLE))
return 0;
stack->Fizzle(sTarget, targetZone);
stack->Fizzle(sTarget, fizzleMode);
return 1;
}
AAOFizzler* AAOFizzler::clone() const
const char * AAFizzler::getMenuText()
{
return NEW AAOFizzler(*this);
return "Fizzle";
}
AAFizzler* AAFizzler::clone() const
{
return NEW AAFizzler(*this);
}
// BanishCard implementations
// Bury