added support for {X}{X} in cost, added support for token(creature, X/X or XX/XX)*XX or X or #. added discard card at random as cost type {d}

This commit is contained in:
omegablast2002@yahoo.com
2010-09-12 16:15:24 +00:00
parent 6063ddcf55
commit c408e5d588
11 changed files with 122 additions and 8 deletions
+7
View File
@@ -162,6 +162,13 @@ int Spell::computeX(MTGCardInstance * card){
return x;
}
int Spell::computeXX(MTGCardInstance * card){
ManaCost * c = cost->Diff(card->getManaCost());
int xx = c->getCost(Constants::MTG_NB_COLORS)/2;
delete c;
return xx;
}
bool Spell::kickerWasPaid(){
return (payResult == ManaCost::MANA_PAID_WITH_KICKER);
}
+60
View File
@@ -77,7 +77,67 @@ void LifeCost::Render(){
mFont->DrawString(buffer, 20 ,20, JGETEXT_LEFT);
}
//endlifecost
//discard a card at random as a cost
//DiscardRandom cost
DiscardRandomCost * DiscardRandomCost::clone() const{
DiscardRandomCost * ec = NEW DiscardRandomCost(*this);
if (tc) ec->tc = tc->clone();
return ec;
}
DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc):ExtraCost(_tc){
if (tc) tc->targetter = NULL;
target = NULL;
}
int DiscardRandomCost::setSource(MTGCardInstance * card){
ExtraCost::setSource(card);
if (tc) tc->targetter = NULL;
if (!tc) target = card;
return 1;
}
int DiscardRandomCost::setPayment(MTGCardInstance * card){
if (tc) {
int result = tc->addTarget(card);
if (result) {
target = card;
return result;
}
}
return 0;
}
int DiscardRandomCost::isPaymentSet(){
if (target) return 1;
return 0;
}
int DiscardRandomCost::canPay(){
MTGGameZone * z = target->controller()->game->hand;
int nbcards = z->nb_cards;
if(nbcards < 1) return 0;
return 1;
}
int DiscardRandomCost::doPay(){
MTGCardInstance * _target = (MTGCardInstance *) target;
if(target){
_target->controller()->game->discardRandom(_target->controller()->game->hand);
target = NULL;
if (tc) tc->initTargets();
return 1;
}
return 0;
}
void DiscardRandomCost::Render(){
//TODO : real stuff
WFont * mFont = resources.GetWFont(Constants::MAIN_FONT);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
mFont->SetColor(ARGB(255,255,255,255));
char buffer[200];
sprintf(buffer, "%s", _("Discard Random").c_str());
mFont->DrawString(buffer, 20 ,20, JGETEXT_LEFT);
}
//discardrandomcost
//Tap target cost
TapTargetCost * TapTargetCost::clone() const{
TapTargetCost * ec = NEW TapTargetCost(*this);
+11 -3
View File
@@ -653,7 +653,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
WParsedInt * multiplier = NULL;
size_t star = s.find("*");
if (star != string::npos) multiplier = NEW WParsedInt(s.substr(star+1),spell,card);
size_t end = s.find(")", found);
int tokenId = atoi(s.substr(found + 6,end - found - 6).c_str());
if (tokenId){
@@ -670,11 +669,14 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
previous = end+1;
end = s.find(",",previous);
string spt = s.substr(previous,end - previous);
int value = 0;
int power, toughness;
parsePowerToughness(spt,&power, &toughness);
if(!spt.find("X/X") || !spt.find("x/x")){value = spell->computeX(card);}
if(!spt.find("XX/XX") || !spt.find("xx/xx")){value = spell->computeXX(card);}
parsePowerToughness(spt,&power, &toughness);
string sabilities = s.substr(end+1);
ATokenCreator * tok = NEW ATokenCreator(id,card,NULL,sname,stypes,power,toughness,sabilities,0, multiplier);
ATokenCreator * tok = NEW ATokenCreator(id,card,NULL,sname,stypes,power + value,toughness + value,sabilities,0, multiplier);
tok->oneShot = 1;
return tok;
}
@@ -1374,6 +1376,12 @@ int AbilityFactory::computeX(Spell * spell, MTGCardInstance * card){
return 0;
}
//Returns the "XX" cost that was paid for a spell
int AbilityFactory::computeXX(Spell * spell, MTGCardInstance * card){
if (spell) return spell->computeXX(card);
return 0;
}
int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCardInstance * card, int id, MTGGameZone * dest){
+1
View File
@@ -85,6 +85,7 @@ int MTGCardInstance::init(){
CardPrimitive::init();
data = this;
X = 0;
XX = 0;
return 1;
}
+6 -2
View File
@@ -107,7 +107,8 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){
}
}//end of storm
if(!card->has(Constants::STORM)){
copy->X = spell->computeX(copy);
copy->X = spell->computeX(copy);
copy->XX = spell->computeXX(copy);
}
}
@@ -236,7 +237,8 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card){
}
}//end of storm
if(!card->has(Constants::STORM)){
copy->X = spell->computeX(copy);
copy->X = spell->computeX(copy);
copy->XX = spell->computeXX(copy);
}
}
@@ -368,6 +370,7 @@ int MTGBuyBackRule::reactToClick(MTGCardInstance * card){
}//end of storm
if(!card->has(Constants::STORM)){
copy->X = spell->computeX(copy);
copy->XX = spell->computeXX(copy);
}
}
@@ -495,6 +498,7 @@ int MTGFlashBackRule::reactToClick(MTGCardInstance * card){
}//end of storm
if(!card->has(Constants::STORM)){
copy->X = spell->computeX(copy);
copy->XX = spell->computeXX(copy);
}
}
+14
View File
@@ -122,6 +122,20 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan
}
manaCost->addExtraCost(NEW LifeCost(tc));
//end life cost
//DiscardRandom cost
}else if (value[0] == 'd'){
//tap
OutputDebugString("DiscardRandom\n");
TargetChooserFactory tcf;
TargetChooser * tc = NULL;
size_t target_start = value.find("(");
size_t target_end = value.find(")");
if (target_start!=string::npos && target_end!=string::npos){
string target = value.substr(target_start+1, target_end-1 - target_start);
tc = tcf.createTargetChooser(target,c);
}
manaCost->addExtraCost(NEW DiscardRandomCost(tc));
//DiscardRandom cost
}else if (value[0] == 'c'){
//Counters