Condensed castrestrictions/handsize rule massively. handled by 1 rule now and checked in one pass.

This commit is contained in:
omegablast2002@yahoo.com
2010-09-24 19:26:32 +00:00
parent 27ae3b834b
commit 75c0733a38
4 changed files with 49 additions and 284 deletions

View File

@@ -116,14 +116,6 @@ class MTGCantCasterstart:public MTGAbility{
int testDestroy();
virtual MTGCantCasterstart * clone() const;
};
class MTGCantCastercheck:public MTGAbility{
public:
MTGCantCastercheck(int _id);
int receiveEvent(WEvent * event);
virtual ostream& toString(ostream& out) const;
int testDestroy();
virtual MTGCantCastercheck * clone() const;
};
//affinity rules
class MTGAffinityRule:public MTGAbility{
public:

View File

@@ -32,7 +32,6 @@ void DuelLayers::init(){
action->Add(NEW MTGAffinityRule(-1));
action->Add(NEW MTGUnearthRule(-1));
action->Add(NEW MTGCantCasterstart(-1));
action->Add(NEW MTGCantCastercheck(-1));
action->Add(NEW MTGSneakAttackRule(-1));
action->Add(NEW MTGLifelinkRule(-1));
action->Add(NEW MTGDeathtouchRule(-1));

View File

@@ -120,21 +120,6 @@ void GameObserver::nextGamePhase(){
for (int i = 0; i < 2; ++i)
players[i]->getManaPool()->init();
// //End of turn--unearth clean up---leaving this as comment for code refference. origanal method i had for unearth now handled by sneakattackrule.
//if (currentGamePhase == Constants::MTG_PHASE_ENDOFTURN) {
// GameObserver *game = game->GetInstance();
// Player * p = game->currentPlayer;
// MTGGameZone * z = p->game->inPlay;
// for (int i= 0; i < z->nb_cards; i++){
// MTGCardInstance * card = z->cards[i];
//if (card->has(Constants::UNEARTH)) {
// for(i = z->nb_cards; i > -1; i--){
// card->controller()->game->putInExile(card);
//}
// }
// }
//}
if (currentGamePhase == Constants::MTG_PHASE_AFTER_EOT){
//Auto Hand cleaning, in case the player didn't do it himself
while(currentPlayer->game->hand->nb_cards > 7 && currentPlayer->nomaxhandsize < 1)

View File

@@ -1085,26 +1085,29 @@ HUDDisplay::~HUDDisplay(){
//putting cards with restricting effects inplay
MTGCantCasterstart::MTGCantCasterstart(int _id):MTGAbility(_id,NULL){};
int MTGCantCasterstart::receiveEvent(WEvent * event){
if (event->type == WEvent::CHANGE_ZONE){
WEventZoneChange * e = (WEventZoneChange *) event;
MTGCardInstance * card = e->card->previous;
if(card){
if (card->basicAbilities[Constants::BOTHCANTCAST] || card->basicAbilities[Constants::BOTHNOCREATURE] || card->basicAbilities[Constants::CANTCAST] || card->basicAbilities[Constants::CANTCASTCREATURE] || card->basicAbilities[Constants::CANTCASTTWO] || card->basicAbilities[Constants::ONLYONEBOTH] || card->basicAbilities[Constants::NOMAXHAND] ){
if(card){
if (card->basicAbilities[Constants::BOTHCANTCAST] || card->basicAbilities[Constants::BOTHNOCREATURE] || card->basicAbilities[Constants::CANTCAST] || card->basicAbilities[Constants::CANTCASTCREATURE] || card->basicAbilities[Constants::CANTCASTTWO] || card->basicAbilities[Constants::ONLYONEBOTH] || card->basicAbilities[Constants::NOMAXHAND] ){
int ok = 0;
for (int i = 0; i < 2 ; i++){
Player * p = game->players[i];
if (e->from == p->game->graveyard || e->from == p->game->hand || e->from == p->game->library || e->from == p->game->exile){ ok = 1;
}
for (int i = 0; i < 2 ; i++){
Player * p = game->players[i];
if (e->to == p->game->inPlay){//this will trigger a check if opponent or player cast the card.
if (e->from == p->game->graveyard || e->from == p->game->hand || e->from == p->game->library || e->from == p->game->exile || e->to == p->game->inPlay || e->to == p->game->graveyard || e->to == p->game->hand || e->to == p->game->library || e->to == p->game->exile || e->from == p->game->inPlay ){ ok = 1;
//check happens----------
//reset restrictions if they exist and runs a check if these cards still exist.
p->nomaxhandsize = 0;
p->opponent()->nomaxhandsize = 0;
p->onlyonecast = 0;
p->opponent()->onlyonecast = 0;
p->castrestrictedspell = 0;//0 means no restrictions apply.
p->castrestrictedcreature = 0;
p->opponent()->castrestrictedspell = 0;
p->opponent()->castrestrictedcreature = 0;
/*--------------------------------------------------------------*/
for (int i = 0; i < 2 ; i++){
Player * p = game->players[i];
MTGGameZone * z = card->controller()->game->inPlay;
MTGGameZone * y = card->controller()->opponent()->game->inPlay;
int nbcards = z->nb_cards;
@@ -1113,122 +1116,66 @@ HUDDisplay::~HUDDisplay(){
//check my battlefield and opponents
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::NOMAXHAND)){
if (c->has(Constants::NOMAXHAND)){
card->controller()->nomaxhandsize = 1;
}
} //any on other side?
if (c->has(Constants::BOTHCANTCAST)){
card->controller()->castrestrictedspell = 1;
card->controller()->opponent()->castrestrictedspell = 1;
}
if (c->has(Constants::CANTCAST)){
card->controller()->castrestrictedspell = 1;
}
if (c->has(Constants::BOTHNOCREATURE)){
card->controller()->castrestrictedcreature += 1;
card->controller()->opponent()->castrestrictedcreature += 1;
}
if (c->has(Constants::CANTCASTCREATURE)){
card->controller()->castrestrictedcreature = 1;
}
if (c->has(Constants::ONLYONEBOTH)){
card->controller()->onlyonecast = 1;
card->controller()->opponent()->onlyonecast = 1;
}
if (c->has(Constants::CANTCASTTWO)){
card->controller()->onlyonecast = 1;
}
}
//any on other side?
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::NOMAXHAND)){
card->controller()->opponent()->nomaxhandsize = 1;
}
}
//--------------both cant cast-----------------
//check my battlefield and opponents
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::BOTHCANTCAST)){
if (c->has(Constants::BOTHCANTCAST)){
card->controller()->castrestrictedspell = 1;
card->controller()->opponent()->castrestrictedspell = 1;
}
} //any on other side?
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::BOTHCANTCAST)){
card->controller()->castrestrictedspell = 1;
card->controller()->opponent()->castrestrictedspell = 1;
}
}
//maybe one of us is still restricted, lets check...
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTCAST)){
card->controller()->castrestrictedspell = 1;
}
} //any on other side?
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::CANTCAST)){
card->controller()->opponent()->castrestrictedspell = 1;
}
}
//---how about if we cant cast creatures---
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::BOTHNOCREATURE)){
card->controller()->castrestrictedcreature += 1;
card->controller()->opponent()->castrestrictedcreature += 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::BOTHNOCREATURE)){
if (c->has(Constants::BOTHNOCREATURE)){
card->controller()->castrestrictedcreature = 1;
card->controller()->opponent()->castrestrictedcreature = 1;
}
}
//---
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTCASTCREATURE)){
card->controller()->castrestrictedcreature = 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::CANTCASTCREATURE)){
if (c->has(Constants::CANTCASTCREATURE)){
card->controller()->opponent()->castrestrictedcreature = 1;
}
}
//---what if i can only cast 1?
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::ONLYONEBOTH)){
if (c->has(Constants::ONLYONEBOTH)){
card->controller()->onlyonecast = 1;
card->controller()->opponent()->onlyonecast = 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::ONLYONEBOTH)){
card->controller()->onlyonecast = 1;
if (c->has(Constants::CANTCASTTWO)){
card->controller()->opponent()->onlyonecast = 1;
}
}
//---
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTCASTTWO)){
card->controller()->onlyonecast = 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::CANTCASTTWO)){
card->controller()->opponent()->onlyonecast = 1;
if (c->has(Constants::CANTCAST)){
card->controller()->opponent()->castrestrictedspell = 1;
}
}
//-----if a card with both*restrict* was found then the players are still restricted, if one player is still restricted he stays restricted.
return 1;
}
return 1;
}
return 1;
}
}
return 1;
}
return 1;
}
return 1;
}
}
return 1;
}
ostream& MTGCantCasterstart::toString(ostream& out) const
@@ -1242,164 +1189,6 @@ HUDDisplay::~HUDDisplay(){
a->isClone = 1;
return a;
}
//check if cast resristrictions are lifted when a card leaves play
MTGCantCastercheck::MTGCantCastercheck(int _id):MTGAbility(_id,NULL){};
int MTGCantCastercheck::receiveEvent(WEvent * event){
if (event->type == WEvent::CHANGE_ZONE){
WEventZoneChange * e = (WEventZoneChange *) event;
MTGCardInstance * card = e->card->previous;
if (card && (card->basicAbilities[Constants::BOTHCANTCAST] || card->basicAbilities[Constants::BOTHNOCREATURE] || card->basicAbilities[Constants::CANTCAST] || card->basicAbilities[Constants::CANTCASTCREATURE] || card->basicAbilities[Constants::CANTCASTTWO] || card->basicAbilities[Constants::ONLYONEBOTH]|| card->basicAbilities[Constants::NOMAXHAND])){
int ok = 0;
for (int i = 0; i < 2 ; i++){
Player * p = game->players[i];
if (e->from == p->game->inPlay) ok = 1;
}
if (!ok) return 0;
for (int i = 0; i < 2 ; i++){
Player * p = game->players[i];
if (e->to == p->game->graveyard || e->to == p->game->hand || e->to == p->game->library || e->to == p->game->exile){//if it goes ANYWHERE but inplay.
//check happens----------
//reset restrictions
p->nomaxhandsize = 0;
p->opponent()->nomaxhandsize = 0;
p->onlyonecast = 0;
p->opponent()->onlyonecast = 0;
p->castrestrictedspell = 0;//0 means no restrictions apply.
p->castrestrictedcreature = 0;
p->opponent()->castrestrictedspell = 0;
p->opponent()->castrestrictedcreature = 0;
/*--------------------------------------------------------------*/
MTGGameZone * z = card->controller()->game->inPlay;
MTGGameZone * y = card->controller()->opponent()->game->inPlay;
int nbcards = z->nb_cards;
int onbcards = y->nb_cards;
//no max hand size
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::NOMAXHAND)){
p->nomaxhandsize = 1;
}
} //any on other side?
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::NOMAXHAND)){
p->opponent()->nomaxhandsize = 1;
}
}
//check my battlefield and opponents
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::BOTHCANTCAST)){
p->castrestrictedspell = 1;
p->opponent()->castrestrictedspell = 1;
}
} //any on other side?
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::BOTHCANTCAST)){
p->castrestrictedspell = 1;
p->opponent()->castrestrictedspell = 1;
}
}
//maybe one of us is still restricted, lets check...
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTCAST)){
p->castrestrictedspell = 1;
}
} //any on other side?
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::CANTCAST)){
p->opponent()->castrestrictedspell = 1;
}
}
//---how about if we cant cast creatures---
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::BOTHNOCREATURE)){
p->castrestrictedcreature = 1;
p->opponent()->castrestrictedcreature = 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::BOTHNOCREATURE)){
p->castrestrictedcreature = 1;
p->opponent()->castrestrictedcreature = 1;
}
}
//---
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTCASTCREATURE)){
p->castrestrictedcreature = 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::CANTCASTCREATURE)){
p->opponent()->castrestrictedcreature = 1;
}
}
//---what if i can only cast 1?
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::ONLYONEBOTH)){
p->onlyonecast = 1;
p->opponent()->onlyonecast = 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::ONLYONEBOTH)){
p->onlyonecast = 1;
p->opponent()->onlyonecast = 1;
}
}
//---
for (int j = 0; j < nbcards; ++j){
MTGCardInstance * c = z->cards[j];
if (c->has(Constants::CANTCASTTWO)){
p->onlyonecast = 1;
}
}
//maybe opponent has one....
for (int j = 0; j < onbcards; ++j){
MTGCardInstance * c = y->cards[j];
if (c->has(Constants::CANTCASTTWO)){
p->opponent()->onlyonecast = 1;
}
}
//-----if a card with both*restrict* was found then the players are still restricted, if one player is still restricted he stays restricted.
return 1;
}
}
}
}
return 0;
}
ostream& MTGCantCastercheck::toString(ostream& out) const
{
out << "MTGCantCastercheck ::: (";
return MTGAbility::toString(out) << ")";
}
int MTGCantCastercheck::testDestroy(){return 0;}
MTGCantCastercheck * MTGCantCastercheck::clone() const{
MTGCantCastercheck * a = NEW MTGCantCastercheck(*this);
a->isClone = 1;
return a;
}
//the end of this very complex code line.