refactored lifestate check

This commit is contained in:
Anthony Calosa
2015-09-03 20:11:47 +08:00
parent 886eaa4002
commit 42d0480f77
4 changed files with 55 additions and 61 deletions

View File

@@ -69,6 +69,7 @@ public:
ManaPool * getManaPool(); ManaPool * getManaPool();
void takeMulligan(); void takeMulligan();
void serumMulligan(); void serumMulligan();
bool DeadLifeState();
ManaCost * doesntEmpty; ManaCost * doesntEmpty;
ManaCost * poolDoesntEmpty; ManaCost * poolDoesntEmpty;
void cleanupPhase(); void cleanupPhase();

View File

@@ -727,34 +727,7 @@ void GameObserver::gameStateBasedEffects()
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
//life checks/poison checks also checks cant win or lose.// //life checks/poison checks also checks cant win or lose.//
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
if (players[i]->life <= 0 || players[i]->poisonCount >= 10) players[i]->DeadLifeState();//refactored
{
int cantlosers = 0;
MTGGameZone * z = players[i]->game->inPlay;
int nbcards = z->nb_cards;
for (int j = 0; j < nbcards; ++j)
{
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTLOSE) || (c->has(Constants::CANTLIFELOSE) && players[i]->poisonCount < 10))
{
cantlosers++;
}
}
MTGGameZone * k = players[i]->opponent()->game->inPlay;
int onbcards = k->nb_cards;
for (int m = 0; m < onbcards; ++m)
{
MTGCardInstance * e = k->cards[m];
if (e->has(Constants::CANTWIN))
{
cantlosers++;
}
}
if (cantlosers < 1)
{
setLoser(players[i]);
}
}
} }
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//-------------card based states effects------------// //-------------card based states effects------------//

View File

@@ -4963,39 +4963,25 @@ int TriggeredAbility::receiveEvent(WEvent * e)
} }
if(dynamic_cast<WEventLife*>(e)) if(dynamic_cast<WEventLife*>(e))
{ {
//check life state... basic prevention for infinite loop of bugs\exquisite_blood_i953.txt test.. //check life state on life triger
//exquisite blood and sanguine bond in play will stop looping as long as the triggered player WEventLife * lifecheck = dynamic_cast<WEventLife*>(e);
//met this condition... taken from gamestatebasecheck... if (lifecheck->player->DeadLifeState())
WEventLife * lifecheck = dynamic_cast<WEventLife*>(e); {
if ((lifecheck->player->life <= 0)||(lifecheck->player->poisonCount >= 10)) return 0;
{ }
int cantlosers = 0; fireAbility();
MTGGameZone * z = lifecheck->player->game->inPlay; return 1;
int nbcards = z->nb_cards; }
for (int j = 0; j < nbcards; ++j) if(dynamic_cast<WEventDamage*>(e))
{ {
MTGCardInstance * c = z->cards[j]; //check life state on damage trigger
if (c->has(Constants::CANTLOSE) || (c->has(Constants::CANTLIFELOSE) && lifecheck->player->poisonCount < 10)) WEventDamage * lifecheck = dynamic_cast<WEventDamage*>(e);
{ if (lifecheck->damage->target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER)
cantlosers++; {
} Player * triggerPlayer = (Player *) lifecheck->damage->target;
} if(triggerPlayer->DeadLifeState())
MTGGameZone * k = lifecheck->player->opponent()->game->inPlay; return 0;
int onbcards = k->nb_cards; }
for (int m = 0; m < onbcards; ++m)
{
MTGCardInstance * e = k->cards[m];
if (e->has(Constants::CANTWIN))
{
cantlosers++;
}
}
if (cantlosers < 1)
{
//lifecheck->player->getObserver()->setLoser(lifecheck->player);
return 0;
}
}
fireAbility(); fireAbility();
return 1; return 1;
} }

View File

@@ -233,6 +233,40 @@ void Player::serumMulligan()
//Draw hand no penalty //Draw hand no penalty
} }
bool Player::DeadLifeState()
{
if ((life <= 0)||(poisonCount >= 10))
{
int cantlosers = 0;
MTGGameZone * z = game->inPlay;
int nbcards = z->nb_cards;
for (int j = 0; j < nbcards; ++j)
{
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTLOSE) || (c->has(Constants::CANTLIFELOSE) && poisonCount < 10))
{
cantlosers++;
}
}
MTGGameZone * k = opponent()->game->inPlay;
int onbcards = k->nb_cards;
for (int m = 0; m < onbcards; ++m)
{
MTGCardInstance * e = k->cards[m];
if (e->has(Constants::CANTWIN))
{
cantlosers++;
}
}
if (cantlosers < 1)
{
getObserver()->setLoser(this);
return true;
}
}
return false;
}
//Cleanup phase at the end of a turn //Cleanup phase at the end of a turn
void Player::cleanupPhase() void Player::cleanupPhase()
{ {