Separated PT Modifiers, Fixed Changeling, Modified Counter as a cost

CDA Todo
This commit is contained in:
Anthony Calosa
2015-09-12 12:03:52 +08:00
parent 8b287cca0c
commit 11d68c0e27
9 changed files with 119 additions and 66 deletions
+27 -29
View File
@@ -2260,16 +2260,18 @@ public:
{ {
if(!nonstatic) if(!nonstatic)
return; return;
((MTGCardInstance *) target)->power -= wppt->power.getValue(); ((MTGCardInstance *) target)->pbonus -= wppt->power.getValue();
((MTGCardInstance *) target)->addToToughness(-wppt->toughness.getValue()); ((MTGCardInstance *) target)->tbonus -= wppt->toughness.getValue();
((MTGCardInstance *) target)->applyPTL();
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->pbonus += wppt->power.getValue();
_target->addToToughness(wppt->toughness.getValue()); _target->tbonus += wppt->toughness.getValue();
_target->applyPTL();
} }
int addToGame() int addToGame()
@@ -2280,8 +2282,9 @@ public:
SAFE_DELETE(wppt); SAFE_DELETE(wppt);
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source); wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
} }
_target->power += wppt->power.getValue(); _target->pbonus += wppt->power.getValue();
_target->addToToughness(wppt->toughness.getValue()); _target->tbonus += wppt->toughness.getValue();
_target->applyPTL();
if(_target->has(Constants::INDESTRUCTIBLE) && wppt->toughness.getValue() < 0 && _target->toughness <= 0) if(_target->has(Constants::INDESTRUCTIBLE) && wppt->toughness.getValue() < 0 && _target->toughness <= 0)
{ {
_target->controller()->game->putInGraveyard(_target); _target->controller()->game->putInGraveyard(_target);
@@ -2291,8 +2294,9 @@ public:
int destroy() int destroy()
{ {
((MTGCardInstance *) target)->power -= wppt->power.getValue(); ((MTGCardInstance *) target)->pbonus -= wppt->power.getValue();
((MTGCardInstance *) target)->addToToughness(-wppt->toughness.getValue()); ((MTGCardInstance *) target)->tbonus -= wppt->toughness.getValue();
((MTGCardInstance *) target)->applyPTL();
return 1; return 1;
} }
const string getMenuText() const string getMenuText()
@@ -4027,8 +4031,6 @@ string menu;
class ASwapPT: public InstantAbility class ASwapPT: public InstantAbility
{ {
public: public:
int oldpower;
int oldtoughness;
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)
{ {
@@ -4042,13 +4044,13 @@ 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
oldpower = _target->power;
oldtoughness = _target->toughness;
_target->addToToughness(oldpower); if(_target->isPTswitch)
_target->addToToughness(-oldtoughness); _target->isPTswitch = false;
_target->power = oldtoughness; else
_target->isPTswitch = true;
_target->applyPTL();
} }
return 1; return 1;
} }
@@ -4060,12 +4062,10 @@ 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
oldpower = _target->power;
oldtoughness = _target->toughness;
_target->addToToughness(oldpower); _target->isPTswitch = false;
_target->addToToughness(-oldtoughness);
_target->power = oldtoughness; _target->applyPTL();
} }
return 1; return 1;
@@ -4307,13 +4307,9 @@ public:
string newpower; string newpower;
bool newpowerfound; bool newpowerfound;
int oldpower;
int oldpowerbonus;
string newtoughness; string newtoughness;
bool newtoughnessfound; bool newtoughnessfound;
int oldtoughness;
int oldtoughnessbonus;
map<Damageable *, vector<MTGAbility *> > newAbilities; map<Damageable *, vector<MTGAbility *> > newAbilities;
vector<string> newAbilitiesList; vector<string> newAbilitiesList;
bool newAbilityFound; bool newAbilityFound;
@@ -5651,15 +5647,17 @@ public:
{ {
nbOpponents = source->blockers.size(); nbOpponents = source->blockers.size();
if (nbOpponents <= MaxOpponent) return 0; if (nbOpponents <= MaxOpponent) return 0;
source->power += PowerModifier * (nbOpponents - MaxOpponent); source->pbonus += PowerModifier * (nbOpponents - MaxOpponent);
source->addToToughness(ToughnessModifier * (nbOpponents - MaxOpponent)); source->tbonus += ToughnessModifier * (nbOpponents - MaxOpponent);
source->applyPTL();
} }
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 -= PowerModifier * (nbOpponents - MaxOpponent); source->pbonus -= PowerModifier * (nbOpponents - MaxOpponent);
source->addToToughness(-ToughnessModifier * (nbOpponents - MaxOpponent)); source->tbonus -= ToughnessModifier * (nbOpponents - MaxOpponent);
source->applyPTL();
nbOpponents = 0; nbOpponents = 0;
} }
} }
+2 -1
View File
@@ -33,8 +33,9 @@ public:
MTGCardInstance * target; MTGCardInstance * target;
Counters(MTGCardInstance * _target); Counters(MTGCardInstance * _target);
~Counters(); ~Counters();
int addCounter(const char * _name, int _power = 0, int _toughness = 0); int addCounter(const char * _name, int _power = 0, int _toughness = 0, bool _noevent = false);
int addCounter(int _power, int _toughness); int addCounter(int _power, int _toughness);
int addCounter(int _power, int _toughness, bool _noevent);
int removeCounter(const char * _name, int _power = 0, int _toughness = 0); int removeCounter(const char * _name, int _power = 0, int _toughness = 0);
int removeCounter(int _power, int _toughness); int removeCounter(int _power, int _toughness);
Counter * hasCounter(const char * _name, int _power = 0, int _toughness = 0); Counter * hasCounter(const char * _name, int _power = 0, int _toughness = 0);
+7
View File
@@ -73,8 +73,10 @@ public:
int isToken; int isToken;
int origpower; int origpower;
int basepower;//to keep origpower intact int basepower;//to keep origpower intact
int pbonus;
int origtoughness; int origtoughness;
int basetoughness;//to keep origtoughness intact int basetoughness;//to keep origtoughness intact
int tbonus;
int isMultiColored; int isMultiColored;
int isLeveler; int isLeveler;
bool enchanted; bool enchanted;
@@ -184,6 +186,11 @@ 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);
+11 -18
View File
@@ -4183,23 +4183,17 @@ for (it = types.begin(); it != types.end(); it++)
if(newpowerfound ) if(newpowerfound )
{//setting p/t only overrides base p/t as of M15 changes {//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);
oldpower = _target->power;
oldpowerbonus = oldpower - _target->basepower;
_target->setPower(oldpowerbonus + val->getValue());
_target->basepower = val->getValue(); _target->basepower = val->getValue();
//?effects that change pt outside this? _target->isSettingBase = true;
//_target->power += reapplyCountersBonus(_target,false,true); _target->applyPTL();
delete val; delete val;
} }
if(newtoughnessfound ) if(newtoughnessfound )
{//setting p/t only overrides base p/t as of M15 changes {//setting p/t only overrides base p/t as of M15 changes
WParsedInt * val = NEW WParsedInt(newtoughness,NULL, source); WParsedInt * val = NEW WParsedInt(newtoughness,NULL, source);
oldtoughness = _target->toughness;
oldtoughnessbonus = oldtoughness - _target->basetoughness;
_target->setToughness(oldtoughnessbonus + val->getValue());
_target->basetoughness = val->getValue(); _target->basetoughness = val->getValue();
//_target->addToToughness(reapplyCountersBonus(_target,true,false)); _target->isSettingBase = true;
_target->life = _target->toughness; _target->applyPTL();
delete val; delete val;
} }
@@ -4286,16 +4280,15 @@ int ATransformer::destroy()
if(newpowerfound ) if(newpowerfound )
{//override since we changed tha base, the bonus must have changed {//override since we changed tha base, the bonus must have changed
oldpowerbonus = (_target->power - _target->basepower);//math hurts my head...it's all over the place :P _target->isSettingBase = false;
_target->setPower(_target->origpower + oldpowerbonus); _target->basepower = _target->origpower;
_target->basepower = _target->origpower;//revert _target->applyPTL();
} }
if(newtoughnessfound ) if(newtoughnessfound )
{//override since we changed tha base, the bonus must have changed {
oldtoughnessbonus = (_target->toughness - _target->basetoughness); _target->isSettingBase = false;
_target->setToughness(_target->origtoughness + oldtoughnessbonus); _target->basetoughness = _target->origtoughness;
_target->basetoughness = _target->origtoughness;//revert _target->applyPTL();
_target->life = _target->toughness;//update
} }
if(newAbilityFound) if(newAbilityFound)
{ {
+19 -9
View File
@@ -56,8 +56,9 @@ int Counter::added()
{ {
if (power != 0 || toughness != 0) if (power != 0 || toughness != 0)
{ {
target->power += power; target->pbonus += power;
target->addToToughness(toughness); target->tbonus += toughness;
target->applyPTL();
} }
return 1; return 1;
} }
@@ -66,8 +67,9 @@ int Counter::removed()
{ {
if (power != 0 || toughness != 0) if (power != 0 || toughness != 0)
{ {
target->power -= power; target->pbonus -= power;
target->addToToughness(-toughness); target->tbonus -= toughness;
target->applyPTL();
} }
return 1; return 1;
} }
@@ -85,7 +87,7 @@ Counters::~Counters()
} }
} }
int Counters::addCounter(const char * _name, int _power, int _toughness) int Counters::addCounter(const char * _name, int _power, int _toughness, bool _noevent)
{ {
/*420.5n If a permanent has both a +1/+1 counter and a -1/-1 counter on it, N +1/+1 and N -1/-1 counters are removed from it, where N is the smaller of the number of +1/+1 and -1/-1 counters on it.*/ /*420.5n If a permanent has both a +1/+1 counter and a -1/-1 counter on it, N +1/+1 and N -1/-1 counters are removed from it, where N is the smaller of the number of +1/+1 and -1/-1 counters on it.*/
GameObserver *g = target->getObserver(); GameObserver *g = target->getObserver();
@@ -109,9 +111,12 @@ int Counters::addCounter(const char * _name, int _power, int _toughness)
Counter * counter = NEW Counter(target, _name, _power, _toughness); Counter * counter = NEW Counter(target, _name, _power, _toughness);
counters.push_back(counter); counters.push_back(counter);
counter->added(); counter->added();
WEvent * w = NEW WEventCounters(this,_name,_power,_toughness,true,false); if (!_noevent)
dynamic_cast<WEventCounters*>(w)->targetCard = this->target; {
g->receiveEvent(w); WEvent * w = NEW WEventCounters(this,_name,_power,_toughness,true,false);
dynamic_cast<WEventCounters*>(w)->targetCard = this->target;
g->receiveEvent(w);
}
mCount++; mCount++;
this->target->doDamageTest = 1; this->target->doDamageTest = 1;
this->target->afterDamage(); this->target->afterDamage();
@@ -122,7 +127,12 @@ int Counters::addCounter(const char * _name, int _power, int _toughness)
int Counters::addCounter(int _power, int _toughness) int Counters::addCounter(int _power, int _toughness)
{ {
return addCounter("", _power, _toughness); return addCounter("", _power, _toughness, false);
}
int Counters::addCounter(int _power, int _toughness, bool _noevent)
{
return addCounter("", _power, _toughness, _noevent);
} }
int Counters::init() int Counters::init()
+2 -2
View File
@@ -949,8 +949,8 @@ int CounterCost::doPay()
if (counter->nb >= 0) if (counter->nb >= 0)
{ //Add counters as a cost { //Add counters as a cost
for (int i = 0; i < counter->nb; i++) for (int i = 0; i < counter->nb; i++)
{ {//send no event because its a cost not an effect... for doubling season
target->counters->addCounter(counter->name.c_str(), counter->power, counter->toughness); target->counters->addCounter(counter->name.c_str(), counter->power, counter->toughness, true);
} }
if (tc) if (tc)
tc->initTargets(); tc->initTargets();
+11 -5
View File
@@ -3597,9 +3597,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->power = 2; card->basepower = 2;
card->life = 2; card->life = 2;
card->toughness = 2; card->basetoughness = 2;
card->setColor(0,1); card->setColor(0,1);
card->name = "Morph"; card->name = "Morph";
card->types.clear(); card->types.clear();
@@ -3607,12 +3607,17 @@ 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->power += card->origpower-2; card->isSettingBase = false;
card->life += card->origtoughness-2; card->power = card->origpower;
card->toughness += card->origtoughness-2; card->basepower = card->origpower;
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;
@@ -3626,6 +3631,7 @@ 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)
+32
View File
@@ -37,8 +37,10 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
lifeOrig = life; lifeOrig = life;
origpower = power; origpower = power;
basepower = origpower; basepower = origpower;
pbonus = 0;
origtoughness = toughness; origtoughness = toughness;
basetoughness = origtoughness; basetoughness = origtoughness;
tbonus = 0;
belongs_to = arg_belongs_to; belongs_to = arg_belongs_to;
owner = NULL; owner = NULL;
if (arg_belongs_to) if (arg_belongs_to)
@@ -51,6 +53,8 @@ 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()
@@ -62,6 +66,34 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
return snapShot; return snapShot;
} }
void MTGCardInstance::applyPTL()
{
//7a ??how to add cda(Characteristic Defining Ability)??
power = origpower;
toughness = origtoughness;
//7b
if (isSettingBase)
{
power = basepower;
toughness = basetoughness;
}
//7c - 7d shared?
power += pbonus;
toughness += tbonus;
life = toughness;
//7e switch is last
if (isPTswitch)
{
oldP = power;
oldT = toughness;
this->addToToughness(oldP);
this->addToToughness(-oldT);
this->power = oldT;
}
/* end */
doDamageTest = 1;
}
void MTGCardInstance::copy(MTGCardInstance * card) void MTGCardInstance::copy(MTGCardInstance * card)
{ {
MTGCard * source = card->model; MTGCard * source = card->model;
+7 -1
View File
@@ -1078,7 +1078,13 @@ bool TypeTargetChooser::canTarget(Targetable * target,bool withoutProtections)
{ {
if (card->hasSubtype(types[i])) return true; if (card->hasSubtype(types[i])) return true;
if (card->data->basicAbilities[(int)Constants::CHANGELING]) return true;//changelings can be targeted as any subtype. if (card->data->basicAbilities[(int)Constants::CHANGELING])
{
if (!MTGAllCards::isSubtypeOfType(i,Subtypes::TYPE_CREATURE))
return false;
return true;
}
if(card->getLCName().size()) if(card->getLCName().size())
{ {
if (MTGAllCards::findType(card->getLCName()) == types[i]) if (MTGAllCards::findType(card->getLCName()) == types[i])