Added X to the filters for this() and thisforeach(), for use with {X} costed activated abilities, although it should theoretically work with spells as well if necessary.

This commit is contained in:
salmelo16
2010-04-14 23:42:47 +00:00
parent 73b494c32d
commit 74d2bbf324
7 changed files with 73 additions and 3 deletions
Binary file not shown.
+17 -2
View File
@@ -400,6 +400,9 @@ class GenericActivatedAbility:public ActivatedAbility, public NestedAbility{
int resolve(){ int resolve(){
counters++; counters++;
SAFE_DELETE(ability->cost);
ability->cost = abilityCost->Diff(cost);
SAFE_DELETE(abilityCost);
ability->target = target; //may have been updated... ability->target = target; //may have been updated...
if (ability) return ability->resolve(); if (ability) return ability->resolve();
return 0; return 0;
@@ -1896,7 +1899,14 @@ public:
int resolve(){ int resolve(){
//TODO check if ability is oneShot ? //TODO check if ability is oneShot ?
if (td->match(source) > 0){ int match;
if (!td->compareAbility){
match = td->match(source);
}else{
match = td->match(this);
}
if (match){
addAbilityToGame(); addAbilityToGame();
}else{ }else{
removeAbilityFromGame(); removeAbilityFromGame();
@@ -1961,7 +1971,12 @@ class AThisForEach:public MTGAbility, public NestedAbility{
int resolve(){ int resolve(){
//TODO check if ability is oneShot ? //TODO check if ability is oneShot ?
int matches = td->match(source); int matches;
if (!td->compareAbility){
matches = td->match(source);
}else{
matches = td->match(this);
}
if (matches > 0) { if (matches > 0) {
if (abilities.size()){ if (abilities.size()){
removeAbilityFromGame(); removeAbilityFromGame();
+1 -1
View File
@@ -12,12 +12,12 @@ using namespace std;
class CardPrimitive { class CardPrimitive {
protected: protected:
ManaCost manaCost;
vector<string> ftdText; vector<string> ftdText;
int init(); int init();
string lcname; string lcname;
public: public:
ManaCost manaCost;
string text; string text;
string name; string name;
+2
View File
@@ -158,9 +158,11 @@ class ActivatedAbility:public MTGAbility{
CLEANUP = 56, CLEANUP = 56,
AFTER_EOT = 57, AFTER_EOT = 57,
}; };
ManaCost * abilityCost;
int restrictions; int restrictions;
int needsTapping; int needsTapping;
ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _restrictions = NO_RESTRICTION,int tap = 1); ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _restrictions = NO_RESTRICTION,int tap = 1);
virtual ~ActivatedAbility();
virtual int reactToClick(MTGCardInstance * card); virtual int reactToClick(MTGCardInstance * card);
virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
virtual int reactToTargetClick(Targetable * object); virtual int reactToTargetClick(Targetable * object);
+13
View File
@@ -12,9 +12,11 @@
class ThisDescriptor{ class ThisDescriptor{
public: public:
int compareAbility;
int comparisonMode; int comparisonMode;
int comparisonCriterion; int comparisonCriterion;
virtual int match(MTGCardInstance * card) = 0; virtual int match(MTGCardInstance * card) = 0;
virtual int match(MTGAbility * ability) = 0;
int matchValue(int value); int matchValue(int value);
}; };
@@ -27,6 +29,7 @@ class ThisCounter:public ThisDescriptor{
public: public:
Counter * counter; Counter * counter;
virtual int match(MTGCardInstance * card); virtual int match(MTGCardInstance * card);
virtual int match(MTGAbility * ability) {return 0;};
ThisCounter(Counter * _counter); ThisCounter(Counter * _counter);
ThisCounter(int power, int toughness, int nb, const char * name); ThisCounter(int power, int toughness, int nb, const char * name);
~ThisCounter(); ~ThisCounter();
@@ -35,19 +38,29 @@ class ThisCounter:public ThisDescriptor{
class ThisCounterAny:public ThisDescriptor{ class ThisCounterAny:public ThisDescriptor{
public: public:
virtual int match(MTGCardInstance *card); virtual int match(MTGCardInstance *card);
virtual int match(MTGAbility * ability) {return 0;};
ThisCounterAny(int nb); ThisCounterAny(int nb);
}; };
class ThisPower:public ThisDescriptor{ class ThisPower:public ThisDescriptor{
public: public:
virtual int match(MTGCardInstance * card); virtual int match(MTGCardInstance * card);
virtual int match(MTGAbility * ability) {return 0;};
ThisPower(int power); ThisPower(int power);
}; };
class ThisToughness:public ThisDescriptor{ class ThisToughness:public ThisDescriptor{
public: public:
virtual int match(MTGCardInstance * card); virtual int match(MTGCardInstance * card);
virtual int match(MTGAbility * ability) {return 0;};
ThisToughness(int toughness); ThisToughness(int toughness);
}; };
class ThisX:public ThisDescriptor{
public:
virtual int match(MTGAbility * ability);
virtual int match(MTGCardInstance * card) {return 0;};
ThisX(int x);
};
#endif #endif
+15
View File
@@ -1813,6 +1813,7 @@ NestedAbility::NestedAbility(MTGAbility * _ability){
ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _cost, int restrictions,int tap):MTGAbility(id,card), restrictions(restrictions), needsTapping(tap){ ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _cost, int restrictions,int tap):MTGAbility(id,card), restrictions(restrictions), needsTapping(tap){
cost = _cost; cost = _cost;
abilityCost = 0;
} }
@@ -1856,13 +1857,17 @@ int ActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
int ActivatedAbility::reactToClick(MTGCardInstance * card){ int ActivatedAbility::reactToClick(MTGCardInstance * card){
// if (cost) cost->setExtraCostsAction(this, card); // if (cost) cost->setExtraCostsAction(this, card);
if (!isReactingToClick(card)) return 0; if (!isReactingToClick(card)) return 0;
Player * player = game->currentlyActing();
if (cost){ if (cost){
if (!cost->isExtraPaymentSet()){ if (!cost->isExtraPaymentSet()){
game->waitForExtraPayment = cost->extraCosts; game->waitForExtraPayment = cost->extraCosts;
return 0; return 0;
} }
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
game->currentlyActing()->getManaPool()->pay(cost); game->currentlyActing()->getManaPool()->pay(cost);
cost->doPayExtra(); cost->doPayExtra();
abilityCost = previousManaPool->Diff(player->getManaPool());
delete previousManaPool;
} }
if (needsTapping && source->isInPlay()) source->tap(); if (needsTapping && source->isInPlay()) source->tap();
fireAbility(); fireAbility();
@@ -1873,14 +1878,18 @@ int ActivatedAbility::reactToClick(MTGCardInstance * card){
int ActivatedAbility::reactToTargetClick(Targetable * object){ int ActivatedAbility::reactToTargetClick(Targetable * object){
if (!isReactingToTargetClick(object)) return 0; if (!isReactingToTargetClick(object)) return 0;
Player * player = game->currentlyActing();
if (cost){ if (cost){
if (object->typeAsTarget() == TARGET_CARD) cost->setExtraCostsAction(this, (MTGCardInstance *) object); if (object->typeAsTarget() == TARGET_CARD) cost->setExtraCostsAction(this, (MTGCardInstance *) object);
if (!cost->isExtraPaymentSet()){ if (!cost->isExtraPaymentSet()){
game->waitForExtraPayment = cost->extraCosts; game->waitForExtraPayment = cost->extraCosts;
return 0; return 0;
} }
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
game->currentlyActing()->getManaPool()->pay(cost); game->currentlyActing()->getManaPool()->pay(cost);
cost->doPayExtra(); cost->doPayExtra();
abilityCost = previousManaPool->Diff(player->getManaPool());
delete previousManaPool;
} }
if (needsTapping && source->isInPlay()) source->tap(); if (needsTapping && source->isInPlay()) source->tap();
fireAbility(); fireAbility();
@@ -1888,6 +1897,12 @@ int ActivatedAbility::reactToTargetClick(Targetable * object){
} }
ActivatedAbility::~ActivatedAbility(){
if (!isClone){
SAFE_DELETE(abilityCost);
}
}
ostream& ActivatedAbility::toString(ostream& out) const ostream& ActivatedAbility::toString(ostream& out) const
{ {
out << "ActivatedAbility ::: restrictions : " << restrictions out << "ActivatedAbility ::: restrictions : " << restrictions
+25
View File
@@ -144,15 +144,28 @@ ThisDescriptor * ThisDescriptorFactory::createThisDescriptor(string s){
return NULL; return NULL;
} }
// X
found = s.find("x");
if (found != string::npos) {
ThisX * td = NEW ThisX(criterion);
if (td){
td->comparisonMode = mode;
return td;
}
return NULL;
}
return NULL; return NULL;
} }
ThisCounter::ThisCounter(Counter * _counter){ ThisCounter::ThisCounter(Counter * _counter){
compareAbility = 0;
counter = _counter; counter = _counter;
comparisonCriterion = counter->nb; comparisonCriterion = counter->nb;
} }
ThisCounter::ThisCounter(int power, int toughness, int nb, const char * name){ ThisCounter::ThisCounter(int power, int toughness, int nb, const char * name){
compareAbility = 0;
counter = NEW Counter(NULL,name,power,toughness); counter = NEW Counter(NULL,name,power,toughness);
comparisonCriterion = nb; comparisonCriterion = nb;
} }
@@ -184,6 +197,7 @@ ThisCounter::~ThisCounter() {
} }
ThisPower::ThisPower(int power){ ThisPower::ThisPower(int power){
compareAbility = 0;
comparisonCriterion = power; comparisonCriterion = power;
} }
@@ -192,6 +206,7 @@ int ThisPower::match(MTGCardInstance * card){
} }
ThisToughness::ThisToughness(int toughness){ ThisToughness::ThisToughness(int toughness){
compareAbility = 0;
comparisonCriterion = toughness; comparisonCriterion = toughness;
} }
@@ -200,6 +215,7 @@ int ThisToughness::match(MTGCardInstance * card){
} }
ThisCounterAny::ThisCounterAny(int nb){ ThisCounterAny::ThisCounterAny(int nb){
compareAbility = 0;
comparisonCriterion = nb; comparisonCriterion = nb;
} }
@@ -210,3 +226,12 @@ int ThisCounterAny::match(MTGCardInstance * card){
} }
return matchValue(result); return matchValue(result);
} }
ThisX::ThisX(int x){
comparisonCriterion = x;
compareAbility = 1;
}
int ThisX::match(MTGAbility * ability){
return matchValue(ability->cost->hasX());
}