diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 22613dd47..f36078bae 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -491,6 +491,7 @@ public: string name; AACounter(int id, MTGCardInstance * source, MTGCardInstance * target, const char * _name, int power, int toughness, int nb, ManaCost * cost = NULL, int doTap = 0) : ActivatedAbility(id, source, cost, 0, doTap), nb(nb), power(power), toughness(toughness), name(_name) { this->target = target; + if(name.find("Level")) aType = MTGAbility::STANDARD_LEVELUP; } @@ -1693,7 +1694,7 @@ class AEquip:public TargetAbility{ public: vector currentAbilities; AEquip(int _id, MTGCardInstance * _source, ManaCost * _cost=NULL, int doTap=0, int restrictions = ActivatedAbility::AS_SORCERY):TargetAbility(_id,_source,NULL,_cost,restrictions,doTap){ - + aType = MTGAbility::STANDARD_EQUIP; } int unequip(){ @@ -2784,7 +2785,7 @@ class AADamagePrevent:public ActivatedAbilityTP{ public: int preventing; AADamagePrevent(int _id, MTGCardInstance * _source, Targetable * _target,int preventing, ManaCost * _cost=NULL, int doTap = 0, int who = TargetChooser::UNSET):ActivatedAbilityTP(_id,_source,_target,_cost,doTap,who),preventing(preventing){ - //aType = MTGAbility::STANDARD_PREVENT; + aType = MTGAbility::STANDARD_PREVENT; } int resolve(){ diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index a50d64eb3..d879b1d5c 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -90,7 +90,9 @@ class MTGAbility: public ActionElement{ FLASHBACK_COST = 10, RETRACE_COST = 11, MTG_COMBATTRIGGERS_RULE = 12, - //STANDARD_PREVENT = 13, + STANDARD_PREVENT = 13, + STANDARD_EQUIP = 14, + STANDARD_LEVELUP = 15, }; diff --git a/projects/mtg/include/MTGCard.h b/projects/mtg/include/MTGCard.h index 0f26301a7..1949e08b9 100644 --- a/projects/mtg/include/MTGCard.h +++ b/projects/mtg/include/MTGCard.h @@ -26,7 +26,7 @@ class MTGCard { int init(); public: - + int LevelUp; int setId; CardPrimitive * data; @@ -36,11 +36,13 @@ class MTGCard { void setMTGId(int id); void setRarity(char _rarity); + void setLevelcap(int _levelupcap); //void setImageName( char * value); void setPrimitive(CardPrimitive * cp); int getMTGId() const; int getId() const; + int getLevelcap() const; char getRarity() const; char * getImageName(); }; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 0278196cd..101105d15 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -85,6 +85,8 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { int removeType(string value, int removeAll = 0); int removeType(int value, int removeAll = 0); + //dangerranking is a hint to Ai which creatures are the ones it should be targetting for effects. + int DangerRanking(); //Combat bool blocked; //Blocked this turn or not? MTGCardInstance * defenser; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 95c0f68a2..4911b40d9 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -196,20 +196,64 @@ int AIAction::getEfficiency(){ //TODO If the card is the target of a damage spell break; } - //case MTGAbility::STANDARD_PREVENT: - // { - // MTGCardInstance * _target = (MTGCardInstance *)(a->target); - // efficiency = 10;//starts out low to avoid spamming it when its not needed. - // if ((!_target->regenerateTokens && g->getCurrentGamePhase() == Constants::MTG_PHASE_COMBATBLOCKERS && (_target->defenser || _target->blockers.size())) || ((_target->canBlock()||_target->canAttack()) && _target->preventable < 2)){ - // efficiency = 95;//increase this chance to be used in combat. - // } - // if (_target->preventable > 2){ - // efficiency -= 10; //lower the chance to be used if the creature already has over 3 prevent points. - // } - // //basically a rip off of regen, if it is not regenerating, its combat blockers, it is being blocked or blocking, and has less then 3 prevents, the effeincy is increased. - // //TODO If the card is the target of a damage spell - // break; - // } + case MTGAbility::STANDARD_PREVENT: + { + MTGCardInstance * _target = (MTGCardInstance *)(a->target); + efficiency = 0;//starts out low to avoid spamming it when its not needed. + bool NeedPreventing; + NeedPreventing = false; + if(g->getCurrentGamePhase() == Constants::MTG_PHASE_COMBATBLOCKERS) + { + if((target->defenser || target->blockers.size()) && target->preventable < target->getNextOpponent()->power) NeedPreventing = true; + } + if (p == target->controller() && NeedPreventing == true && !(target->getNextOpponent()->has(Constants::DEATHTOUCH) || target->getNextOpponent()->has(Constants::WITHER))){ + efficiency = 20 * (target->DangerRanking());//increase this chance to be used in combat if the creature blocking/blocked could kill the creature this chance is taking into consideration how good the creature is, best creature will always be the first "saved".. + if(target->toughness == 1 && target->getNextOpponent()->power == 1) efficiency += 15; + //small bonus added for the poor 1/1s, if we can save them, we will unless something else took precidence. + } + //note is the target is being blocked or blocking a creature with wither or deathtouch, it is not even considered for preventing as it is a waste. + //if its combat blockers, it is being blocked or blocking, and has less prevents the the amount of damage it will be taking, the effeincy is increased slightly and totalled by the danger rank multiplier for final result. + //TODO If the card is the target of a damage spell + break; + } + case MTGAbility::STANDARD_EQUIP: + { + MTGCardInstance * _target = (MTGCardInstance *)(a->target); + efficiency = 0; + if (p == target->controller() && target->equipment <= 1 && !a->source->target) + { + efficiency = 20 * (target->DangerRanking()); + if(target->hasColor(5)) efficiency += 20;//this is to encourage Ai to equip white creatures in a weenie deck. ultimately it will depend on what had the higher dangerranking. + if(target->power == 1 && target->toughness == 1 && target->isToken == 0) efficiency += 10; //small bonus to encourage equipping nontoken 1/1 creatures. + } + if (p == target->controller() && target->equipment > 2 && !a->source->target) + { + efficiency = 15 * (target->DangerRanking()); + } + break; + } + + case MTGAbility::STANDARD_LEVELUP: + { + MTGCardInstance * _target = (MTGCardInstance *)(a->target); + efficiency = 0; + Counter * targetCounter = NULL; + int currentlevel = 0; + if(_target) + { + if(_target->counters && _target->counters->hasCounter("level",0,0)) + { + targetCounter = _target->counters->hasCounter("level",0,0); + currentlevel = targetCounter->nb; + } + } + if (currentlevel < _target->LevelUp){ + efficiency = 65; + efficiency += currentlevel;//increase the efficeincy of leveling up by a small amount equal to current level. + } + break; + } + case MTGAbility::MANA_PRODUCER: //can't use mana producers right now :/ efficiency = 0; break; @@ -232,7 +276,7 @@ int AIAction::getEfficiency(){ ExtraCosts * ec = ability->cost->extraCosts; if (ec) efficiency = efficiency / 3; //Decrease chance of using ability if there is an extra cost to use the ability } - return efficiency; + return efficiency; } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 849d27cc0..be3953fcc 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1705,7 +1705,6 @@ int AbilityFactory::computeXX(Spell * spell, MTGCardInstance * card){ return 0; } - int AbilityFactory::getAbilities(vector * v, Spell * spell, MTGCardInstance * card, int id, MTGGameZone * dest){ if (!card && spell) card = spell->source; diff --git a/projects/mtg/src/MTGCard.cpp b/projects/mtg/src/MTGCard.cpp index 31610442f..a42f67367 100644 --- a/projects/mtg/src/MTGCard.cpp +++ b/projects/mtg/src/MTGCard.cpp @@ -26,6 +26,7 @@ MTGCard::MTGCard(int set_id){ MTGCard::MTGCard(MTGCard * source){ strcpy(image_name, source->image_name); + LevelUp = source->LevelUp; rarity = source->rarity; mtgid = source->mtgid; setId = source->setId; @@ -37,6 +38,7 @@ int MTGCard::init(){ mtgid = 0; data = NULL; rarity = Constants::RARITY_C; + LevelUp = 0; return 1; } @@ -64,6 +66,14 @@ void MTGCard::setRarity(char _rarity){ rarity = _rarity; } +int MTGCard::getLevelcap() const{ + return LevelUp; +} + +void MTGCard::setLevelcap(int levelupcap){ + LevelUp = levelupcap; +} + char * MTGCard::getImageName() { return image_name; } diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index 53f5a8381..c4c027eae 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -457,6 +457,28 @@ MTGCardInstance * MTGCardInstance::getNextPartner(){ return NULL; } +int MTGCardInstance::DangerRanking(){ + int danger; + int result; +danger = 0; +result = 0; +result += power; +result += toughness; +result += getManaCost()->getConvertedCost(); + for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++){ + if(basicAbilities[j]) + { + result += 1; + } + } + if(result > 1) danger += 1; + if(result > 2) danger += 1; + if(result > 4) danger += 1; + if(result > 6) danger += 1; + if(result > 10) danger += 1; + return danger; +} + int MTGCardInstance::setAttacker(int value){ Targetable * previousTarget = NULL; Targetable * target = NULL; diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index 1043f281b..0c467ca9c 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -110,6 +110,12 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi cost->kicker = ManaCost::parseManaCost(value); } break; + + case 'l': //Levelup, this is just to give Ai an idea when to stop leveling a creature. + if(!card) card = NEW MTGCard(); + card->setLevelcap(atoi(val)); + break; + case 'o': //othercost if (!primitive) primitive = NEW CardPrimitive(); if (ManaCost * cost = primitive->getManaCost())