refactored the typemin: cast restriction, there was a reported bug with it and while debugging it screamed refactor.
so i converted it from string comparisons and counting the battlefield..into targetchoosers with declarable operator. simplified the code from the mess it was before into something alot easier to card code with. example before: mytypemin:less type(land),opponenttypemin:* type(land) becomes type(land|mybattlefield)~lessthan~type(land|opponentbattlefield) the new syntax is: type(targetchooser)~operator~number type(targetchooser)~operator~type(targetchooser) the operator are: morethan lessthan equalto
This commit is contained in:
@@ -43,6 +43,7 @@ public:
|
|||||||
|
|
||||||
int maxtargets; //Set to -1 for "unlimited"
|
int maxtargets; //Set to -1 for "unlimited"
|
||||||
bool validTargetsExist();
|
bool validTargetsExist();
|
||||||
|
int countValidTargets();
|
||||||
virtual int setAllZones()
|
virtual int setAllZones()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -105,68 +105,51 @@ int MTGAbility::parseCastRestrictions(MTGCardInstance * card,Player * player,str
|
|||||||
if (cPhase != checkPhaseBased - BEFORE_BEGIN + Constants::MTG_PHASE_BEFORE_BEGIN)
|
if (cPhase != checkPhaseBased - BEFORE_BEGIN + Constants::MTG_PHASE_BEFORE_BEGIN)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t typeRelated = restriction[i].find("typemin:");
|
|
||||||
|
size_t typeRelated = restriction[i].find("type(");
|
||||||
size_t check = NULL;
|
size_t check = NULL;
|
||||||
if(typeRelated != string::npos)
|
if(typeRelated != string::npos)
|
||||||
{
|
{
|
||||||
bool less = false;
|
int firstAmount = 0;
|
||||||
bool more = false;
|
int secondAmount = 0;
|
||||||
int mytypemin = 0;
|
string type;
|
||||||
int opponenttypemin = 0;
|
vector<string> comparasion = split(restriction[i],'~');
|
||||||
int min = 0;
|
if(comparasion.size() != 3)
|
||||||
int opponentmin = 0;
|
return 0;//it was incorrectly coded, user should proofread card code.
|
||||||
string type = "*";
|
bool less = comparasion[1].find("lessthan") != string::npos;
|
||||||
string opponenttype = "*";
|
bool more = comparasion[1].find("morethan") != string::npos;
|
||||||
|
bool equal = comparasion[1].find("equalto") != string::npos;
|
||||||
check = restriction[i].find("mytypemin:");
|
for(unsigned int i = 0; i < comparasion.size(); i++)
|
||||||
if( check != string::npos)
|
|
||||||
{
|
{
|
||||||
size_t start = restriction[i].find(":", check);
|
check = comparasion[i].find("type(");
|
||||||
size_t end = restriction[i].find(" ", check);
|
if( check != string::npos)
|
||||||
size_t lesser = restriction[i].find(":less",check);
|
|
||||||
size_t morer = restriction[i].find(":more",check);
|
|
||||||
if(lesser != string::npos)
|
|
||||||
{
|
{
|
||||||
less = true;
|
size_t start = 0;
|
||||||
|
size_t end = 0;
|
||||||
|
size_t found = comparasion[i].find("type(");
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
end = comparasion[i].find(")", found);
|
||||||
|
type = comparasion[i].substr(found + 5, end - found - 5).c_str();
|
||||||
|
TargetChooserFactory tcf;
|
||||||
|
TargetChooser * ttc = tcf.createTargetChooser(type,card);
|
||||||
|
if(i == 2)
|
||||||
|
secondAmount = ttc->countValidTargets();
|
||||||
|
else
|
||||||
|
firstAmount = ttc->countValidTargets();
|
||||||
|
SAFE_DELETE(ttc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(morer != string::npos)
|
else if (i == 2)
|
||||||
{
|
secondAmount = atoi(comparasion[2].c_str());
|
||||||
more = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
min = atoi(restriction[i].substr(start + 1, end - start - 1).c_str());
|
|
||||||
}
|
|
||||||
size_t found = restriction[i].find("type(");
|
|
||||||
if (found != string::npos)
|
|
||||||
{
|
|
||||||
end = restriction[i].find(")", found);
|
|
||||||
type = restriction[i].substr(found + 5, end - found - 5).c_str();
|
|
||||||
}
|
|
||||||
mytypemin = card->controller()->game->inPlay->countByType(type.c_str());
|
|
||||||
if(mytypemin < min && less == false && more == false)
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
check = restriction[i].find("opponenttypemin:");
|
if(firstAmount < secondAmount && !less && !more && !equal)
|
||||||
if( check != string::npos)
|
|
||||||
{
|
|
||||||
size_t start = restriction[i].find(":", check);
|
|
||||||
size_t end = restriction[i].find(" ", check);
|
|
||||||
opponentmin = atoi(restriction[i].substr(start + 1, end - start - 1).c_str());
|
|
||||||
|
|
||||||
size_t found = restriction[i].find("opponenttype(");
|
|
||||||
if (found != string::npos)
|
|
||||||
{
|
|
||||||
end = restriction[i].find(")", found);
|
|
||||||
opponenttype = restriction[i].substr(found + 13, end - found - 13).c_str();
|
|
||||||
}
|
|
||||||
opponenttypemin = card->controller()->opponent()->game->inPlay->countByType(opponenttype.c_str());
|
|
||||||
if(opponenttypemin < opponentmin && less == false && more == false)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(less && more == false && opponenttypemin <= mytypemin)
|
|
||||||
return 0;
|
return 0;
|
||||||
if(less == false && more && opponenttypemin >= mytypemin)
|
if(equal && firstAmount != secondAmount)
|
||||||
|
return 0;
|
||||||
|
if(less && firstAmount >= secondAmount)
|
||||||
|
return 0;
|
||||||
|
if(more && firstAmount <= secondAmount)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
check = restriction[i].find("turn:");
|
check = restriction[i].find("turn:");
|
||||||
|
|||||||
@@ -832,6 +832,28 @@ bool TargetChooser::validTargetsExist()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TargetChooser::countValidTargets()
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
for (int i = 0; i < 2; ++i)
|
||||||
|
{
|
||||||
|
Player *p = GameObserver::GetInstance()->players[i];
|
||||||
|
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->exile };
|
||||||
|
for (int k = 0; k < 5; k++)
|
||||||
|
{
|
||||||
|
MTGGameZone * z = zones[k];
|
||||||
|
if (targetsZone(z))
|
||||||
|
{
|
||||||
|
for (int j = 0; j < z->nb_cards; j++)
|
||||||
|
{
|
||||||
|
if (canTarget(z->cards[j])) result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool TargetChooser::equals(TargetChooser * tc)
|
bool TargetChooser::equals(TargetChooser * tc)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user