Fix for issue 647 (Evil Presence cast on a swamp removes mana ability)

This commit is contained in:
wagic.the.homebrew
2011-05-08 09:06:56 +00:00
parent b2ba514d7a
commit 2c0b5baab7
10 changed files with 111 additions and 15 deletions
+1 -1
View File
@@ -274,7 +274,7 @@ void CardPrimitive::setName(const string& value)
std::transform(lcname.begin(), lcname.end(), lcname.begin(), ::tolower);
//This is a bug fix for plague rats and the "foreach ability"
//Right now we add names as types, so that they get recognized
if (lcname.at(value.length() - 1) == 's')
if (value.length() && lcname.at(value.length() - 1) == 's')
Subtypes::subtypesList->find(lcname);
}
+9 -6
View File
@@ -303,14 +303,15 @@ void GameObserver::addObserver(MTGAbility * observer)
mLayers->actionLayer()->Add(observer);
}
void GameObserver::removeObserver(ActionElement * observer)
//Returns true if the Ability was correctly removed from the game, false otherwise
//Main (valid) reason of returning false is an attempt at removing an Ability that has already been removed
bool GameObserver::removeObserver(ActionElement * observer)
{
if (observer)
mLayers->actionLayer()->moveToGarbage(observer);
if (!observer)
return false;
return mLayers->actionLayer()->moveToGarbage(observer);
else
{
} //TODO log error
}
GameObserver::~GameObserver()
@@ -375,6 +376,8 @@ void GameObserver::gameStateBasedEffects()
{
MTGCardInstance * card = zone->cards[j];
card->afterDamage();
card->mPropertiesChangedSinceLastUpdate = false;
///////////////////////////////////////////////////////
//Remove auras that don't have a valid target anymore//
///////////////////////////////////////////////////////
+5 -4
View File
@@ -3767,7 +3767,7 @@ void ListMaintainerAbility::updateTargets()
for (map<MTGCardInstance *, bool>::iterator it = cards.begin(); it != cards.end(); ++it)
{
MTGCardInstance * card = (*it).first;
if (!canBeInList(card))
if (!canBeInList(card) || card->mPropertiesChangedSinceLastUpdate)
{
temp[card] = true;
}
@@ -3794,11 +3794,12 @@ void ListMaintainerAbility::updateTargets()
{
for (int j = 0; j < zone->nb_cards; j++)
{
if (canBeInList(zone->cards[j]))
MTGCardInstance * card = zone->cards[j];
if (canBeInList(card))
{
if (cards.find(zone->cards[j]) == cards.end())
if (cards.find(card) == cards.end())
{
temp[zone->cards[j]] = true;
temp[card] = true;
}
}
}
+21
View File
@@ -145,6 +145,7 @@ void MTGCardInstance::initMTGCI()
wasDealtDamage = false;
suspended = false;
castMethod = Constants::NOT_CAST;
mPropertiesChangedSinceLastUpdate = false;
for (int i = 0; i < ManaCost::MANA_PAID_WITH_RETRACE +1; i++)
@@ -233,6 +234,16 @@ void MTGCardInstance::addType(int type)
{
bool before = hasType(type);
CardPrimitive::addType(type);
if (!before)
mPropertiesChangedSinceLastUpdate = true;
// If the card name is not set, set it to the type.
//This is a hack for "transform", used in combination with "losesubtypes" on Basic Lands
//See removeType below
if (!name.length())
setName(Subtypes::subtypesList->find(type));
WEvent * e = NEW WEventCardChangeType(this, type, before, true);
GameObserver * go = GameObserver::GetInstance();
if (go)
@@ -267,6 +278,16 @@ int MTGCardInstance::removeType(int id, int removeAll)
bool before = hasType(id);
int result = CardPrimitive::removeType(id, removeAll);
bool after = hasType(id);
if (before != after)
{
mPropertiesChangedSinceLastUpdate = true;
// Basic lands have the same name as their subtypes, and TargetChoosers don't make a distinction between name and type,
// so if we remove a subtype "Forest", we also need to remove its name.
//This means the card might lose its name, but usually when we force remove a type, we add another one just after that.
//see "AddType" above which force sets a name if necessary
if (name.compare(Subtypes::subtypesList->find(id)) == 0)
setName("");
}
WEvent * e = NEW WEventCardChangeType(this, id, before, after);
GameObserver * go = GameObserver::GetInstance();
if (go)