Phase out Event & Trigger

This commit is contained in:
Anthony Calosa
2017-02-17 14:25:33 +08:00
parent 95b81b6425
commit ba40253a46
6 changed files with 50 additions and 1 deletions

View File

@@ -1332,6 +1332,28 @@ public:
}
};
class TrCardPhasesOut: public Trigger
{
public:
TrCardPhasesOut(GameObserver* observer, int id, MTGCardInstance * source, TargetChooser * tc, bool once = false) :
Trigger(observer, id, source, once, tc)
{
}
int triggerOnEventImpl(WEvent * event)
{
WEventCardPhasesOut * e = dynamic_cast<WEventCardPhasesOut *> (event);
if (!e) return 0;
if (!tc->canTarget(e->card)) return 0;
return 1;
}
TrCardPhasesOut * clone() const
{
return NEW TrCardPhasesOut(*this);
}
};
class TrCardPhasesIn: public Trigger
{
public:

View File

@@ -305,7 +305,13 @@ struct WEventCardControllerChange : public WEventCardUpdate {
virtual Targetable * getTarget(int target);
};
//event when card with phases in
//event when card phases out
struct WEventCardPhasesOut : public WEventCardUpdate {
WEventCardPhasesOut(MTGCardInstance * card);
virtual Targetable * getTarget(int target);
};
//event when card phases in
struct WEventCardPhasesIn : public WEventCardUpdate {
WEventCardPhasesIn(MTGCardInstance * card);
virtual Targetable * getTarget(int target);

View File

@@ -1708,6 +1708,9 @@ int AAPhaseOut::resolve()
if(_target->view)
_target->view->alpha = 50;
_target->initAttackersDefensers();
//add event phases out here
WEvent * e = NEW WEventCardPhasesOut(_target);
game->receiveEvent(e);
return 1;
}
return 0;

View File

@@ -852,6 +852,9 @@ void GameObserver::gameStateBasedEffects()
if(card->view)
card->view->alpha = 50;
card->initAttackersDefensers();
//add event phases out here
WEvent * evphaseout = NEW WEventCardPhasesOut(card);
receiveEvent(evphaseout);
}
else if((card->has(Constants::PHASING) || card->isPhased)&& mCurrentGamePhase == MTG_PHASE_UNTAP && currentPlayer == card->controller() && card->phasedTurn != turn)
{

View File

@@ -1044,6 +1044,10 @@ TriggeredAbility * AbilityFactory::parseTrigger(string s, string, int id, Spell
if (TargetChooser *tc = parseSimpleTC(s,"phasedin", card))
return NEW TrCardPhasesIn(observer, id, card, tc,once);
//Card Phases Out
if (TargetChooser *tc = parseSimpleTC(s,"phasedout", card))
return NEW TrCardPhasesOut(observer, id, card, tc,once);
//CombatTrigger
//Card card attacked and is blocked
found = s.find("combat(");

View File

@@ -236,6 +236,11 @@ WEventCardControllerChange::WEventCardControllerChange(MTGCardInstance * card) :
{
}
WEventCardPhasesOut::WEventCardPhasesOut(MTGCardInstance * card) :
WEventCardUpdate(card)
{
}
WEventCardPhasesIn::WEventCardPhasesIn(MTGCardInstance * card) :
WEventCardUpdate(card)
{
@@ -427,6 +432,12 @@ Targetable * WEventCardControllerChange::getTarget(int target)
return NULL;
}
Targetable * WEventCardPhasesOut::getTarget(int target)
{
if (target) return card;
return NULL;
}
Targetable * WEventCardPhasesIn::getTarget(int target)
{
if (target) return card;