Fix Segmentation Fault & Formatting
This commit is contained in:
@@ -58,8 +58,8 @@ int MTGEventBonus::receiveEvent(WEvent * event)
|
||||
//bonus for chain chain casting without tapping for mana or being interupted;
|
||||
//note gaining mana from other sources is still possible.
|
||||
//only spells going to the stack are counted.
|
||||
if(game->turn <2)//this shouldnt trigger on first turn, chances are they are cheating.
|
||||
return 0;
|
||||
if(game->turn <2)//this shouldnt trigger on first turn, chances are they are cheating.
|
||||
return 0;
|
||||
if (dynamic_cast<WEventCardTappedForMana*>(event))
|
||||
{
|
||||
|
||||
@@ -285,9 +285,9 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost *)
|
||||
int cardsinhand = game->players[0]->game->hand->nb_cards;
|
||||
Player * player = game->currentlyActing();
|
||||
if (!player->game->hand->hasCard(card) && !player->game->graveyard->hasCard(card) && !player->game->exile->hasCard(card))
|
||||
return 0;
|
||||
if ((player->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (player->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
return 0;
|
||||
if ((player->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (player->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
if ((game->turn < 1) && (cardsinhand != 0) && (card->basicAbilities[(int)Constants::LEYLINE])
|
||||
&& game->getCurrentGamePhase() == MTG_PHASE_FIRSTMAIN
|
||||
&& game->players[0]->game->graveyard->nb_cards == 0
|
||||
@@ -478,13 +478,13 @@ int MTGKickerRule::isReactingToClick(MTGCardInstance * card, ManaCost *)
|
||||
return 0;
|
||||
Player * player = game->currentlyActing();
|
||||
if (!player->game->hand->hasCard(card) && !player->game->graveyard->hasCard(card) && !player->game->exile->hasCard(card))
|
||||
return 0;
|
||||
if ((player->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (player->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
return 0;
|
||||
if ((player->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (player->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
ManaCost * kicker = card->getManaCost()->getKicker();
|
||||
if(!kicker)
|
||||
{
|
||||
SAFE_DELETE(kicker);
|
||||
SAFE_DELETE(kicker);
|
||||
return 0;
|
||||
}
|
||||
ManaCost * playerMana = player->getManaPool();
|
||||
@@ -627,13 +627,13 @@ PermanentAbility(observer, _id)
|
||||
|
||||
int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
||||
{
|
||||
ManaCost * alternateCost = card->getManaCost()->getAlternative();
|
||||
if (!game->currentlyActing()->game->hand->hasCard(card) && !game->currentlyActing()->game->graveyard->hasCard(card) && !game->currentlyActing()->game->exile->hasCard(card))
|
||||
return 0;
|
||||
if ((game->currentlyActing()->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (game->currentlyActing()->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
if (card->alias == 110000)
|
||||
return 0;//overload has its own rule
|
||||
ManaCost * alternateCost = card->getManaCost()->getAlternative();
|
||||
if (!game->currentlyActing()->game->hand->hasCard(card) && !game->currentlyActing()->game->graveyard->hasCard(card) && !game->currentlyActing()->game->exile->hasCard(card))
|
||||
return 0;
|
||||
if ((game->currentlyActing()->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (game->currentlyActing()->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
return isReactingToClick( card, mana, alternateCost );
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
|
||||
return 0;
|
||||
|
||||
|
||||
if(card->has(Constants::CANPLAYFROMGRAVEYARD))
|
||||
if(card->has(Constants::CANPLAYFROMGRAVEYARD))
|
||||
alternativeName = "Alternate Cast From Graveyard";
|
||||
else if(card->has(Constants::CANPLAYFROMEXILE))
|
||||
alternativeName = "Alternate Cast From Exile";
|
||||
@@ -686,11 +686,11 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
|
||||
|
||||
int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card)
|
||||
{
|
||||
if ( !isReactingToClick(card))
|
||||
return 0;
|
||||
if ( !isReactingToClick(card))
|
||||
return 0;
|
||||
|
||||
ManaCost *alternateCost = card->getManaCost()->getAlternative();
|
||||
card->paymenttype = MTGAbility::ALTERNATIVE_COST;
|
||||
ManaCost *alternateCost = card->getManaCost()->getAlternative();
|
||||
card->paymenttype = MTGAbility::ALTERNATIVE_COST;
|
||||
|
||||
return reactToClick(card, alternateCost, ManaCost::MANA_PAID_WITH_ALTERNATIVE);
|
||||
}
|
||||
@@ -703,15 +703,15 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter
|
||||
|
||||
if(overload)
|
||||
card->spellTargetType = "";
|
||||
else if(card->model->data->spellTargetType.size())
|
||||
else if(card->model->data->spellTargetType.size())
|
||||
card->spellTargetType = card->model->data->spellTargetType;
|
||||
|
||||
assert(alternateCost);
|
||||
if (alternateCost->isExtraPaymentSet() )
|
||||
{
|
||||
if (!game->targetListIsSet(card))
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
alternateCost->setExtraCostsAction(this, card);
|
||||
@@ -790,9 +790,9 @@ int MTGBuyBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
||||
{
|
||||
Player * player = game->currentlyActing();
|
||||
if (!player->game->hand->hasCard(card) && !player->game->graveyard->hasCard(card) && !player->game->exile->hasCard(card))
|
||||
return 0;
|
||||
if ((player->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (player->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
return 0;
|
||||
if ((player->game->graveyard->hasCard(card) && !card->has(Constants::CANPLAYFROMGRAVEYARD)) || (player->game->exile->hasCard(card) && !card->has(Constants::CANPLAYFROMEXILE)))
|
||||
return 0;
|
||||
if(!allowedToCast(card,player))
|
||||
return 0;
|
||||
return MTGAlternativeCostRule::isReactingToClick( card, mana, card->getManaCost()->getBuyback() );
|
||||
@@ -1180,7 +1180,7 @@ int MTGPayZeroRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
||||
return 0;
|
||||
if ((!card->has(Constants::CANPLAYFROMGRAVEYARD) && player->game->graveyard->hasCard(card))||(!card->has(Constants::CANPLAYFROMEXILE) && player->game->exile->hasCard(card)))
|
||||
return 0;
|
||||
if(card->has(Constants::CANPLAYFROMGRAVEYARD))
|
||||
if(card->has(Constants::CANPLAYFROMGRAVEYARD))
|
||||
CustomName = "Zero Cast From Graveyard";
|
||||
else if(card->has(Constants::CANPLAYFROMEXILE))
|
||||
CustomName = "Zero Cast From Exile";
|
||||
@@ -1225,6 +1225,8 @@ MTGAlternativeCostRule(observer, _id)
|
||||
|
||||
int MTGOverloadRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
||||
{
|
||||
if (card->alias != 110000)
|
||||
return 0;
|
||||
Player * player = game->currentlyActing();
|
||||
ManaCost * cost = NEW ManaCost(card->model->data->getManaCost()->getAlternative());
|
||||
if(card->getIncreasedManaCost()->getConvertedCost())
|
||||
@@ -1234,8 +1236,6 @@ int MTGOverloadRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
||||
|
||||
if (card->isLand())
|
||||
return 0;
|
||||
if (card->alias != 110000)
|
||||
return 0;
|
||||
if (!player->game->graveyard->hasCard(card) && !player->game->exile->hasCard(card) && !player->game->hand->hasCard(card))
|
||||
return 0;
|
||||
if ((!card->has(Constants::CANPLAYFROMGRAVEYARD) && player->game->graveyard->hasCard(card))||(!card->has(Constants::CANPLAYFROMEXILE) && player->game->exile->hasCard(card)))
|
||||
@@ -1912,7 +1912,7 @@ MTGStoneHewerRule::MTGStoneHewerRule(GameObserver* observer, int _id, MTGAllCard
|
||||
for (size_t i = 0; i < collection->ids.size(); i++)
|
||||
{
|
||||
MTGCard * card = collection->collection[collection->ids[i]];
|
||||
if (card->data->hasSubtype("equipment") && (card->getRarity() != Constants::RARITY_T) && //remove tokens
|
||||
if (card->data->hasSubtype("equipment") && (card->getRarity() != Constants::RARITY_T) && //remove tokens
|
||||
card->setId != MTGSets::INTERNAL_SET //remove cards that are defined in primitives. Those are workarounds (usually tokens) and should only be used internally
|
||||
)
|
||||
{
|
||||
@@ -1928,32 +1928,32 @@ MTGStoneHewerRule::MTGStoneHewerRule(GameObserver* observer, int _id, MTGAllCard
|
||||
|
||||
int MTGStoneHewerRule::receiveEvent(WEvent * event)
|
||||
{
|
||||
WEventZoneChange * e = (WEventZoneChange *) event;
|
||||
if (e->to == game->currentlyActing()->game->inPlay && e->card->isCreature())
|
||||
{
|
||||
int eId = genRandomEquipId(e->card->getManaCost()->getConvertedCost());
|
||||
MTGCardInstance * card = genEquip(eId);
|
||||
if(card)
|
||||
{
|
||||
game->currentlyActing()->game->temp->addCard(card);
|
||||
WEventZoneChange * e = (WEventZoneChange *) event;
|
||||
if (e->to == game->currentlyActing()->game->inPlay && e->card->isCreature())
|
||||
{
|
||||
int eId = genRandomEquipId(e->card->getManaCost()->getConvertedCost());
|
||||
MTGCardInstance * card = genEquip(eId);
|
||||
if(card)
|
||||
{
|
||||
game->currentlyActing()->game->temp->addCard(card);
|
||||
Spell * spell = NEW Spell(game, card);
|
||||
spell->resolve();
|
||||
spell->source->isToken = 1;
|
||||
spell->resolve();
|
||||
spell->source->isToken = 1;
|
||||
for (size_t i = 1; i < game->mLayers->actionLayer()->mObjects.size(); i++)
|
||||
{
|
||||
{
|
||||
MTGAbility * a = ((MTGAbility *) game->mLayers->actionLayer()->mObjects[i]);
|
||||
AEquip * eq = dynamic_cast<AEquip*> (a);
|
||||
if (eq && eq->source == spell->source)
|
||||
{
|
||||
((AEquip*)a)->unequip();
|
||||
((AEquip*)a)->equip(e->card);
|
||||
}
|
||||
}
|
||||
SAFE_DELETE(spell);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
AEquip * eq = dynamic_cast<AEquip*> (a);
|
||||
if (eq && eq->source == spell->source)
|
||||
{
|
||||
((AEquip*)a)->unequip();
|
||||
((AEquip*)a)->equip(e->card);
|
||||
}
|
||||
}
|
||||
SAFE_DELETE(spell);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MTGCardInstance * MTGStoneHewerRule::genEquip(int id)
|
||||
@@ -1967,8 +1967,8 @@ MTGCardInstance * MTGStoneHewerRule::genEquip(int id)
|
||||
|
||||
int MTGStoneHewerRule::genRandomEquipId(int convertedCost)
|
||||
{
|
||||
if (convertedCost >= 20)
|
||||
convertedCost = 19;
|
||||
if (convertedCost >= 20)
|
||||
convertedCost = 19;
|
||||
int total_cards = 0;
|
||||
int i = (game->getRandomGenerator()->random() % int(convertedCost+1));//+1 becuase we want to generate a random "<=" the coverted.
|
||||
while (!total_cards && i >= 0)
|
||||
@@ -2004,29 +2004,29 @@ PermanentAbility(observer, _id)
|
||||
|
||||
int MTGHermitRule::receiveEvent(WEvent * event)
|
||||
{
|
||||
WEventPhaseChange * e = dynamic_cast<WEventPhaseChange*>(event);
|
||||
WEventPhaseChange * e = dynamic_cast<WEventPhaseChange*>(event);
|
||||
if (e && e->from->id == MTG_PHASE_UNTAP)
|
||||
{
|
||||
MTGCardInstance * lcard = NULL;
|
||||
vector<MTGCardInstance*>lands = vector<MTGCardInstance*>();
|
||||
for(int i = 0; i < game->currentPlayer->game->library->nb_cards-1; i++)
|
||||
{
|
||||
MTGCardInstance * temp = game->currentPlayer->game->library->cards[i];
|
||||
if(temp && temp->isLand())
|
||||
lands.push_back(temp);
|
||||
}
|
||||
if(lands.size())
|
||||
{
|
||||
MTGCardInstance * lcard = NULL;
|
||||
vector<MTGCardInstance*>lands = vector<MTGCardInstance*>();
|
||||
for(int i = 0; i < game->currentPlayer->game->library->nb_cards-1; i++)
|
||||
{
|
||||
MTGCardInstance * temp = game->currentPlayer->game->library->cards[i];
|
||||
if(temp && temp->isLand())
|
||||
lands.push_back(temp);
|
||||
}
|
||||
if(lands.size())
|
||||
lcard = lands[game->getRandomGenerator()->random() % lands.size()];
|
||||
if(lcard)
|
||||
{
|
||||
MTGCardInstance * copy = game->currentPlayer->game->putInZone(lcard,game->currentPlayer->game->library, game->currentPlayer->game->temp);
|
||||
if(lcard)
|
||||
{
|
||||
MTGCardInstance * copy = game->currentPlayer->game->putInZone(lcard,game->currentPlayer->game->library, game->currentPlayer->game->temp);
|
||||
Spell * spell = NEW Spell(game, copy);
|
||||
spell->resolve();
|
||||
delete spell;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MTGHermitRule * MTGHermitRule::clone() const
|
||||
|
||||
Reference in New Issue
Block a user