Tidy up a little...

This commit is contained in:
Anthony Calosa
2015-09-17 21:30:55 +08:00
parent e097d38347
commit 478dea6af4
5 changed files with 129 additions and 68 deletions
+13 -38
View File
@@ -2420,9 +2420,9 @@ public:
{ {
SAFE_DELETE(wppt); SAFE_DELETE(wppt);
if(cda) if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
} }
MTGCardInstance * _target = (MTGCardInstance *) target; MTGCardInstance * _target = (MTGCardInstance *) target;
_target->power += wppt->power.getValue(); _target->power += wppt->power.getValue();
@@ -2434,9 +2434,9 @@ public:
{ {
SAFE_DELETE(wppt); SAFE_DELETE(wppt);
if(cda) if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
} }
((MTGCardInstance *) target)->origpower = wppt->power.getValue(); ((MTGCardInstance *) target)->origpower = wppt->power.getValue();
((MTGCardInstance *) target)->origtoughness = (wppt->toughness.getValue() + ((MTGCardInstance *) target)->life)-((MTGCardInstance *) target)->life;//what? ((MTGCardInstance *) target)->origtoughness = (wppt->toughness.getValue() + ((MTGCardInstance *) target)->life)-((MTGCardInstance *) target)->life;//what?
@@ -2449,27 +2449,17 @@ public:
{ {
SAFE_DELETE(wppt); SAFE_DELETE(wppt);
if(cda) if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
} }
if(cda) if(cda)
{//Characteristic-defining abilities {//Characteristic-defining abilities
_target->origpower = wppt->power.getValue();//set orig pt _target->cdaPT(wppt->power.getValue(),wppt->toughness.getValue());
_target->origtoughness = wppt->toughness.getValue();
_target->setPower(_target->origpower);//update PT
_target->setToughness(_target->origtoughness);
_target->power += _target->pbonus;//add new bonus
_target->addToToughness(_target->tbonus);
} }
else else
{ {
_target->power -= _target->pbonus;//remove current bonuses _target->addptbonus(wppt->power.getValue(),wppt->toughness.getValue());
_target->addToToughness(-_target->tbonus);
_target->pbonus += wppt->power.getValue();//update bonus
_target->tbonus += wppt->toughness.getValue();
_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)
{ {
@@ -2485,12 +2475,7 @@ public:
} }
else else
{ {
((MTGCardInstance *) target)->power -= ((MTGCardInstance *) target)->pbonus; ((MTGCardInstance *) target)->removeptbonus(wppt->power.getValue(),wppt->toughness.getValue());
((MTGCardInstance *) target)->addToToughness(-((MTGCardInstance *) target)->tbonus);
((MTGCardInstance *) target)->pbonus -= wppt->power.getValue();
((MTGCardInstance *) target)->tbonus -= wppt->toughness.getValue();
((MTGCardInstance *) target)->power += ((MTGCardInstance *) target)->pbonus;
((MTGCardInstance *) target)->addToToughness(((MTGCardInstance *) target)->tbonus);
} }
return 1; return 1;
} }
@@ -2500,9 +2485,9 @@ public:
{ {
SAFE_DELETE(wppt); SAFE_DELETE(wppt);
if(cda) if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
} }
sprintf(menuText, "%i/%i", wppt->power.getValue(), wppt->toughness.getValue()); sprintf(menuText, "%i/%i", wppt->power.getValue(), wppt->toughness.getValue());
return menuText; return menuText;
@@ -5846,23 +5831,13 @@ public:
{ {
nbOpponents = source->blockers.size(); nbOpponents = source->blockers.size();
if (nbOpponents <= MaxOpponent) return 0; if (nbOpponents <= MaxOpponent) return 0;
source->power -= source->pbonus; source->addptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
source->addToToughness(-source->tbonus);
source->pbonus += PowerModifier * (nbOpponents - MaxOpponent);
source->tbonus += ToughnessModifier * (nbOpponents - MaxOpponent);
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->removeptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
source->addToToughness(-source->tbonus);
source->pbonus -= PowerModifier * (nbOpponents - MaxOpponent);
source->tbonus -= ToughnessModifier * (nbOpponents - MaxOpponent);
source->power += source->pbonus;
source->addToToughness(source->tbonus);
nbOpponents = 0; nbOpponents = 0;
} }
} }
+15
View File
@@ -220,6 +220,21 @@ public:
void tap(); void tap();
void attemptUntap(); void attemptUntap();
//cda and other func
void stripPTbonus();
void minusPTbonus(int p = 0, int t = 0);
void plusPTbonus(int p = 0, int t = 0);
void applyPTbonus();
void addcounter(int p = 0, int t = 0);
void removecounter(int p = 0, int t = 0);
void addptbonus(int p = 0, int t = 0);
void removeptbonus(int p = 0, int t = 0);
void addbaseP(int p = 0);
void addbaseT(int t = 0);
void revertbaseP();
void revertbaseT();
void cdaPT(int p = 0, int t = 0);
void eventattacked(); void eventattacked();
void eventattackedAlone(); void eventattackedAlone();
void eventattackednotblocked(); void eventattackednotblocked();
+4 -18
View File
@@ -4186,10 +4186,7 @@ for (it = types.begin(); it != types.end(); it++)
if(newpowerfound ) if(newpowerfound )
{ {
WParsedInt * val = NEW WParsedInt(newpower,NULL, source); WParsedInt * val = NEW WParsedInt(newpower,NULL, source);
_target->basepower = val->getValue(); _target->addbaseP(val->getValue());
_target->power -= _target->pbonus;
_target->power = (_target->power + _target->basepower) - _target->power;
_target->power += _target->pbonus;
delete val; delete val;
} }
if(newtoughnessfound ) if(newtoughnessfound )
@@ -4197,10 +4194,7 @@ for (it = types.begin(); it != types.end(); it++)
//and you turn it into 1/1, the 1 damage is still there and the creature must die... //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... //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->addbaseT(val->getValue());
_target->addToToughness(-_target->tbonus);
_target->addToToughness(_target->basetoughness - _target->toughness);
_target->addToToughness(_target->tbonus);
delete val; delete val;
} }
@@ -4290,19 +4284,11 @@ int ATransformer::destroy()
if(newpowerfound ) if(newpowerfound )
{ {
_target->power -= _target->pbonus; _target->revertbaseP();
_target->power += _target->origpower;
_target->power -= _target->basepower;
_target->power += _target->pbonus;
_target->basepower = _target->origpower;
} }
if(newtoughnessfound ) if(newtoughnessfound )
{ {
_target->addToToughness(-_target->tbonus); _target->revertbaseT();
_target->addToToughness(_target->origtoughness);
_target->addToToughness(-_target->basetoughness);
_target->addToToughness(_target->tbonus);
_target->basetoughness = _target->origtoughness;
} }
if(newAbilityFound) if(newAbilityFound)
{ {
+2 -12
View File
@@ -56,12 +56,7 @@ int Counter::added()
{ {
if (power != 0 || toughness != 0) if (power != 0 || toughness != 0)
{ {
target->power -= target->pbonus; target->addcounter(power, toughness);
target->addToToughness(-target->tbonus);
target->pbonus += power;
target->tbonus += toughness;
target->power += target->pbonus;
target->addToToughness(target->pbonus);
} }
return 1; return 1;
} }
@@ -70,12 +65,7 @@ int Counter::removed()
{ {
if (power != 0 || toughness != 0) if (power != 0 || toughness != 0)
{ {
target->power -= target->pbonus; target->removecounter(power, toughness);
target->addToToughness(-target->tbonus);
target->pbonus -= power;
target->tbonus -= toughness;
target->power += target->pbonus;
target->addToToughness(target->pbonus);
} }
return 1; return 1;
} }
+95
View File
@@ -599,6 +599,101 @@ int MTGCardInstance::setToughness(int value)
return 1; return 1;
} }
void MTGCardInstance::stripPTbonus()
{
power -= pbonus;
addToToughness(-tbonus);
}
void MTGCardInstance::plusPTbonus(int p, int t)
{
pbonus += p;
tbonus += t;
}
void MTGCardInstance::minusPTbonus(int p, int t)
{
pbonus -= p;
tbonus -= t;
}
void MTGCardInstance::applyPTbonus()
{
power += pbonus;
addToToughness(tbonus);
}
void MTGCardInstance::addcounter(int p, int t)
{
stripPTbonus();
plusPTbonus(p,t);
applyPTbonus();
}
void MTGCardInstance::addptbonus(int p, int t)
{
stripPTbonus();
plusPTbonus(p,t);
applyPTbonus();
}
void MTGCardInstance::removecounter(int p, int t)
{
stripPTbonus();
minusPTbonus(p,t);
applyPTbonus();
}
void MTGCardInstance::removeptbonus(int p, int t)
{
stripPTbonus();
minusPTbonus(p,t);
applyPTbonus();
}
void MTGCardInstance::addbaseP(int p)
{
basepower = p;
power -= pbonus;
power = p;
power += pbonus;
}
void MTGCardInstance::addbaseT(int t)
{
basetoughness = t;
addToToughness(-tbonus);
addToToughness(t - toughness);
addToToughness(tbonus);
}
void MTGCardInstance::revertbaseP()
{
power -= pbonus;
power += origpower;
power -= basepower;
power += pbonus;
basepower = origpower;
}
void MTGCardInstance::revertbaseT()
{
addToToughness(-tbonus);
addToToughness(origtoughness);
addToToughness(-basetoughness);
addToToughness(tbonus);
basetoughness = origtoughness;
}
void MTGCardInstance::cdaPT(int p, int t)
{
origpower = p;
origtoughness = t;
setPower(p);
setToughness(t);
applyPTbonus();
}
int MTGCardInstance::canBlock() int MTGCardInstance::canBlock()
{ {
if (tapped) if (tapped)