Refactored ABlink: extracted common code as method "returnCardIntoPlay"
This commit is contained in:
@@ -4433,6 +4433,8 @@ public:
|
|||||||
const char * getMenuText();
|
const char * getMenuText();
|
||||||
ABlink * clone() const;
|
ABlink * clone() const;
|
||||||
~ABlink();
|
~ABlink();
|
||||||
|
private:
|
||||||
|
void returnCardIntoPlay(MTGCardInstance *_target);
|
||||||
};
|
};
|
||||||
|
|
||||||
//blinkinstant
|
//blinkinstant
|
||||||
|
|||||||
@@ -4979,75 +4979,7 @@ void ABlink::Update(float dt)
|
|||||||
if (Blinked == NULL)
|
if (Blinked == NULL)
|
||||||
MTGAbility::Update(dt);
|
MTGAbility::Update(dt);
|
||||||
MTGCardInstance * _target = Blinked;
|
MTGCardInstance * _target = Blinked;
|
||||||
MTGCardInstance * Blinker = NULL;
|
returnCardIntoPlay(_target);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
MTGAbility::Update(dt);
|
MTGAbility::Update(dt);
|
||||||
}
|
}
|
||||||
@@ -5081,13 +5013,23 @@ void ABlink::resolveBlink()
|
|||||||
Blinked = _target;
|
Blinked = _target;
|
||||||
if(!blinkueot && !blinkForSource)
|
if(!blinkueot && !blinkForSource)
|
||||||
{
|
{
|
||||||
|
returnCardIntoPlay(_target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ABlink::returnCardIntoPlay(MTGCardInstance* _target) {
|
||||||
MTGCardInstance * Blinker = NULL;
|
MTGCardInstance * Blinker = NULL;
|
||||||
if (!blinkhand)
|
if (!blinkhand)
|
||||||
Blinker = _target->controller()->game->putInZone(_target, _target->currentZone,
|
Blinker = _target->controller()->game->putInZone(
|
||||||
|
_target,
|
||||||
|
_target->currentZone,
|
||||||
_target->owner->game->battlefield);
|
_target->owner->game->battlefield);
|
||||||
if (blinkhand)
|
if (blinkhand)
|
||||||
{
|
{
|
||||||
_target->controller()->game->putInZone(_target, _target->currentZone,
|
_target->controller()->game->putInZone(
|
||||||
|
_target,
|
||||||
|
_target->currentZone,
|
||||||
_target->owner->game->hand);
|
_target->owner->game->hand);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5096,7 +5038,9 @@ void ABlink::resolveBlink()
|
|||||||
if (spell->source->hasSubtype(Subtypes::TYPE_AURA) && !blinkhand)
|
if (spell->source->hasSubtype(Subtypes::TYPE_AURA) && !blinkhand)
|
||||||
{
|
{
|
||||||
TargetChooserFactory tcf(game);
|
TargetChooserFactory tcf(game);
|
||||||
TargetChooser * tc = tcf.createTargetChooser(spell->source->spellTargetType,spell->source);
|
TargetChooser * tc = tcf.createTargetChooser(
|
||||||
|
spell->source->spellTargetType,
|
||||||
|
spell->source);
|
||||||
if (!tc->validTargetsExist())
|
if (!tc->validTargetsExist())
|
||||||
{
|
{
|
||||||
spell->source->owner->game->putInExile(spell->source);
|
spell->source->owner->game->putInExile(spell->source);
|
||||||
@@ -5125,6 +5069,7 @@ void ABlink::resolveBlink()
|
|||||||
spell->source->power = spell->source->origpower;
|
spell->source->power = spell->source->origpower;
|
||||||
spell->source->toughness = spell->source->origtoughness;
|
spell->source->toughness = spell->source->origtoughness;
|
||||||
spell->source->X = 0;
|
spell->source->X = 0;
|
||||||
|
if (!spell->source->hasSubtype(Subtypes::TYPE_AURA)) {
|
||||||
spell->resolve();
|
spell->resolve();
|
||||||
if (stored)
|
if (stored)
|
||||||
{
|
{
|
||||||
@@ -5140,15 +5085,13 @@ void ABlink::resolveBlink()
|
|||||||
clonedStored->addToGame();
|
clonedStored->addToGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SAFE_DELETE(spell);
|
SAFE_DELETE(spell);
|
||||||
SAFE_DELETE(tc);
|
SAFE_DELETE(tc);
|
||||||
|
SAFE_DELETE(stored);
|
||||||
this->forceDestroy = 1;
|
this->forceDestroy = 1;
|
||||||
if(stored)
|
|
||||||
delete(stored);
|
|
||||||
Blinked = NULL;
|
Blinked = NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int ABlink::resolve()
|
int ABlink::resolve()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user