diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 2c5df1adf..9a647c920 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -1191,7 +1191,8 @@ public: ABasicAbilityModifier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int _modifier = 1) : MTGAbility(_id, _source, _target), modifier(_modifier), ability(_ability) { - + aType = MTGAbility::STANDARDABILITYGRANT; + abilitygranted = ability; } int addToGame() @@ -1249,6 +1250,8 @@ public: int _modifier = 1, int _tap = 1) : TargetAbility(_id, _source, _cost, 0, _tap), modifier(_modifier), ability(_ability) { + aType = MTGAbility::STANDARDABILITYGRANT; + abilitygranted = ability; nbTargets = 0; tc = _tc; if (!tc) tc = NEW CreatureTargetChooser(_source); @@ -1321,7 +1324,8 @@ public: AInstantBasicAbilityModifierUntilEOT(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int value) : InstantAbility(_id, _source, _target), ability(_ability), value(value) { - + aType = MTGAbility::STANDARDABILITYGRANT; + abilitygranted = ability; } int addToGame() @@ -1370,6 +1374,7 @@ public: { target = _target; ability = NEW AInstantBasicAbilityModifierUntilEOT(_id, _source, _target, _ability, _value); + aType = MTGAbility::STANDARDABILITYGRANT; } int isReactingToClick(MTGCardInstance * card, ManaCost * cost = NULL) @@ -1423,6 +1428,7 @@ public: ASpellCastLife(int id, MTGCardInstance * _source, CardDescriptor _trigger, ManaCost * _cost, int _life) : MTGAbility(id, _source), trigger(_trigger), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) { + aType = MTGAbility::LIFER; } ASpellCastLife(int id, MTGCardInstance * _source, int color, ManaCost * _cost, int _life) : MTGAbility(id, _source), cost(_cost), life(_life), lastUsedOn(NULL), lastChecked(NULL) diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index ecad92e36..c4c8618a4 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -57,6 +57,7 @@ class MTGAbility: public ActionElement{ Targetable * target; int aType; int naType; + int abilitygranted; int nbcardAmount; MTGCardInstance * source; MTGAbility(int id, MTGCardInstance * card); @@ -100,6 +101,10 @@ class MTGAbility: public ActionElement{ STANDARD_PUMP = 18, STANDARD_BECOMES = 19, UPCOST = 20, + STANDARDABILITYGRANT = 21, + UNTAPPER = 22, + TAPPER = 23, + LIFER = 24, }; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 8917d1a30..8d197d949 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -150,7 +150,8 @@ ManaCost * AIPlayer::getPotentialMana(MTGCardInstance * target) used[card] = true; } } - } + } + result->add(this->getManaPool()); return result; } @@ -382,21 +383,18 @@ int AIAction::getEfficiency() MTGCardInstance * _target = (MTGCardInstance *) (a->target); MTGAbility * a = AbilityFactory::getCoreAbility(ability); AManaProducer * amp = dynamic_cast (a); + efficiency = 0; //trying to encourage Ai to use his foreach manaproducers in first main if (a->naType == MTGAbility::MANA_PRODUCER && (g->getCurrentGamePhase() == Constants::MTG_PHASE_FIRSTMAIN || g->getCurrentGamePhase() == Constants::MTG_PHASE_SECONDMAIN ) && _target->controller()->game->hand->nb_cards > 0) { for (int i = Constants::MTG_NB_COLORS - 1; i > 0; i--) { - if((p->game->hand->hasColor(i) || p->game->hand->hasColor(0) ) + if((p->game->hand->hasColor(i) || p->game->hand->hasColor(0)) && (dynamic_cast(( dynamic_cast( a )->ability))->output->hasColor(i))) { efficiency = 100; } - else - { - efficiency = 0; - } } if(p->game->hand->hasX()) { @@ -426,7 +424,70 @@ int AIAction::getEfficiency() } break; } - case MTGAbility::MANA_PRODUCER: //can't use mana producers right now :/ + case MTGAbility::STANDARDABILITYGRANT: + { + efficiency = 0; + MTGCardInstance * _target = (MTGCardInstance *) (a->target); + //ensuring that Ai grants abilities to creatures during first main, so it can actually use them in combat. + if (_target && !_target->has(a->abilitygranted) && g->getCurrentGamePhase() == Constants::MTG_PHASE_FIRSTMAIN) + { + //trying to avoid Ai giving ie:flying creatures ie:flying twice. + efficiency = (20 * _target->DangerRanking()); + } + if (target) + { + AbilityFactory af; + int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); + + if ((suggestion == BAKA_EFFECT_BAD && p == target->controller()) || (suggestion == BAKA_EFFECT_GOOD && p + != target->controller())) + { + efficiency = 0; + //stop giving trample to the players creatures. + } + if (suggestion == BAKA_EFFECT_BAD && p != target->controller() && target->has(a->abilitygranted)) + { + efficiency = (20 * _target->DangerRanking()); + } + } + break; + } + case MTGAbility::UNTAPPER: + //untap things that Ai owns and are tapped. + { + efficiency = 0; + MTGCardInstance * _target = (MTGCardInstance *) (a->target); + if (_target && _target->isTapped() && p->isAI() && p == _target->controller()) + { + efficiency = 100; + } + break; + } + case MTGAbility::TAPPER: + //tap things the player owns and that are untapped. + { + efficiency = 0; + MTGCardInstance * _target = (MTGCardInstance *) (a->target); + if (_target && !_target->isTapped() && p != _target->controller()) + { + efficiency = 100; + } + break; + } + case MTGAbility::LIFER: + { + //use life abilities whenever possible. + efficiency = 100; + AbilityFactory af; + int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); + if ((suggestion == BAKA_EFFECT_BAD && p == a->target) || (suggestion == BAKA_EFFECT_GOOD && p + != a->target)) + { + efficiency = 0; + } + break; + } + case MTGAbility::MANA_PRODUCER: efficiency = 0; break; default: diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 5ecf77ff9..1fc8fabff 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -550,6 +550,7 @@ AAFrozen * AAFrozen::clone() const AALifer::AALifer(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * life, ManaCost * _cost, int _tap, int who) : ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), life(life) { + aType = MTGAbility::LIFER; } int AALifer::resolve() @@ -990,6 +991,7 @@ AATapper::AATapper(int id, MTGCardInstance * card, MTGCardInstance * _target, Ma ActivatedAbility(id, card, _cost, 0, doTap) { target = _target; + aType = MTGAbility::TAPPER; } int AATapper::resolve() @@ -1021,6 +1023,7 @@ AAUntapper::AAUntapper(int id, MTGCardInstance * card, MTGCardInstance * _target ActivatedAbility(id, card, _cost, 0, doTap) { target = _target; + aType = MTGAbility::UNTAPPER; } int AAUntapper::resolve() diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 0f419a75a..b1fa27a07 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -542,7 +542,7 @@ int MTGGameZone::hasColor(int value) { for (int i = 0; i < (nb_cards); i++) { - if (cards[i]->getManaCost()->hasColor(value)) + if (cards[i]->getManaCost()->hasColor(value) && cards[i]->getManaCost()->getConvertedCost() > 0) { return 1; }