Refactored ABlink: extracted common code as method "returnCardIntoPlay"

This commit is contained in:
pankdm
2013-09-27 19:25:28 +00:00
parent d4268f18af
commit 7894ca3ace
2 changed files with 80 additions and 135 deletions

View File

@@ -4433,6 +4433,8 @@ public:
const char * getMenuText();
ABlink * clone() const;
~ABlink();
private:
void returnCardIntoPlay(MTGCardInstance *_target);
};
//blinkinstant

View File

@@ -4979,75 +4979,7 @@ void ABlink::Update(float dt)
if (Blinked == NULL)
MTGAbility::Update(dt);
MTGCardInstance * _target = Blinked;
MTGCardInstance * Blinker = NULL;
if(!blinkhand)
Blinker = _target->controller()->game->putInZone(_target, _target->currentZone,
_target->owner->game->battlefield);
if(blinkhand)
{
_target->controller()->game->putInZone(_target, _target->currentZone,
_target->owner->game->hand);
return;
}
Spell * spell = NEW Spell(game, Blinker);
spell->source->counters->init();
if(spell->source->hasSubtype(Subtypes::TYPE_AURA) && !blinkhand)
{
TargetChooserFactory tcf(game);
TargetChooser * tc = tcf.createTargetChooser(spell->source->spellTargetType,spell->source);
if(!tc->validTargetsExist())
{
spell->source->owner->game->putInExile(spell->source);
SAFE_DELETE(spell);
SAFE_DELETE(tc);
this->forceDestroy = 1;
return;
}
MTGGameZone * inplay = spell->source->owner->game->inPlay;
spell->source->target = NULL;
for(int i = game->getRandomGenerator()->random()%inplay->nb_cards;;i = game->getRandomGenerator()->random()%inplay->nb_cards)
{
if(tc->canTarget(inplay->cards[i]) && spell->source->target == NULL)
{
spell->source->target = inplay->cards[i];
spell->getNextCardTarget();
spell->resolve();
SAFE_DELETE(spell);
SAFE_DELETE(tc);
this->forceDestroy = 1;
return;
}
if(!tc->validTargetsExist())
return;
}
}
spell->source->power = spell->source->origpower;
spell->source->toughness = spell->source->origtoughness;
spell->source->X = 0;
if(!spell->source->hasSubtype(Subtypes::TYPE_AURA))
{
spell->resolve();
if(stored)
{
MTGAbility * clonedStored = stored->clone();
clonedStored->target = spell->source;
if (clonedStored->oneShot)
{
clonedStored->resolve();
delete (clonedStored);
}
else
{
clonedStored->addToGame();
}
}
}
delete spell;
this->forceDestroy = 1;
Blinker = NULL;
return;
returnCardIntoPlay(_target);
}
MTGAbility::Update(dt);
}
@@ -5081,13 +5013,23 @@ void ABlink::resolveBlink()
Blinked = _target;
if(!blinkueot && !blinkForSource)
{
returnCardIntoPlay(_target);
}
}
}
void ABlink::returnCardIntoPlay(MTGCardInstance* _target) {
MTGCardInstance * Blinker = NULL;
if (!blinkhand)
Blinker = _target->controller()->game->putInZone(_target, _target->currentZone,
Blinker = _target->controller()->game->putInZone(
_target,
_target->currentZone,
_target->owner->game->battlefield);
if (blinkhand)
{
_target->controller()->game->putInZone(_target, _target->currentZone,
_target->controller()->game->putInZone(
_target,
_target->currentZone,
_target->owner->game->hand);
return;
}
@@ -5096,7 +5038,9 @@ void ABlink::resolveBlink()
if (spell->source->hasSubtype(Subtypes::TYPE_AURA) && !blinkhand)
{
TargetChooserFactory tcf(game);
TargetChooser * tc = tcf.createTargetChooser(spell->source->spellTargetType,spell->source);
TargetChooser * tc = tcf.createTargetChooser(
spell->source->spellTargetType,
spell->source);
if (!tc->validTargetsExist())
{
spell->source->owner->game->putInExile(spell->source);
@@ -5125,6 +5069,7 @@ void ABlink::resolveBlink()
spell->source->power = spell->source->origpower;
spell->source->toughness = spell->source->origtoughness;
spell->source->X = 0;
if (!spell->source->hasSubtype(Subtypes::TYPE_AURA)) {
spell->resolve();
if (stored)
{
@@ -5140,15 +5085,13 @@ void ABlink::resolveBlink()
clonedStored->addToGame();
}
}
}
SAFE_DELETE(spell);
SAFE_DELETE(tc);
SAFE_DELETE(stored);
this->forceDestroy = 1;
if(stored)
delete(stored);
Blinked = NULL;
}
}
}
int ABlink::resolve()
{