modified transforms( ability. mods in first comment.
This commit is contained in:
@@ -2490,22 +2490,20 @@ public:
|
|||||||
list<int>abilities;
|
list<int>abilities;
|
||||||
list<int>types;
|
list<int>types;
|
||||||
list<int>colors;
|
list<int>colors;
|
||||||
|
list<int>oldcolors;
|
||||||
ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities):MTGAbility(id,source,target){
|
ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities):MTGAbility(id,source,target){
|
||||||
//TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class;
|
//TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class;
|
||||||
|
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||||
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++){
|
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++){
|
||||||
size_t found = sabilities.find(Constants::MTGBasicAbilities[j]);
|
size_t found = sabilities.find(Constants::MTGBasicAbilities[j]);
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
abilities.push_back(j);
|
abilities.push_back(j);}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (int j = 0; j < Constants::MTG_NB_COLORS; j++){
|
for (int j = 0; j < Constants::MTG_NB_COLORS; j++){
|
||||||
size_t found = sabilities.find(Constants::MTGColorStrings[j]);
|
size_t found = sabilities.find(Constants::MTGColorStrings[j]);
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
colors.push_back(j);
|
colors.push_back(j);}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string s = stypes;
|
string s = stypes;
|
||||||
while (s.size()){
|
while (s.size()){
|
||||||
size_t found = s.find(" ");
|
size_t found = s.find(" ");
|
||||||
@@ -2516,49 +2514,97 @@ public:
|
|||||||
}else{
|
}else{
|
||||||
int id = Subtypes::subtypesList->find(s);
|
int id = Subtypes::subtypesList->find(s);
|
||||||
types.push_back(id);
|
types.push_back(id);
|
||||||
s = "";
|
s = "";}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int addToGame(){
|
int addToGame(){
|
||||||
MTGCardInstance * _target = (MTGCardInstance *)target;
|
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||||
list<int>::iterator it;
|
for (int j = 0; j < Constants::MTG_NB_COLORS; j++){
|
||||||
for ( it=types.begin() ; it != types.end(); it++ ){
|
if (_target->hasColor(j))
|
||||||
_target->addType(*it);
|
oldcolors.push_back(j);
|
||||||
}
|
}
|
||||||
for ( it=colors.begin() ; it != colors.end(); it++ ){
|
list<int>::iterator it;
|
||||||
_target->setColor(*it);
|
for ( it=types.begin() ; it != types.end(); it++ ){_target->addType(*it);}
|
||||||
}
|
for ( it=colors.begin() ; it != colors.end(); it++ ){_target->setColor(*it,1);}
|
||||||
for ( it=abilities.begin() ; it != abilities.end(); it++ ){
|
for ( it=oldcolors.begin() ; it != oldcolors.end(); it++ ){}
|
||||||
_target->basicAbilities[*it]++;
|
for ( it=abilities.begin() ; it != abilities.end(); it++ ){_target->basicAbilities[*it]++;}
|
||||||
}
|
return MTGAbility::addToGame();}
|
||||||
return MTGAbility::addToGame();
|
|
||||||
}
|
|
||||||
int destroy(){
|
int destroy(){
|
||||||
MTGCardInstance * _target = (MTGCardInstance *)target;
|
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||||
list<int>::iterator it;
|
list<int>::iterator it;
|
||||||
for ( it=types.begin() ; it != types.end(); it++ ){
|
for ( it=types.begin() ; it != types.end(); it++ ){_target->removeType(*it);}
|
||||||
_target->removeType(*it);
|
for ( it=colors.begin() ; it != colors.end(); it++ ){_target->removeColor(*it);}
|
||||||
}
|
for ( it=oldcolors.begin() ; it != oldcolors.end(); it++ ){_target->setColor(*it);}
|
||||||
for ( it=colors.begin() ; it != colors.end(); it++ ){
|
for ( it=abilities.begin() ; it != abilities.end(); it++ ){_target->basicAbilities[*it]--;}
|
||||||
_target->removeColor(*it);
|
return 1;}
|
||||||
}
|
ATransformer * clone() const{
|
||||||
for ( it=abilities.begin() ; it != abilities.end(); it++ ){
|
|
||||||
_target->basicAbilities[*it]--;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ATransformer * clone() const{
|
|
||||||
ATransformer * a = NEW ATransformer(*this);
|
ATransformer * a = NEW ATransformer(*this);
|
||||||
a->isClone = 1;
|
a->isClone = 1;
|
||||||
return a;
|
return a;}
|
||||||
|
~ATransformer(){}
|
||||||
|
};
|
||||||
|
//Adds types/abilities/P/T to a card (until end of turn)
|
||||||
|
class ATransformerUEOT: public InstantAbility{
|
||||||
|
public:
|
||||||
|
ATransformer * ability;
|
||||||
|
ATransformerUEOT(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities):InstantAbility(id,source,target){
|
||||||
|
ability = NEW ATransformer(id,source,target,types,abilities);}
|
||||||
|
int resolve(){
|
||||||
|
ATransformer * a = ability->clone();
|
||||||
|
GenericInstantAbility * wrapper = NEW GenericInstantAbility(1,source,(Damageable *)(this->target),a);
|
||||||
|
wrapper->addToGame();
|
||||||
|
return 1;}
|
||||||
|
ATransformerUEOT * clone() const{
|
||||||
|
ATransformerUEOT * a = NEW ATransformerUEOT(*this);
|
||||||
|
a->ability = this->ability->clone();
|
||||||
|
a->isClone = 1;
|
||||||
|
return a;}
|
||||||
|
~ATransformerUEOT(){
|
||||||
|
delete ability;
|
||||||
|
}};
|
||||||
|
//transforms forever
|
||||||
|
class ATransformerFOREVER:public MTGAbility{
|
||||||
|
public:
|
||||||
|
list<int>abilities;
|
||||||
|
list<int>types;
|
||||||
|
list<int>colors;
|
||||||
|
ATransformerFOREVER(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities):MTGAbility(id,source,target){
|
||||||
|
//TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class;
|
||||||
|
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++){
|
||||||
|
size_t found = sabilities.find(Constants::MTGBasicAbilities[j]);
|
||||||
|
if (found != string::npos){
|
||||||
|
abilities.push_back(j);}
|
||||||
|
}
|
||||||
|
for (int j = 0; j < Constants::MTG_NB_COLORS; j++){
|
||||||
|
size_t found = sabilities.find(Constants::MTGColorStrings[j]);
|
||||||
|
if (found != string::npos){
|
||||||
|
colors.push_back(j);}
|
||||||
|
}
|
||||||
|
string s = stypes;
|
||||||
|
while (s.size()){
|
||||||
|
size_t found = s.find(" ");
|
||||||
|
if (found != string::npos){
|
||||||
|
int id = Subtypes::subtypesList->find(s.substr(0,found));
|
||||||
|
types.push_back(id);
|
||||||
|
s = s.substr(found+1);
|
||||||
|
}else{
|
||||||
|
int id = Subtypes::subtypesList->find(s);
|
||||||
|
types.push_back(id);
|
||||||
|
s = "";}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
int addToGame(){
|
||||||
~ATransformer(){
|
MTGCardInstance * _target = (MTGCardInstance *)target;
|
||||||
}
|
list<int>::iterator it;
|
||||||
|
for ( it=types.begin() ; it != types.end(); it++ ){_target->addType(*it);}
|
||||||
|
for ( it=colors.begin() ; it != colors.end(); it++ ){_target->setColor(*it,1);}
|
||||||
|
for ( it=abilities.begin() ; it != abilities.end(); it++ ){_target->basicAbilities[*it]++;}
|
||||||
|
return MTGAbility::addToGame();}
|
||||||
|
ATransformerFOREVER * clone() const{
|
||||||
|
ATransformerFOREVER * a = NEW ATransformerFOREVER(*this);
|
||||||
|
a->isClone = 1;
|
||||||
|
return a;}
|
||||||
|
~ATransformerFOREVER(){}
|
||||||
};
|
};
|
||||||
//Adds types/abilities/P/T to a card (aura)
|
//Adds types/abilities/P/T to a card (aura)
|
||||||
class ABecomes:public MTGAbility{
|
class ABecomes:public MTGAbility{
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ class AbilityFactory{
|
|||||||
Counter * parseCounter(string s, MTGCardInstance * target, Spell * spell = NULL);
|
Counter * parseCounter(string s, MTGCardInstance * target, Spell * spell = NULL);
|
||||||
int parsePowerToughness(string s, int *power, int *toughness);
|
int parsePowerToughness(string s, int *power, int *toughness);
|
||||||
int getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCardInstance * card = NULL, int id = 0,MTGGameZone * dest = NULL);
|
int getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCardInstance * card = NULL, int id = 0,MTGGameZone * dest = NULL);
|
||||||
MTGAbility * parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated = 0, int forceUEOT = 0,int oneShot = 0, MTGGameZone * dest = NULL);
|
MTGAbility * parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated = 0, int forceUEOT = 0,int oneShot = 0,int forceForever = 0, MTGGameZone * dest = NULL);
|
||||||
int abilityEfficiency(MTGAbility * a, Player * p, int mode = MODE_ABILITY, TargetChooser * tc = NULL);
|
int abilityEfficiency(MTGAbility * a, Player * p, int mode = MODE_ABILITY, TargetChooser * tc = NULL);
|
||||||
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL, MTGGameZone * dest = NULL);
|
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL, MTGGameZone * dest = NULL);
|
||||||
static int computeX(Spell * spell, MTGCardInstance * card);
|
static int computeX(Spell * spell, MTGCardInstance * card);
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ MTGAbility * AbilityFactory::getCoreAbility(MTGAbility * a){
|
|||||||
//Parses a string and returns the corresponding MTGAbility object
|
//Parses a string and returns the corresponding MTGAbility object
|
||||||
//Returns NULL if parsing failed
|
//Returns NULL if parsing failed
|
||||||
//Beware, Spell CAN be null when the function is called by the AI trying to analyze the effects of a given card
|
//Beware, Spell CAN be null when the function is called by the AI trying to analyze the effects of a given card
|
||||||
MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated, int forceUEOT, int oneShot, MTGGameZone * dest){
|
MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated, int forceUEOT, int oneShot,int forceFOREVER, MTGGameZone * dest){
|
||||||
size_t found;
|
size_t found;
|
||||||
|
|
||||||
string whitespaces (" \t\f\v\n\r");
|
string whitespaces (" \t\f\v\n\r");
|
||||||
@@ -722,6 +722,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (found!= string::npos) forceUEOT = 1;
|
if (found!= string::npos) forceUEOT = 1;
|
||||||
found = s.find("oneshot");
|
found = s.find("oneshot");
|
||||||
if (found!= string::npos) oneShot = 1;
|
if (found!= string::npos) oneShot = 1;
|
||||||
|
found = s.find("forever");
|
||||||
|
if (found!= string::npos) forceFOREVER = 1;
|
||||||
|
|
||||||
//PreventCombat Damage
|
//PreventCombat Damage
|
||||||
found = s.find("preventallcombatdamage");
|
found = s.find("preventallcombatdamage");
|
||||||
@@ -939,10 +941,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Becomes... (animate artifact...: becomes(Creature, manacost/manacost)
|
//Becomes... (animate artifact...: becomes(Creature, manacost/manacost)
|
||||||
found = s.find("becomes(");
|
found = s.find("becomes(");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
@@ -983,9 +981,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
||||||
else{amount = atoi(s.substr(start+1).c_str());}
|
else{amount = atoi(s.substr(start+1).c_str());}
|
||||||
MTGAbility * a = NEW AManaRedux(id,card,target,amount,0);
|
MTGAbility * a = NEW AManaRedux(id,card,target,amount,0);
|
||||||
return a;
|
return a;}
|
||||||
}
|
|
||||||
//ManaRedux
|
|
||||||
found = s.find("green:");
|
found = s.find("green:");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
size_t start = s.find(":",found);
|
size_t start = s.find(":",found);
|
||||||
@@ -994,9 +990,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
||||||
else{amount = atoi(s.substr(start+1).c_str());}
|
else{amount = atoi(s.substr(start+1).c_str());}
|
||||||
MTGAbility * a = NEW AManaRedux(id,card,target,amount,1);
|
MTGAbility * a = NEW AManaRedux(id,card,target,amount,1);
|
||||||
return a;
|
return a;}
|
||||||
}
|
|
||||||
//ManaRedux
|
|
||||||
found = s.find("blue:");
|
found = s.find("blue:");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
size_t start = s.find(":",found);
|
size_t start = s.find(":",found);
|
||||||
@@ -1005,9 +999,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
||||||
else{amount = atoi(s.substr(start+1).c_str());}
|
else{amount = atoi(s.substr(start+1).c_str());}
|
||||||
MTGAbility * a = NEW AManaRedux(id,card,target,amount,2);
|
MTGAbility * a = NEW AManaRedux(id,card,target,amount,2);
|
||||||
return a;
|
return a;}
|
||||||
}
|
|
||||||
//ManaRedux
|
|
||||||
found = s.find("red:");
|
found = s.find("red:");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
size_t start = s.find(":",found);
|
size_t start = s.find(":",found);
|
||||||
@@ -1016,9 +1008,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
||||||
else{amount = atoi(s.substr(start+1).c_str());}
|
else{amount = atoi(s.substr(start+1).c_str());}
|
||||||
MTGAbility * a = NEW AManaRedux(id,card,target,amount,3);
|
MTGAbility * a = NEW AManaRedux(id,card,target,amount,3);
|
||||||
return a;
|
return a;}
|
||||||
}
|
|
||||||
//ManaRedux
|
|
||||||
found = s.find("black:");
|
found = s.find("black:");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
size_t start = s.find(":",found);
|
size_t start = s.find(":",found);
|
||||||
@@ -1027,9 +1017,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
if (end != string::npos){amount = atoi(s.substr(start+1,end-start-1).c_str());}
|
||||||
else{amount = atoi(s.substr(start+1).c_str());}
|
else{amount = atoi(s.substr(start+1).c_str());}
|
||||||
MTGAbility * a = NEW AManaRedux(id,card,target,amount,4);
|
MTGAbility * a = NEW AManaRedux(id,card,target,amount,4);
|
||||||
return a;
|
return a;}
|
||||||
}
|
|
||||||
//ManaRedux
|
|
||||||
found = s.find("white:");
|
found = s.find("white:");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
size_t start = s.find(":",found);
|
size_t start = s.find(":",found);
|
||||||
@@ -1040,23 +1028,12 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
MTGAbility * a = NEW AManaRedux(id,card,target,amount,5);
|
MTGAbility * a = NEW AManaRedux(id,card,target,amount,5);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
//resetcost dirty code
|
||||||
//resetcost
|
|
||||||
found = s.find("resetcost");
|
found = s.find("resetcost");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
MTGAbility * a = NEW AResetCost(id,card,target);
|
MTGAbility * a = NEW AResetCost(id,card,target);
|
||||||
return a;}
|
return a;
|
||||||
////one less mana
|
}
|
||||||
// found = s.find("oneless");
|
|
||||||
// if (found != string::npos){
|
|
||||||
//MTGAbility * a = NEW AOneless(id,card,target);
|
|
||||||
// return a;}
|
|
||||||
////more more mana
|
|
||||||
// found = s.find("onemore");
|
|
||||||
// if (found != string::npos){
|
|
||||||
//MTGAbility * a = NEW AOnemore(id,card,target);
|
|
||||||
// return a;}
|
|
||||||
|
|
||||||
//transform....(hivestone,living enchantment)
|
//transform....(hivestone,living enchantment)
|
||||||
found = s.find("transforms(");
|
found = s.find("transforms(");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
@@ -1079,10 +1056,12 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
}
|
}
|
||||||
MTGAbility * ab;
|
MTGAbility * ab;
|
||||||
if (forceUEOT){
|
if (forceUEOT){
|
||||||
ab = NEW ATransformer(id,card,target,stypes,sabilities);
|
ab = NEW ATransformerUEOT(id,card,target,stypes,sabilities);
|
||||||
}else{
|
}else{
|
||||||
ab = NEW ATransformer(id,card,target,stypes,sabilities);
|
ab = NEW ATransformer(id,card,target,stypes,sabilities);
|
||||||
}return ab;
|
}if(forceFOREVER){ab = NEW ATransformerFOREVER(id,card,target,stypes,sabilities);
|
||||||
|
}
|
||||||
|
return ab;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Change Power/Toughness
|
//Change Power/Toughness
|
||||||
@@ -1325,7 +1304,7 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
|
|||||||
magicText = "";
|
magicText = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
MTGAbility * a = parseMagicLine(line, result, spell, card,0,0,0,dest);
|
MTGAbility * a = parseMagicLine(line, result, spell, card,0,0,0,0,dest);
|
||||||
if (a){
|
if (a){
|
||||||
v->push_back(a);
|
v->push_back(a);
|
||||||
result++;
|
result++;
|
||||||
|
|||||||
Reference in New Issue
Block a user