Fixed issue #1054 (opened by @ranger7271), fixed/added primitives with "scry" ability, improved scry ability for both Human and AI player, added a new ability to replace the scry ability with some actions (e.g. Eligeth, Crossroads Augur).

This commit is contained in:
Vittorio Alfieri
2021-02-08 17:08:20 +01:00
parent a858ed405f
commit eb8da4d4b2
13 changed files with 320 additions and 289 deletions
+12 -2
View File
@@ -652,16 +652,26 @@ int OrderedAIAction::getEfficiency()
if(grA->source->getAICustomCode().size() && grA->source->alias != 185709)//Sphinx of Jwar Isle so the ai will ignore it
{
//efficiency = 45 + (owner->getRandomGenerator()->random() % 50);
AbilityFactory af(g);
MTGAbility * parsedAICC = af.parseMagicLine(cReplaceString(grA->source->getAICustomCode(),"activate",""),0,NULL,grA->source);
efficiency = getRevealedEfficiency(parsedAICC);
SAFE_DELETE(parsedAICC);
}
else // this is why the AI never chooses any card at all? reveal is used to get cards so it should be at better value
efficiency = 60;
}
else if (GenericScryAbility * grA = dynamic_cast<GenericScryAbility *>(a))
{
if(grA->source->getAICustomCode().size())
{
AbilityFactory af(g);
MTGAbility * parsedAICC = af.parseMagicLine(cReplaceString(grA->source->getAICustomCode(),"activate",""),0,NULL,grA->source);
efficiency = getRevealedEfficiency(parsedAICC);
SAFE_DELETE(parsedAICC);
}
else // this is why the AI never chooses any card at all? scry is used to get cards so it should be at better value
efficiency = 60;
}
//At this point the "basic" efficiency is computed, we further tweak it depending on general decisions, independent of theAbility type
MayAbility * may = dynamic_cast<MayAbility*>(ability);
+56 -25
View File
@@ -56,15 +56,15 @@ int GenericRevealAbility::resolve()
{
if(source->lastController->isAI() && source->getAICustomCode().size())
{
string abi = source->getAICustomCode();
std::transform(abi.begin(), abi.end(), abi.begin(), ::tolower);//fix crash
AbilityFactory af(game);
MTGAbility * a3 = af.parseMagicLine(abi, this->GetId(), NULL, source);
a3->oneShot = 1;
a3->canBeInterrupted = false;
a3->resolve();
SAFE_DELETE(a3);
return 1;
string abi = source->getAICustomCode();
std::transform(abi.begin(), abi.end(), abi.begin(), ::tolower);//fix crash
AbilityFactory af(game);
MTGAbility * a3 = af.parseMagicLine(abi, this->GetId(), NULL, source);
a3->oneShot = 1;
a3->canBeInterrupted = false;
a3->resolve();
SAFE_DELETE(a3);
return 1;
}
MTGAbility * ability = NEW MTGRevealingCards(game, this->GetId(), source, howMany);
ability->addToGame();
@@ -580,7 +580,7 @@ MTGScryCards::MTGScryCards(GameObserver* observer, int _id, MTGCardInstance * ca
delayed = coreAbility.find("delayed") != string::npos;
dontRevealAfter = coreAbility.find("dontshow") != string::npos;
if(dontRevealAfter)
revealTopAmount = 0;
revealTopAmount = 0;
vector<string>second = parseBetween(coreAbility, "scrycore ", " scrycoreend");
if (second.size())
{
@@ -757,12 +757,23 @@ bool MTGScryCards::CheckUserInput(JButton key)
source->getObserver()->mLayers->stackLayer()->Remove(abilityFirst);
game->removeObserver(abilityFirst);
if (!this->source->controller()->isAI())
game->Update(0);
game->Update(0);
if (zone->cards.size())
{
initDisplay(revealTopAmount);
abilitySecond = contructAbility(abilityTwo);
game->addObserver(abilitySecond);
if (revealTopAmount == 0 && dontRevealAfter && delayed) // Execute delayed action even if dontshow option is active.
{
MTGAbility * delayedA = contructAbility(delayedAbilityString);
if (delayedA->oneShot)
{
delayedA->resolve();
SAFE_DELETE(delayedA);
}
else
delayedA->addToGame();
}
}
}
else if (tc->source)
@@ -784,7 +795,7 @@ bool MTGScryCards::CheckUserInput(JButton key)
source->getObserver()->mLayers->stackLayer()->Remove(abilityFirst);
game->removeObserver(abilityFirst);
if (!this->source->controller()->isAI())
game->Update(1);
game->Update(1);
if (zone->cards.size() || (revealDisplay && !zone->cards.size()))
{
@@ -792,19 +803,17 @@ bool MTGScryCards::CheckUserInput(JButton key)
abilitySecond = contructAbility(abilityTwo);
game->addObserver(abilitySecond);
if(revealTopAmount == 0 && dontRevealAfter && delayed)
{
MTGAbility * delayedA = contructAbility(delayedAbilityString);
if (delayedA->oneShot)
{
MTGAbility * delayedA = contructAbility(delayedAbilityString);
if (delayedA->oneShot)
{
delayedA->resolve();
SAFE_DELETE(delayedA);
}
else
delayedA->addToGame();
delayedA->resolve();
SAFE_DELETE(delayedA);
}
else
delayedA->addToGame();
}
}
}
if (!tc && abilitySecond && abilitySecond->testDestroy())
{
@@ -833,7 +842,6 @@ bool MTGScryCards::CheckUserInput(JButton key)
}
else
delayedA->addToGame();
}
}
}
@@ -890,8 +898,31 @@ GenericScryAbility::GenericScryAbility(GameObserver* observer, int id, MTGCardIn
int GenericScryAbility::resolve()
{
MTGAbility * ability = NEW MTGScryCards(game, this->GetId(), source, howMany);
ability->addToGame();
bool replaceScry = false;
for(int i = 0; i < source->lastController->game->battlefield->nb_cards; i ++){
if(source->lastController->game->battlefield->cards[i]->has(Constants::REPLACESCRY))
replaceScry = true;
}
if(!replaceScry && source->lastController->isAI() && source->getAICustomCode().size())
{
string abi = source->getAICustomCode();
std::transform(abi.begin(), abi.end(), abi.begin(), ::tolower);//fix crash
AbilityFactory af(game);
MTGAbility * a3 = af.parseMagicLine(abi, this->GetId(), NULL, source);
a3->oneShot = 1;
a3->canBeInterrupted = false;
a3->resolve();
SAFE_DELETE(a3);
} else if(!replaceScry) {
MTGAbility * ability = NEW MTGScryCards(game, this->GetId(), source, howMany);
ability->addToGame();
}
string number = "0";
vector<string> amount = parseBetween(howMany, "", " ");
if (amount.size())
number = amount[1];
WParsedInt nbCardP(number, NULL, source);
source->scryedCards = nbCardP.getValue();
WEvent * e = NEW WEventCardScryed(source);
game->receiveEvent(e);
return 1;
+4 -3
View File
@@ -852,10 +852,9 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card, Player * playe
{
vector<string>getPaid = parseBetween(restriction[i].c_str(),"paid(",")");
string paid = getPaid[1];
for (size_t j = 0; j < sizeof(kAlternateCostIds)/sizeof(kAlternateCostIds[0]); ++j)
{
string keyword = kAlternateCostKeywords[j];
string keyword = kAlternateCostKeywords[j];
if (paid.find(keyword) != string::npos)
{
if (!(card->alternateCostPaid[j] > 0 ))
@@ -864,8 +863,10 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card, Player * playe
}
}
}
}
check = restriction[i].find("never");
if(check != string::npos)
return 0;
}
return 1;
}
+1
View File
@@ -266,6 +266,7 @@ void MTGCardInstance::initMTGCI()
lastFlipResult = -1;
dieSide = 0;
lastRollResult = 0;
scryedCards = 0;
isAttacking = NULL;
storedCard = NULL;
storedSourceCard = NULL;
+2 -1
View File
@@ -208,7 +208,8 @@ const char* Constants::MTGBasicAbilities[] = {
"foretell", //It has foretell cost
"anytypeofmanaability", //It allows to spend mana as it were of any color to activate abilities.
"boast", //It has boast ability
"twoboast" //It has boast twice ability (e.g. Birgi, God of Storytelling)
"twoboast", //It has boast twice ability (e.g. Birgi, God of Storytelling)
"replacescry" //It has scry replacement ability
};
map<string,int> Constants::MTGBasicAbilitiesMap;
+4
View File
@@ -1001,6 +1001,10 @@ void WParsedInt::init(string s, Spell * spell, MTGCardInstance * card)
else
intValue = card->revealedLast->getManaCost()->getConvertedCost();
}
else if (s == "scryedcards")//returns how many card have been scryed from current card
{
intValue = card->scryedCards;
}
else if(!intValue)//found nothing, try parsing a atoi
{
intValue = atoi(s.c_str());