CDA complete

This fixes the bug I introduced lst time. The damage was not taking into
account, but this time the damage reflects...
TODO/TOFOLLOW: update test and update all cards that uses CDA :)
This commit is contained in:
Anthony Calosa
2015-09-16 06:42:02 +08:00
parent 72aaa18a35
commit 6aab17d0b3
6 changed files with 94 additions and 110 deletions
+62 -53
View File
@@ -679,43 +679,28 @@ private:
else if (s == "gravecardtypes")//Tarmogoyf else if (s == "gravecardtypes")//Tarmogoyf
{ {
intValue = 0; intValue = 0;
bool art, cre, enc, ins, lnd, sor, trb, pwk = false; int art, cre, enc, ins, lnd, sor, trb, pwk = 0;
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
Player * p = card->getObserver()->players[i]; Player * p = card->getObserver()->players[i];
if(p->game->graveyard->hasType("planeswalker")) if(p->game->graveyard->hasType("planeswalker"))
pwk = true; pwk = 1;
if(p->game->graveyard->hasType("tribal")) if(p->game->graveyard->hasType("tribal"))
trb = true; trb = 1;
if(p->game->graveyard->hasType("sorcery")) if(p->game->graveyard->hasType("sorcery"))
sor = true; sor = 1;
if(p->game->graveyard->hasType("land")) if(p->game->graveyard->hasType("land"))
lnd = true; lnd = 1;
if(p->game->graveyard->hasType("instant")) if(p->game->graveyard->hasType("instant"))
ins = true; ins = 1;
if(p->game->graveyard->hasType("enchantment")) if(p->game->graveyard->hasType("enchantment"))
enc = true; enc = 1;
if(p->game->graveyard->hasType("creature")) if(p->game->graveyard->hasType("creature"))
cre = true; cre = 1;
if(p->game->graveyard->hasType("artifact")) if(p->game->graveyard->hasType("artifact"))
art = true; art = 1;
} }
if (art) intValue = art + cre + enc + ins + lnd + sor + trb + pwk;
intValue += 1;
if (cre)
intValue += 1;
if (enc)
intValue += 1;
if (ins)
intValue += 1;
if (lnd)
intValue += 1;
if (sor)
intValue += 1;
if (trb)
intValue += 1;
if (pwk)
intValue += 1;
} }
else if (s == "morethanfourcards") else if (s == "morethanfourcards")
{ {
@@ -2339,24 +2324,28 @@ public:
{ {
if(!nonstatic) if(!nonstatic)
return; return;
if(!((MTGCardInstance *) target)->isSettingBase) if(!cda)
{ {
((MTGCardInstance *) target)->power -= wppt->power.getValue(); ((MTGCardInstance *) target)->power -= wppt->power.getValue();
((MTGCardInstance *) target)->addToToughness(-wppt->toughness.getValue()); ((MTGCardInstance *) target)->addToToughness(-wppt->toughness.getValue());
if(PT.size()) if(PT.size())
{ {
SAFE_DELETE(wppt); SAFE_DELETE(wppt);
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
} }
MTGCardInstance * _target = (MTGCardInstance *) target; MTGCardInstance * _target = (MTGCardInstance *) target;
_target->power += wppt->power.getValue(); _target->power += wppt->power.getValue();
_target->addToToughness(wppt->toughness.getValue()); _target->addToToughness(wppt->toughness.getValue());
//update }
if(cda) else
{//7a update wppt {//CDA 7a update wppt
_target->origpower = wppt->power.getValue(); if(PT.size())
_target->origtoughness = wppt->toughness.getValue(); {
} SAFE_DELETE(wppt);
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
}
((MTGCardInstance *) target)->origpower = wppt->power.getValue();
((MTGCardInstance *) target)->origtoughness = wppt->toughness.getValue();
} }
} }
int addToGame() int addToGame()
@@ -2369,15 +2358,23 @@ public:
} }
if(cda) if(cda)
{//Characteristic-defining abilities {//Characteristic-defining abilities
_target->origpower = wppt->power.getValue(); _target->origpower = wppt->power.getValue();//set orig pt
_target->origtoughness = wppt->toughness.getValue(); _target->origtoughness = wppt->toughness.getValue();
_target->applyPTL(); _target->power -= _target->pbonus;//remove current bonuses
_target->addToToughness(-_target->tbonus);
_target->setPower(_target->origpower);//update PT
_target->setToughness(_target->origtoughness);
_target->power += _target->pbonus;//add new bonus
_target->addToToughness(_target->tbonus);
} }
else else
{ {
_target->pbonus += wppt->power.getValue(); _target->power -= _target->pbonus;//remove current bonuses
_target->addToToughness(-_target->tbonus);
_target->pbonus += wppt->power.getValue();//update bonus
_target->tbonus += wppt->toughness.getValue(); _target->tbonus += wppt->toughness.getValue();
_target->applyPTL(); _target->power += _target->pbonus;//add new bonus
_target->addToToughness(_target->tbonus);
} }
if(_target->has(Constants::INDESTRUCTIBLE) && wppt->toughness.getValue() < 0 && _target->toughness <= 0) if(_target->has(Constants::INDESTRUCTIBLE) && wppt->toughness.getValue() < 0 && _target->toughness <= 0)
{ {
@@ -2393,9 +2390,12 @@ public:
} }
else else
{ {
((MTGCardInstance *) target)->power -= ((MTGCardInstance *) target)->pbonus;
((MTGCardInstance *) target)->addToToughness(-((MTGCardInstance *) target)->tbonus);
((MTGCardInstance *) target)->pbonus -= wppt->power.getValue(); ((MTGCardInstance *) target)->pbonus -= wppt->power.getValue();
((MTGCardInstance *) target)->tbonus -= wppt->toughness.getValue(); ((MTGCardInstance *) target)->tbonus -= wppt->toughness.getValue();
((MTGCardInstance *) target)->applyPTL(); ((MTGCardInstance *) target)->power += ((MTGCardInstance *) target)->pbonus;
((MTGCardInstance *) target)->addToToughness(((MTGCardInstance *) target)->tbonus);
} }
return 1; return 1;
} }
@@ -4129,6 +4129,8 @@ string menu;
class ASwapPT: public InstantAbility class ASwapPT: public InstantAbility
{ {
public: public:
int oldP;
int oldT;
ASwapPT(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) : ASwapPT(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) :
InstantAbility(observer, _id, _source, _target) InstantAbility(observer, _id, _source, _target)
{ {
@@ -4143,12 +4145,11 @@ public:
while (_target->next) while (_target->next)
_target = _target->next; //This is for cards such as rampant growth _target = _target->next; //This is for cards such as rampant growth
if(_target->isPTswitch) oldP = _target->power;
_target->isPTswitch = false; oldT = _target->toughness;
else _target->addToToughness(oldP);
_target->isPTswitch = true; _target->addToToughness(-oldT);
_target->setPower(oldT);
_target->applyPTL();
} }
return 1; return 1;
} }
@@ -4161,9 +4162,11 @@ public:
while (_target->next) while (_target->next)
_target = _target->next; //This is for cards such as rampant growth _target = _target->next; //This is for cards such as rampant growth
_target->isPTswitch = false; oldP = _target->power;
oldT = _target->toughness;
_target->applyPTL(); _target->addToToughness(oldP);
_target->addToToughness(-oldT);
_target->setPower(oldT);
} }
return 1; return 1;
@@ -5745,17 +5748,23 @@ public:
{ {
nbOpponents = source->blockers.size(); nbOpponents = source->blockers.size();
if (nbOpponents <= MaxOpponent) return 0; if (nbOpponents <= MaxOpponent) return 0;
source->power -= source->pbonus;
source->addToToughness(-source->tbonus);
source->pbonus += PowerModifier * (nbOpponents - MaxOpponent); source->pbonus += PowerModifier * (nbOpponents - MaxOpponent);
source->tbonus += ToughnessModifier * (nbOpponents - MaxOpponent); source->tbonus += ToughnessModifier * (nbOpponents - MaxOpponent);
source->applyPTL(); source->power += source->pbonus;
source->addToToughness(source->tbonus);
} }
else if (WEventPhaseChange* pe = dynamic_cast<WEventPhaseChange*>(event)) else if (WEventPhaseChange* pe = dynamic_cast<WEventPhaseChange*>(event))
{ {
if (MTG_PHASE_AFTER_EOT == pe->to->id && nbOpponents > MaxOpponent) if (MTG_PHASE_AFTER_EOT == pe->to->id && nbOpponents > MaxOpponent)
{ {
source->power -= source->pbonus;
source->addToToughness(-source->tbonus);
source->pbonus -= PowerModifier * (nbOpponents - MaxOpponent); source->pbonus -= PowerModifier * (nbOpponents - MaxOpponent);
source->tbonus -= ToughnessModifier * (nbOpponents - MaxOpponent); source->tbonus -= ToughnessModifier * (nbOpponents - MaxOpponent);
source->applyPTL(); source->power += source->pbonus;
source->addToToughness(source->tbonus);
nbOpponents = 0; nbOpponents = 0;
} }
} }
-5
View File
@@ -186,11 +186,6 @@ public:
int addToToughness(int value); int addToToughness(int value);
int setToughness(int value); int setToughness(int value);
bool isSettingBase;
bool isPTswitch;
int oldP;
int oldT;
void applyPTL();
vector<TargetChooser *>protections; vector<TargetChooser *>protections;
int addProtection(TargetChooser * tc); int addProtection(TargetChooser * tc);
+19 -11
View File
@@ -4181,19 +4181,23 @@ for (it = types.begin(); it != types.end(); it++)
} }
} }
if(newpowerfound ) if(newpowerfound )
{//setting p/t only overrides base p/t as of M15 changes {
WParsedInt * val = NEW WParsedInt(newpower,NULL, source); WParsedInt * val = NEW WParsedInt(newpower,NULL, source);
_target->basepower = val->getValue(); _target->basepower = val->getValue();
_target->isSettingBase = true; _target->power -= _target->pbonus;
_target->applyPTL(); _target->power = (_target->power + _target->basepower) - _target->power;
_target->power += _target->pbonus;
delete val; delete val;
} }
if(newtoughnessfound ) if(newtoughnessfound )
{//setting p/t only overrides base p/t as of M15 changes {//we should consider the damage if there is, if you have a 5/5 creature with 1 damage,
//and you turn it into 1/1, the 1 damage is still there and the creature must die...
//the toughness is intact but what we see in the game is the life...
WParsedInt * val = NEW WParsedInt(newtoughness,NULL, source); WParsedInt * val = NEW WParsedInt(newtoughness,NULL, source);
_target->basetoughness = val->getValue(); _target->basetoughness = val->getValue();
_target->isSettingBase = true; _target->addToToughness(-_target->tbonus);
_target->applyPTL(); _target->addToToughness(_target->basetoughness - _target->toughness);
_target->addToToughness(_target->tbonus);
delete val; delete val;
} }
@@ -4279,16 +4283,20 @@ int ATransformer::destroy()
} }
if(newpowerfound ) if(newpowerfound )
{//override since we changed tha base, the bonus must have changed {
_target->isSettingBase = false; _target->power -= _target->pbonus;
_target->power += _target->origpower;
_target->power -= _target->basepower;
_target->power += _target->pbonus;
_target->basepower = _target->origpower; _target->basepower = _target->origpower;
_target->applyPTL();
} }
if(newtoughnessfound ) if(newtoughnessfound )
{ {
_target->isSettingBase = false; _target->addToToughness(-_target->tbonus);
_target->addToToughness(_target->origtoughness);
_target->addToToughness(-_target->basetoughness);
_target->addToToughness(_target->tbonus);
_target->basetoughness = _target->origtoughness; _target->basetoughness = _target->origtoughness;
_target->applyPTL();
} }
if(newAbilityFound) if(newAbilityFound)
{ {
+8 -2
View File
@@ -56,9 +56,12 @@ int Counter::added()
{ {
if (power != 0 || toughness != 0) if (power != 0 || toughness != 0)
{ {
target->power -= target->pbonus;
target->addToToughness(-target->tbonus);
target->pbonus += power; target->pbonus += power;
target->tbonus += toughness; target->tbonus += toughness;
target->applyPTL(); target->power += target->pbonus;
target->addToToughness(target->pbonus);
} }
return 1; return 1;
} }
@@ -67,9 +70,12 @@ int Counter::removed()
{ {
if (power != 0 || toughness != 0) if (power != 0 || toughness != 0)
{ {
target->power -= target->pbonus;
target->addToToughness(-target->tbonus);
target->pbonus -= power; target->pbonus -= power;
target->tbonus -= toughness; target->tbonus -= toughness;
target->applyPTL(); target->power += target->pbonus;
target->addToToughness(target->pbonus);
} }
return 1; return 1;
} }
+5 -11
View File
@@ -3602,9 +3602,9 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
if(card->previous && card->previous->morphed && !card->turningOver) if(card->previous && card->previous->morphed && !card->turningOver)
{ {
magicText = card->magicTexts["facedown"]; magicText = card->magicTexts["facedown"];
card->basepower = 2; card->power = 2;
card->life = 2; card->life = 2;
card->basetoughness = 2; card->toughness = 2;
card->setColor(0,1); card->setColor(0,1);
card->name = "Morph"; card->name = "Morph";
card->types.clear(); card->types.clear();
@@ -3612,17 +3612,12 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
card->setType(cre.c_str()); card->setType(cre.c_str());
card->basicAbilities.reset(); card->basicAbilities.reset();
card->getManaCost()->resetCosts(); card->getManaCost()->resetCosts();
card->isSettingBase = true;
card->applyPTL();
} }
else if(card && !card->morphed && card->turningOver) else if(card && !card->morphed && card->turningOver)
{ {
card->isSettingBase = false; card->power += card->origpower-2;
card->power = card->origpower; card->life += card->origtoughness-2;
card->basepower = card->origpower; card->toughness += card->origtoughness-2;
card->life = card->origtoughness;
card->toughness = card->origtoughness;
card->basetoughness = card->origtoughness;
card->setColor(0,1); card->setColor(0,1);
card->name = card->model->data->name; card->name = card->model->data->name;
card->types = card->model->data->types; card->types = card->model->data->types;
@@ -3636,7 +3631,6 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
string faceupC= card->magicTexts["faceup"]; string faceupC= card->magicTexts["faceup"];
magicText.append("\n"); magicText.append("\n");
magicText.append(faceupC); magicText.append(faceupC);
card->applyPTL();
} }
else if(card && card->hasType(Subtypes::TYPE_EQUIPMENT) && card->target) else if(card && card->hasType(Subtypes::TYPE_EQUIPMENT) && card->target)
-28
View File
@@ -53,8 +53,6 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
thatmuch = 0; thatmuch = 0;
flanked = 0; flanked = 0;
castMethod = Constants::NOT_CAST; castMethod = Constants::NOT_CAST;
isSettingBase = false;
isPTswitch = false;
} }
MTGCardInstance * MTGCardInstance::createSnapShot() MTGCardInstance * MTGCardInstance::createSnapShot()
@@ -66,32 +64,6 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
return snapShot; return snapShot;
} }
void MTGCardInstance::applyPTL()
{
//7a ??(Characteristic Defining Ability)??
power = origpower;
toughness = origtoughness;
//7b
if (isSettingBase)
{
power = basepower;
toughness = basetoughness;
}
//7c - 7d shared?
power += pbonus;
toughness += tbonus;
//7e switch is last
if (isPTswitch)
{
oldP = power;
oldT = toughness;
toughness = oldP;
power = oldT;
}
life = toughness;
doDamageTest = 1;
}
void MTGCardInstance::copy(MTGCardInstance * card) void MTGCardInstance::copy(MTGCardInstance * card)
{ {
MTGCard * source = card->model; MTGCard * source = card->model;