diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index 66d66acd1..589e8766a 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -69,6 +69,7 @@ public: ManaPool * getManaPool(); void takeMulligan(); void serumMulligan(); + bool DeadLifeState(); ManaCost * doesntEmpty; ManaCost * poolDoesntEmpty; void cleanupPhase(); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 2f77f9d36..b82960119 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -727,34 +727,7 @@ void GameObserver::gameStateBasedEffects() /////////////////////////////////////////////////////////// //life checks/poison checks also checks cant win or lose.// /////////////////////////////////////////////////////////// - if (players[i]->life <= 0 || players[i]->poisonCount >= 10) - { - 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]); - } - } + players[i]->DeadLifeState();//refactored } ////////////////////////////////////////////////////// //-------------card based states effects------------// diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index a6c81c6eb..e8d6c34ed 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -4963,39 +4963,25 @@ int TriggeredAbility::receiveEvent(WEvent * e) } if(dynamic_cast(e)) { - //check life state... basic prevention for infinite loop of bugs\exquisite_blood_i953.txt test.. - //exquisite blood and sanguine bond in play will stop looping as long as the triggered player - //met this condition... taken from gamestatebasecheck... - WEventLife * lifecheck = dynamic_cast(e); - if ((lifecheck->player->life <= 0)||(lifecheck->player->poisonCount >= 10)) - { - int cantlosers = 0; - MTGGameZone * z = lifecheck->player->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) && lifecheck->player->poisonCount < 10)) - { - cantlosers++; - } - } - MTGGameZone * k = lifecheck->player->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) - { - //lifecheck->player->getObserver()->setLoser(lifecheck->player); - return 0; - } - } + //check life state on life triger + WEventLife * lifecheck = dynamic_cast(e); + if (lifecheck->player->DeadLifeState()) + { + return 0; + } + fireAbility(); + return 1; + } + if(dynamic_cast(e)) + { + //check life state on damage trigger + WEventDamage * lifecheck = dynamic_cast(e); + if (lifecheck->damage->target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER) + { + Player * triggerPlayer = (Player *) lifecheck->damage->target; + if(triggerPlayer->DeadLifeState()) + return 0; + } fireAbility(); return 1; } diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index 6cbb98dbd..2003d0b83 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -233,6 +233,40 @@ void Player::serumMulligan() //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 void Player::cleanupPhase() {