added a new aihint #HINT:dontattackwith(targetchooser)
which tells the ai not to use the targetible cards as attackers, this can be card names, and CD modes.
modified the way ai handles multikicker. it will not be casting 1/1 joragas anymore :D
made WParsedInt ignore "+" signs....
added a new affinity ability...autohand=affinity(creature[vampire]|mygraveyard) ....
this is essentially affinity for creatures in your grave.
added supkeyword to clone clone addtype(zombie)....it adds the type listed to the cards types on clone...
reparse PT bonus on resolve.
reworked bushido, it should now work correctly...aside from that it now excepts word variables...fumiko is now bushido(type:creature[attacking]:battlefield/type:creature[attacking]:battlefield)
added a keyword to access acontrolsteal..the keyword is "steal"
auto=ueot steal target(creature)
reworked persist to handle undying..added the new counter handling rules intruduced by wotc in ISD
added a vector cardsAbilities to mtgcardinstance...this keeps the abilities added to the game for a card to use stored where we can easly alter or remove them.
added an automatic increase to geteff return if the ability is a putinplay ability.
finished coding support for flip and double sided cards, though viewing the "other side" is still not possible yet.
the ability follows the mtg rules.
the ability syntax is flip(card name)...a card can flip into any other card by name...even flip into itself.
added a "canPay() call for Ninja cost...to prevent it from coming up in a menu unless you're in blockers....
added 3 new restriction types that work very similar to type(
thisturn(tc)~morethan~2
lastturn(tc)~lessthan~thisturn(tc)
compare(wordvarible)~equalto~compare(wordvarible)
these are pretty self explanitory.
moved "&&" ability parsing below "this(" allowing "this(" to grant abilities now which contain &&...enclave egologist bug is fixed by this.
fixed an issue with combatspirit link for some reason the way i was doing the bool was not always working.
took care of the todo for AProtectionFrom...you can now give a protection from(blah) in a instant or ueot ability.
added altho very limited right now a "targetedplayer" tc word. i hope to increase this with time.
as always my sidekick doc already has some cards coded for this and test will follow the addition of the cards.
This commit is contained in:
@@ -16,6 +16,7 @@ class AIHint
|
|||||||
public:
|
public:
|
||||||
string mCondition;
|
string mCondition;
|
||||||
string mAction;
|
string mAction;
|
||||||
|
string mCombatAttackTip;
|
||||||
int mSourceId;
|
int mSourceId;
|
||||||
AIHint(string line);
|
AIHint(string line);
|
||||||
};
|
};
|
||||||
@@ -36,6 +37,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
AIHints (AIPlayerBaka * player);
|
AIHints (AIPlayerBaka * player);
|
||||||
AIAction * suggestAbility(ManaCost * potentialMana);
|
AIAction * suggestAbility(ManaCost * potentialMana);
|
||||||
|
bool HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card = NULL);
|
||||||
void add(string line);
|
void add(string line);
|
||||||
~AIHints();
|
~AIHints();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class AIPlayerBaka: public AIPlayer{
|
|||||||
//Tries to play an ability recommended by the deck creator
|
//Tries to play an ability recommended by the deck creator
|
||||||
virtual int selectHintAbility();
|
virtual int selectHintAbility();
|
||||||
|
|
||||||
virtual vector<MTGAbility*> canPayMana(MTGCardInstance * card = NULL,ManaCost * mCost = NULL);
|
virtual vector<MTGAbility*> canPayMana(MTGCardInstance * card = NULL,ManaCost * mCost = NULL, map<MTGCardInstance*, bool>usedCards = map<MTGCardInstance*,bool>());
|
||||||
virtual vector<MTGAbility*> canPaySunBurst(ManaCost * mCost = NULL);
|
virtual vector<MTGAbility*> canPaySunBurst(ManaCost * mCost = NULL);
|
||||||
|
|
||||||
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
|
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ private:
|
|||||||
s = s.substr(1);
|
s = s.substr(1);
|
||||||
multiplier = -1;
|
multiplier = -1;
|
||||||
}
|
}
|
||||||
|
if(s[0] == '+')
|
||||||
|
{
|
||||||
|
//ignore "+" signs....
|
||||||
|
s = s.substr(1);
|
||||||
|
}
|
||||||
//rounding values, the words can be written anywhere in the line,
|
//rounding values, the words can be written anywhere in the line,
|
||||||
//they are erased after parsing.
|
//they are erased after parsing.
|
||||||
if(s.find("halfup") != string::npos)
|
if(s.find("halfup") != string::npos)
|
||||||
@@ -858,6 +863,18 @@ public:
|
|||||||
/*
|
/*
|
||||||
Generic classes
|
Generic classes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class ANewAffinity: public MTGAbility
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string tcString;
|
||||||
|
string manaString;
|
||||||
|
ANewAffinity(GameObserver* observer, int _id, MTGCardInstance * _source,string Tc = "", string mana ="");
|
||||||
|
void Update(float dt);
|
||||||
|
int testDestroy();
|
||||||
|
ANewAffinity * clone() const;
|
||||||
|
};
|
||||||
|
|
||||||
//if/ifnot Cond then EFFECT
|
//if/ifnot Cond then EFFECT
|
||||||
class IfThenAbility: public ActivatedAbility
|
class IfThenAbility: public ActivatedAbility
|
||||||
{
|
{
|
||||||
@@ -993,11 +1010,13 @@ class AACloner: public ActivatedAbility
|
|||||||
public:
|
public:
|
||||||
int who;
|
int who;
|
||||||
string with;
|
string with;
|
||||||
|
string types;
|
||||||
list<int> awith;
|
list<int> awith;
|
||||||
list<int> colors;
|
list<int> colors;
|
||||||
|
list<int> typesToAdd;
|
||||||
|
|
||||||
AACloner(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL, int who = 0,
|
AACloner(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target = NULL, ManaCost * _cost = NULL, int who = 0,
|
||||||
string abilitiesStringList = "");
|
string abilitiesStringList = "",string typeslist = "");
|
||||||
int resolve();
|
int resolve();
|
||||||
const char * getMenuText();
|
const char * getMenuText();
|
||||||
virtual ostream& toString(ostream& out) const;
|
virtual ostream& toString(ostream& out) const;
|
||||||
@@ -1650,6 +1669,11 @@ public:
|
|||||||
int addToGame()
|
int addToGame()
|
||||||
{
|
{
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
|
if(PT.size())
|
||||||
|
{
|
||||||
|
SAFE_DELETE(wppt);
|
||||||
|
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
|
||||||
|
}
|
||||||
_target->power += wppt->power.getValue();
|
_target->power += wppt->power.getValue();
|
||||||
_target->addToToughness(wppt->toughness.getValue());
|
_target->addToToughness(wppt->toughness.getValue());
|
||||||
if(_target->has(Constants::INDESTRUCTIBLE) && wppt->toughness.getValue() < 0 && _target->toughness <= 0)
|
if(_target->has(Constants::INDESTRUCTIBLE) && wppt->toughness.getValue() < 0 && _target->toughness <= 0)
|
||||||
@@ -4906,50 +4930,25 @@ public:
|
|||||||
class ABushidoAbility: public MTGAbility
|
class ABushidoAbility: public MTGAbility
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MTGCardInstance * opponents[20];
|
string PowerToughnessModifier;
|
||||||
int nbOpponents;
|
|
||||||
int PowerModifier;
|
|
||||||
int ToughnessModifier;
|
|
||||||
|
|
||||||
ABushidoAbility(GameObserver* observer, int _id, MTGCardInstance * _source, int _PowerModifier, int _ToughnessModifier) :
|
ABushidoAbility(GameObserver* observer, int _id, MTGCardInstance * _source, string _PowerToughnessModifier) :
|
||||||
MTGAbility(observer, _id, _source)
|
MTGAbility(observer, _id, _source)
|
||||||
{
|
{
|
||||||
PowerModifier = _PowerModifier;
|
PowerToughnessModifier = _PowerToughnessModifier;
|
||||||
ToughnessModifier = _ToughnessModifier;
|
|
||||||
nbOpponents = 0;
|
|
||||||
}
|
}
|
||||||
int receiveEvent(WEvent * event)
|
int receiveEvent(WEvent * event)
|
||||||
{
|
|
||||||
if (dynamic_cast<WEventBlockersChosen*> (event))
|
|
||||||
{
|
{
|
||||||
MTGCardInstance * opponent = source->getNextOpponent();
|
if (dynamic_cast<WEventBlockersChosen*> (event))
|
||||||
if (!opponent) return 0;
|
|
||||||
source->power += PowerModifier;
|
|
||||||
source->addToToughness(ToughnessModifier);
|
|
||||||
while (opponent)
|
|
||||||
{
|
{
|
||||||
opponents[nbOpponents] = opponent;
|
MTGCardInstance * opponent = source->getNextOpponent();
|
||||||
nbOpponents++;
|
if (!opponent) return 0;
|
||||||
opponent = source->getNextOpponent(opponent);
|
PTInstant * a = NEW PTInstant(game, this->GetId(), source, source,NEW WParsedPT(PowerToughnessModifier,NULL,source));
|
||||||
|
GenericInstantAbility * wrapper = NEW GenericInstantAbility(game, 1, source,source, a);
|
||||||
|
wrapper->addToGame();
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else if (WEventPhaseChange* pe = dynamic_cast<WEventPhaseChange*>(event))
|
|
||||||
{
|
|
||||||
if (MTG_PHASE_AFTER_EOT == pe->to->id && nbOpponents)
|
|
||||||
{
|
|
||||||
source->power -= PowerModifier;
|
|
||||||
source->addToToughness(-ToughnessModifier);
|
|
||||||
nbOpponents = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ostream& toString(ostream& out) const
|
|
||||||
{
|
|
||||||
out << "ABushidoAbility ::: opponents : " << opponents << " ; nbOpponents : " << nbOpponents << " (";
|
|
||||||
return MTGAbility::toString(out) << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
ABushidoAbility * clone() const
|
ABushidoAbility * clone() const
|
||||||
{
|
{
|
||||||
@@ -4999,14 +4998,24 @@ public:
|
|||||||
AInstantControlSteal(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) :
|
AInstantControlSteal(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) :
|
||||||
InstantAbility(observer, _id, _source, _target)
|
InstantAbility(observer, _id, _source, _target)
|
||||||
{
|
{
|
||||||
TrueController = _target->controller();
|
|
||||||
TheftController = source->controller();
|
|
||||||
MTGCardInstance * copy = _target->changeController(TheftController);
|
|
||||||
target = copy;
|
|
||||||
source->target = copy;
|
|
||||||
copy->summoningSickness = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int resolve()
|
||||||
|
{
|
||||||
|
MTGCardInstance * _theftTarget = (MTGCardInstance*)target;
|
||||||
|
if(_theftTarget)
|
||||||
|
{
|
||||||
|
TrueController = _theftTarget->controller();
|
||||||
|
TheftController = source->controller();
|
||||||
|
MTGCardInstance * copy = _theftTarget->changeController(TheftController);
|
||||||
|
target = copy;
|
||||||
|
source->target = copy;
|
||||||
|
copy->summoningSickness = 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int destroy()
|
int destroy()
|
||||||
{
|
{
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
int init(MTGCardInstance * _target, const char * _name, int _power, int _toughness);
|
int init(MTGCardInstance * _target, const char * _name, int _power, int _toughness);
|
||||||
bool sameAs(const char * _name, int _power, int _toughness);
|
bool sameAs(const char * _name, int _power, int _toughness);
|
||||||
bool cancels(int _power, int _toughness);
|
bool cancels(int _power, int _toughness);
|
||||||
|
int cancelCounter(int power, int toughness);
|
||||||
int added();
|
int added();
|
||||||
int removed();
|
int removed();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ class Ninja : public ExtraCost
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Ninja(TargetChooser *_tc = NULL);
|
Ninja(TargetChooser *_tc = NULL);
|
||||||
|
virtual int canPay();
|
||||||
virtual int isPaymentSet();
|
virtual int isPaymentSet();
|
||||||
virtual int doPay();
|
virtual int doPay();
|
||||||
virtual Ninja * clone() const;
|
virtual Ninja * clone() const;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
vector<MTGCardInstance*>parentCards;
|
vector<MTGCardInstance*>parentCards;
|
||||||
vector<MTGCardInstance*>childrenCards;
|
vector<MTGCardInstance*>childrenCards;
|
||||||
|
vector<MTGAbility *>cardsAbilities;
|
||||||
|
|
||||||
int setAttacker(int value);
|
int setAttacker(int value);
|
||||||
int setDefenser(MTGCardInstance * c);
|
int setDefenser(MTGCardInstance * c);
|
||||||
@@ -95,6 +96,7 @@ public:
|
|||||||
int MaxLevelUp;
|
int MaxLevelUp;
|
||||||
int kicked;
|
int kicked;
|
||||||
bool isDualWielding;
|
bool isDualWielding;
|
||||||
|
bool stillNeeded;
|
||||||
Player * lastController;
|
Player * lastController;
|
||||||
MTGGameZone * getCurrentZone();
|
MTGGameZone * getCurrentZone();
|
||||||
MTGGameZone * previousZone;
|
MTGGameZone * previousZone;
|
||||||
|
|||||||
@@ -210,8 +210,9 @@ class Constants
|
|||||||
SNOWSWAMPWALK = 90,
|
SNOWSWAMPWALK = 90,
|
||||||
CANATTACK = 91,
|
CANATTACK = 91,
|
||||||
HYDRA = 92,
|
HYDRA = 92,
|
||||||
|
UNDYING = 93,
|
||||||
|
|
||||||
NB_BASIC_ABILITIES = 93,
|
NB_BASIC_ABILITIES = 94,
|
||||||
|
|
||||||
|
|
||||||
RARITY_S = 'S', //Special Rarity
|
RARITY_S = 'S', //Special Rarity
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ class MTGGameZone {
|
|||||||
|
|
||||||
//list of cards that have been through this zone in the current turn
|
//list of cards that have been through this zone in the current turn
|
||||||
vector<MTGCardInstance *> cardsSeenThisTurn;
|
vector<MTGCardInstance *> cardsSeenThisTurn;
|
||||||
|
//list of cards that have been through this zone in the last turn
|
||||||
|
vector<MTGCardInstance *> cardsSeenLastTurn;
|
||||||
int nb_cards;
|
int nb_cards;
|
||||||
MTGGameZone();
|
MTGGameZone();
|
||||||
~MTGGameZone();
|
~MTGGameZone();
|
||||||
@@ -104,8 +106,9 @@ class MTGGameZone {
|
|||||||
bool hasX();
|
bool hasX();
|
||||||
|
|
||||||
//How many cards matching a TargetChooser have been put in this zone during the turn
|
//How many cards matching a TargetChooser have been put in this zone during the turn
|
||||||
int seenThisTurn(TargetChooser * tc, int castFilter = Constants::CAST_DONT_CARE);
|
int seenThisTurn(TargetChooser * tc, int castFilter = Constants::CAST_DONT_CARE,bool lastTurn = false);
|
||||||
int seenThisTurn(string s, int castFilter = Constants::CAST_DONT_CARE);
|
int seenThisTurn(string s, int castFilter = Constants::CAST_DONT_CARE);
|
||||||
|
int seenLastTurn(string s, int castFilter = Constants::CAST_DONT_CARE);
|
||||||
|
|
||||||
void setOwner(Player * player);
|
void setOwner(Player * player);
|
||||||
MTGCardInstance * lastCardDrawn;
|
MTGCardInstance * lastCardDrawn;
|
||||||
@@ -175,6 +178,7 @@ public:
|
|||||||
MTGRemovedFromGame * removedFromGame;
|
MTGRemovedFromGame * removedFromGame;
|
||||||
MTGRemovedFromGame * exile; //alias to removedFromZone
|
MTGRemovedFromGame * exile; //alias to removedFromZone
|
||||||
MTGGameZone * garbage;
|
MTGGameZone * garbage;
|
||||||
|
MTGGameZone * garbageLastTurn;
|
||||||
MTGGameZone * temp;
|
MTGGameZone * temp;
|
||||||
|
|
||||||
MTGPlayerCards();
|
MTGPlayerCards();
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
virtual void reinit();
|
virtual void reinit();
|
||||||
void x();
|
void x();
|
||||||
int hasX();
|
int hasX();
|
||||||
|
int hasAnotherCost();
|
||||||
ManaCost(std::vector<int8_t>& _cost, int nb_elems = 1);
|
ManaCost(std::vector<int8_t>& _cost, int nb_elems = 1);
|
||||||
ManaCost();
|
ManaCost();
|
||||||
~ManaCost();
|
~ManaCost();
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ AIHint::AIHint(string _line)
|
|||||||
mAction = action;
|
mAction = action;
|
||||||
mSourceId = 0;
|
mSourceId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> splitDontAttack = parseBetween(action, "dontattackwith(", ")");
|
||||||
|
if(splitDontAttack.size())
|
||||||
|
{
|
||||||
|
mCombatAttackTip = splitDontAttack[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AIHints::AIHints(AIPlayerBaka * player): mPlayer(player)
|
AIHints::AIHints(AIPlayerBaka * player): mPlayer(player)
|
||||||
@@ -62,6 +68,27 @@ AIHint * AIHints::getByCondition (string condition)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AIHints::HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
TargetChooserFactory tfc(observer);
|
||||||
|
TargetChooser * hintTc = NULL;
|
||||||
|
for(unsigned int i = 0; i < hints.size();i++)
|
||||||
|
{
|
||||||
|
if (hints[i]->mCombatAttackTip.size())
|
||||||
|
{
|
||||||
|
hintTc = tfc.createTargetChooser(hints[i]->mCombatAttackTip,card);
|
||||||
|
if(hintTc && hintTc->canTarget(card,true))
|
||||||
|
{
|
||||||
|
SAFE_DELETE(hintTc);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
SAFE_DELETE(hintTc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//return true if a given ability matches a hint's description
|
//return true if a given ability matches a hint's description
|
||||||
//Eventually this will look awfully similar to the parser...any way to merge them somehow ?
|
//Eventually this will look awfully similar to the parser...any way to merge them somehow ?
|
||||||
bool AIHints::abilityMatches(MTGAbility * ability, AIHint * hint)
|
bool AIHints::abilityMatches(MTGAbility * ability, AIHint * hint)
|
||||||
@@ -159,6 +186,11 @@ string AIHints::constraintsNotFulfilled(AIAction * action, AIHint * hint, ManaCo
|
|||||||
|
|
||||||
if (!action)
|
if (!action)
|
||||||
{
|
{
|
||||||
|
if (hint->mCombatAttackTip.size())
|
||||||
|
{
|
||||||
|
out << "to see if this can attack[" << hint->mCombatAttackTip << "]";
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
if (hint->mSourceId && !findSource(hint->mSourceId))
|
if (hint->mSourceId && !findSource(hint->mSourceId))
|
||||||
{
|
{
|
||||||
out << "needcardinplay[" << hint->mSourceId << "]";
|
out << "needcardinplay[" << hint->mSourceId << "]";
|
||||||
@@ -220,6 +252,8 @@ AIAction * AIHints::findAbilityRecursive(AIHint * hint, ManaCost * potentialMana
|
|||||||
}
|
}
|
||||||
|
|
||||||
string s = constraintsNotFulfilled(a, hint, potentialMana);
|
string s = constraintsNotFulfilled(a, hint, potentialMana);
|
||||||
|
if (hint->mCombatAttackTip.size())
|
||||||
|
return NULL;
|
||||||
if (s.size())
|
if (s.size())
|
||||||
{
|
{
|
||||||
SAFE_DELETE(a);
|
SAFE_DELETE(a);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "GuiCombat.h"
|
#include "GuiCombat.h"
|
||||||
#include "AIHints.h"
|
#include "AIHints.h"
|
||||||
#include "ManaCostHybrid.h"
|
#include "ManaCostHybrid.h"
|
||||||
|
#include "MTGRules.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// AIAction
|
// AIAction
|
||||||
@@ -602,7 +603,10 @@ int OrderedAIAction::getEfficiency()
|
|||||||
//Decrease chance of using ability if there is an extra cost to use the ability, ignore tap
|
//Decrease chance of using ability if there is an extra cost to use the ability, ignore tap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (MTGPutInPlayRule * pip = dynamic_cast<MTGPutInPlayRule *>(a))
|
||||||
|
{
|
||||||
|
efficiency += 65;
|
||||||
|
}
|
||||||
return efficiency;
|
return efficiency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,7 +718,7 @@ bool AIPlayerBaka::payTheManaCost(ManaCost * cost, MTGCardInstance * target,vect
|
|||||||
}
|
}
|
||||||
if(k == gotPayments.size()-1)//only add it once, and at the end.
|
if(k == gotPayments.size()-1)//only add it once, and at the end.
|
||||||
paid->add(this->getManaPool());//incase some of our payments were mana already in the pool/.
|
paid->add(this->getManaPool());//incase some of our payments were mana already in the pool/.
|
||||||
if(paid->canAfford(cost) && (!cost->hasX() || k == gotPayments.size()-1))
|
if(paid->canAfford(cost) && (!cost->hasX() && !cost->hasAnotherCost()) || k == gotPayments.size()-1)
|
||||||
{
|
{
|
||||||
SAFE_DELETE(paid);
|
SAFE_DELETE(paid);
|
||||||
for(size_t clicking = 0; clicking < clicks.size(); ++clicking)
|
for(size_t clicking = 0; clicking < clicks.size(); ++clicking)
|
||||||
@@ -830,12 +834,12 @@ ManaCost * AIPlayerBaka::getPotentialMana(MTGCardInstance * target)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<MTGAbility*> AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * cost)
|
vector<MTGAbility*> AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * cost, map<MTGCardInstance*,bool>usedCards )
|
||||||
{
|
{
|
||||||
if(!cost || (cost && !cost->getConvertedCost()))
|
if(!cost || (cost && !cost->getConvertedCost()))
|
||||||
return vector<MTGAbility*>();
|
return vector<MTGAbility*>();
|
||||||
ManaCost * result = NEW ManaCost();
|
ManaCost * result = NEW ManaCost();
|
||||||
map<MTGCardInstance *, bool> used;
|
map<MTGCardInstance *, bool> used = usedCards;
|
||||||
vector<MTGAbility*>payments = vector<MTGAbility*>();
|
vector<MTGAbility*>payments = vector<MTGAbility*>();
|
||||||
if (this->getManaPool()->getConvertedCost())
|
if (this->getManaPool()->getConvertedCost())
|
||||||
{
|
{
|
||||||
@@ -1003,6 +1007,34 @@ vector<MTGAbility*> AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost *
|
|||||||
return payments;//we didn't meet one of the color cost requirements.
|
return payments;//we didn't meet one of the color cost requirements.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(cost->kicker && !usedCards.size())
|
||||||
|
{
|
||||||
|
|
||||||
|
ManaCost * withKickerCost= NEW ManaCost(cost->kicker);
|
||||||
|
int canKick = 0;
|
||||||
|
vector<MTGAbility*>kickerPayment;
|
||||||
|
bool keepLooking = true;
|
||||||
|
while(keepLooking)
|
||||||
|
{
|
||||||
|
kickerPayment = canPayMana(target,withKickerCost,used);
|
||||||
|
if(kickerPayment.size())
|
||||||
|
{
|
||||||
|
for(unsigned int w = 0;w < kickerPayment.size();++w)
|
||||||
|
{
|
||||||
|
if(!used[kickerPayment[w]->source])
|
||||||
|
{
|
||||||
|
payments.push_back(kickerPayment[w]);
|
||||||
|
used[kickerPayment[w]->source] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canKick += 1;
|
||||||
|
keepLooking = cost->kicker->isMulti;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
keepLooking = false;
|
||||||
|
}
|
||||||
|
SAFE_DELETE(withKickerCost);
|
||||||
|
}
|
||||||
SAFE_DELETE(check);
|
SAFE_DELETE(check);
|
||||||
SAFE_DELETE(checkResult);
|
SAFE_DELETE(checkResult);
|
||||||
}
|
}
|
||||||
@@ -1612,7 +1644,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
|||||||
int currentCost = card->getManaCost()->getConvertedCost();
|
int currentCost = card->getManaCost()->getConvertedCost();
|
||||||
int hasX = card->getManaCost()->hasX();
|
int hasX = card->getManaCost()->hasX();
|
||||||
gotPayments.clear();
|
gotPayments.clear();
|
||||||
if(!pMana->canAfford(card->getManaCost()))
|
if((!pMana->canAfford(card->getManaCost()) || card->getManaCost()->kicker))
|
||||||
gotPayments = canPayMana(card,card->getManaCost());
|
gotPayments = canPayMana(card,card->getManaCost());
|
||||||
//for preformence reason we only look for specific mana if the payment couldn't be made with pmana.
|
//for preformence reason we only look for specific mana if the payment couldn't be made with pmana.
|
||||||
if ((currentCost > maxCost || hasX) && (gotPayments.size() || pMana->canAfford(card->getManaCost())))
|
if ((currentCost > maxCost || hasX) && (gotPayments.size() || pMana->canAfford(card->getManaCost())))
|
||||||
@@ -1671,8 +1703,6 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
|||||||
// shouldPlay == baka_effect_bad giving it a 1 for odd ball lottery chance.
|
// shouldPlay == baka_effect_bad giving it a 1 for odd ball lottery chance.
|
||||||
shouldPlayPercentage = 1;
|
shouldPlayPercentage = 1;
|
||||||
}
|
}
|
||||||
DebugTrace("Should I play " << (card ? card->name : "Nothing" ) << "?" << endl
|
|
||||||
<<"shouldPlayPercentage = "<< shouldPlayPercentage);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//Reduce the chances of playing a spell with X cost if available mana is low
|
//Reduce the chances of playing a spell with X cost if available mana is low
|
||||||
@@ -1685,18 +1715,12 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
|||||||
}
|
}
|
||||||
if(card->getManaCost() && card->getManaCost()->kicker && card->getManaCost()->kicker->isMulti)
|
if(card->getManaCost() && card->getManaCost()->kicker && card->getManaCost()->kicker->isMulti)
|
||||||
{
|
{
|
||||||
|
shouldPlayPercentage = 10* size_t(gotPayments.size())/int(1+(card->getManaCost()->getConvertedCost()+card->getManaCost()->kicker->getConvertedCost()));
|
||||||
ManaCost * withKickerCost= NEW ManaCost(card->getManaCost());
|
if(shouldPlayPercentage < 40)
|
||||||
withKickerCost->add(withKickerCost->kicker);
|
shouldPlayPercentage = shouldPlayPercentage/3;
|
||||||
int canKick = 0;
|
|
||||||
while(pMana->canAfford(withKickerCost))
|
|
||||||
{
|
|
||||||
withKickerCost->add(withKickerCost->kicker);
|
|
||||||
canKick += 1;
|
|
||||||
}
|
|
||||||
SAFE_DELETE(withKickerCost);
|
|
||||||
shouldPlayPercentage = 10*canKick;
|
|
||||||
}
|
}
|
||||||
|
DebugTrace("Should I play " << (card ? card->name : "Nothing" ) << "?" << endl
|
||||||
|
<<"shouldPlayPercentage = "<< shouldPlayPercentage);
|
||||||
if(card->getRestrictions().size())
|
if(card->getRestrictions().size())
|
||||||
{
|
{
|
||||||
AbilityFactory af(observer);
|
AbilityFactory af(observer);
|
||||||
@@ -1708,7 +1732,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
|||||||
int chance = randomChance % 100;
|
int chance = randomChance % 100;
|
||||||
if (chance > shouldPlayPercentage)
|
if (chance > shouldPlayPercentage)
|
||||||
continue;
|
continue;
|
||||||
if(shouldPlayPercentage < 10)
|
if(shouldPlayPercentage <= 10)
|
||||||
{
|
{
|
||||||
DebugTrace("shouldPlayPercentage was less than 10 this was a lottery roll on RNG");
|
DebugTrace("shouldPlayPercentage was less than 10 this was a lottery roll on RNG");
|
||||||
}
|
}
|
||||||
@@ -1720,7 +1744,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
|||||||
}
|
}
|
||||||
if(nextCardToPlay)
|
if(nextCardToPlay)
|
||||||
{
|
{
|
||||||
if(!pMana->canAfford(nextCardToPlay->getManaCost()))
|
if(!pMana->canAfford(nextCardToPlay->getManaCost()) || nextCardToPlay->getManaCost()->kicker)
|
||||||
gotPayments = canPayMana(nextCardToPlay,nextCardToPlay->getManaCost());
|
gotPayments = canPayMana(nextCardToPlay,nextCardToPlay->getManaCost());
|
||||||
DebugTrace(" AI wants to play card." << endl
|
DebugTrace(" AI wants to play card." << endl
|
||||||
<< "- Next card to play: " << (nextCardToPlay ? nextCardToPlay->name : "None" ) << endl );
|
<< "- Next card to play: " << (nextCardToPlay ? nextCardToPlay->name : "None" ) << endl );
|
||||||
@@ -2002,6 +2026,8 @@ int AIPlayerBaka::chooseAttackers()
|
|||||||
MTGCardInstance * card = NULL;
|
MTGCardInstance * card = NULL;
|
||||||
while ((card = cd.nextmatch(game->inPlay, card)))
|
while ((card = cd.nextmatch(game->inPlay, card)))
|
||||||
{
|
{
|
||||||
|
if(hints && hints->HintSaysDontAttack(observer,card))
|
||||||
|
continue;
|
||||||
observer->cardClick(card, MTGAbility::MTG_ATTACK_RULE);
|
observer->cardClick(card, MTGAbility::MTG_ATTACK_RULE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ Interruptible(observer, 0)
|
|||||||
mHeight = 40;
|
mHeight = 40;
|
||||||
type = ACTION_SPELL;
|
type = ACTION_SPELL;
|
||||||
cost = NEW ManaCost();
|
cost = NEW ManaCost();
|
||||||
|
cost->extraCosts = NULL;
|
||||||
tc = NULL;
|
tc = NULL;
|
||||||
from = _source->getCurrentZone();
|
from = _source->getCurrentZone();
|
||||||
payResult = ManaCost::MANA_UNPAID;
|
payResult = ManaCost::MANA_UNPAID;
|
||||||
@@ -209,7 +210,11 @@ Interruptible(observer, 0)
|
|||||||
Spell::Spell(GameObserver* observer, int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _cost, int payResult) :
|
Spell::Spell(GameObserver* observer, int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _cost, int payResult) :
|
||||||
Interruptible(observer, id), tc(tc), cost(_cost), payResult(payResult)
|
Interruptible(observer, id), tc(tc), cost(_cost), payResult(payResult)
|
||||||
{
|
{
|
||||||
if (!cost) cost = NEW ManaCost();
|
if (!cost)
|
||||||
|
{
|
||||||
|
cost = NEW ManaCost();
|
||||||
|
cost->extraCosts = NULL;
|
||||||
|
}
|
||||||
source = _source;
|
source = _source;
|
||||||
mHeight = 40;
|
mHeight = 40;
|
||||||
type = ACTION_SPELL;
|
type = ACTION_SPELL;
|
||||||
@@ -291,12 +296,13 @@ int Spell::resolve()
|
|||||||
{
|
{
|
||||||
Player * p = source->controller();
|
Player * p = source->controller();
|
||||||
int castMethod = source->castMethod;
|
int castMethod = source->castMethod;
|
||||||
|
vector<Targetable*>backupTgt = source->backupTargets;
|
||||||
source = p->game->putInZone(source, from, p->game->battlefield);
|
source = p->game->putInZone(source, from, p->game->battlefield);
|
||||||
|
|
||||||
// We need to get the information about the cast method on both the card in the stack AND the card in play,
|
// We need to get the information about the cast method on both the card in the stack AND the card in play,
|
||||||
//so we copy it from the previous card (in the stack) to the new one (in play).
|
//so we copy it from the previous card (in the stack) to the new one (in play).
|
||||||
source->castMethod = castMethod;
|
source->castMethod = castMethod;
|
||||||
|
source->backupTargets = backupTgt;
|
||||||
from = p->game->battlefield;
|
from = p->game->battlefield;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +315,6 @@ int Spell::resolve()
|
|||||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AbilityFactory af(observer);
|
AbilityFactory af(observer);
|
||||||
af.addAbilities(observer->mLayers->actionLayer()->getMaxId(), this);
|
af.addAbilities(observer->mLayers->actionLayer()->getMaxId(), this);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -290,9 +290,9 @@ AACounter::AACounter(GameObserver* observer, int id, MTGCardInstance * source, M
|
|||||||
AbilityFactory af(game);
|
AbilityFactory af(game);
|
||||||
if(counterstring.size())
|
if(counterstring.size())
|
||||||
{
|
{
|
||||||
Counter * checkcounter = af.parseCounter(counterstring, source, NULL);
|
Counter * checkcounter = af.parseCounter(counterstring, source, NULL);
|
||||||
nb = checkcounter->nb;
|
nb = checkcounter->nb;
|
||||||
delete checkcounter;
|
delete checkcounter;
|
||||||
}
|
}
|
||||||
if (nb > 0)
|
if (nb > 0)
|
||||||
{
|
{
|
||||||
@@ -314,22 +314,40 @@ AACounter::AACounter(GameObserver* observer, int id, MTGCardInstance * source, M
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
for (int i = 0; i < -nb; i++)
|
|
||||||
{
|
{
|
||||||
while (_target->next)
|
for (int i = 0; i < -nb; i++)
|
||||||
_target = _target->next;
|
{
|
||||||
_target->counters->removeCounter(name.c_str(), power, toughness);
|
while (_target->next)
|
||||||
|
_target = _target->next;
|
||||||
|
_target->counters->removeCounter(name.c_str(), power, toughness);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_target->doDamageTest = 1;
|
||||||
|
if(!_target->afterDamage())
|
||||||
|
{
|
||||||
|
//If a creature with +1/+1 counters on it gets enough -1/-1 counters to kill it,
|
||||||
|
//it dies before the two counters have the chance to cancel out. For example,
|
||||||
|
//if your Strangleroot Geist with a +1/+1 counter on it got three -1/-1 counters
|
||||||
|
//from Skinrender's "enters the battlefield" ability, the Geist would die with //
|
||||||
|
//one +1/+1 counter and three -1/-1 counters and wouldn't return to the battlefield.
|
||||||
|
for (int i = 0; i < _target->counters->mCount; i++)
|
||||||
|
{
|
||||||
|
if (_target->counters->counters[i]->cancels(power, toughness) && !name.size() && _target->counters->counters[i]->nb > 0)
|
||||||
|
{
|
||||||
|
_target->counters->counters[i]->cancelCounter(power,toughness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//specail cases, indestructible creatures which recieve enough counters to kill it are destroyed as a state based effect
|
||||||
|
if(_target->toughness <= 0 && _target->has(Constants::INDESTRUCTIBLE) && toughness < 0)
|
||||||
|
_target->controller()->game->putInGraveyard(_target);
|
||||||
|
return nb;
|
||||||
}
|
}
|
||||||
//specail cases, indestructible creatures which recieve enough counters to kill it are destroyed as a state based effect
|
return 0;
|
||||||
if(_target->toughness <= 0 && _target->has(Constants::INDESTRUCTIBLE) && toughness < 0)
|
|
||||||
_target->controller()->game->putInGraveyard(_target);
|
|
||||||
return nb;
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* AACounter::getMenuText()
|
const char* AACounter::getMenuText()
|
||||||
{
|
{
|
||||||
@@ -975,6 +993,7 @@ int AAMorph::resolve()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
a->addToGame();
|
a->addToGame();
|
||||||
|
_target->cardsAbilities.push_back(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1040,23 +1059,16 @@ int AAFlip::resolve()
|
|||||||
MTGCardInstance * myFlip = NEW MTGCardInstance(fcard, _target->controller()->game);
|
MTGCardInstance * myFlip = NEW MTGCardInstance(fcard, _target->controller()->game);
|
||||||
_target->name = myFlip->name;
|
_target->name = myFlip->name;
|
||||||
_target->colors = myFlip->colors;
|
_target->colors = myFlip->colors;
|
||||||
_target->power = (myFlip->power + _target->power) - _target->origpower;
|
|
||||||
_target->addToToughness(myFlip->toughness - _target->origtoughness);
|
|
||||||
_target->types = myFlip->types;
|
_target->types = myFlip->types;
|
||||||
_target->text = myFlip->text;
|
_target->text = myFlip->text;
|
||||||
_target->formattedText = myFlip->formattedText;
|
_target->formattedText = myFlip->formattedText;
|
||||||
ActionLayer * al = game->mLayers->actionLayer();
|
ActionLayer * al = game->mLayers->actionLayer();
|
||||||
for (int k = (int)(al->mObjects.size()) - 1; k > 0; k--)
|
for(unsigned int i = 0;i < _target->cardsAbilities.size();i++)
|
||||||
{
|
{
|
||||||
MTGAbility * a = dynamic_cast<MTGAbility*>(game->mLayers->actionLayer()->mObjects[k]);
|
MTGAbility * a = dynamic_cast<MTGAbility *>(_target->cardsAbilities[i]);
|
||||||
if(a && a->source == _target)
|
if(a) game->removeObserver(a);
|
||||||
{
|
|
||||||
a->forceDestroy = 1;
|
|
||||||
a->destroy();
|
|
||||||
a->removeFromGame();
|
|
||||||
al->removeFromGame(a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_target->cardsAbilities.clear();
|
||||||
_target->magicText = myFlip->magicText;
|
_target->magicText = myFlip->magicText;
|
||||||
af.getAbilities(¤tAbilities, NULL, _target);
|
af.getAbilities(¤tAbilities, NULL, _target);
|
||||||
for (size_t i = 0; i < currentAbilities.size(); ++i)
|
for (size_t i = 0; i < currentAbilities.size(); ++i)
|
||||||
@@ -1073,12 +1085,43 @@ int AAFlip::resolve()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
a->addToGame();
|
a->addToGame();
|
||||||
|
_target->cardsAbilities.push_back(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SAFE_DELETE(myFlip);
|
//power
|
||||||
|
int powerMod = 0;
|
||||||
|
int toughMod = 0;
|
||||||
|
bool powerlessThanOriginal = false;
|
||||||
|
bool toughLessThanOriginal = false;
|
||||||
|
if(_target->power < _target->origpower)
|
||||||
|
{
|
||||||
|
powerMod = _target->origpower - _target->power;
|
||||||
|
powerlessThanOriginal = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
powerMod =_target->power - _target->origpower;
|
||||||
|
}
|
||||||
|
//toughness
|
||||||
|
if(_target->toughness <= _target->origtoughness)
|
||||||
|
{
|
||||||
|
toughMod = _target->origtoughness - _target->toughness;
|
||||||
|
toughLessThanOriginal = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toughMod =_target->toughness - _target->origtoughness;
|
||||||
|
}
|
||||||
|
_target->power = powerlessThanOriginal?myFlip->power - powerMod:myFlip->power + powerMod;
|
||||||
|
_target->life = toughLessThanOriginal?myFlip->toughness - toughMod:myFlip->toughness + toughMod;
|
||||||
|
_target->toughness = toughLessThanOriginal?myFlip->toughness - toughMod:myFlip->toughness + toughMod;
|
||||||
|
_target->origpower = myFlip->origpower;
|
||||||
|
_target->origtoughness = myFlip->origtoughness;
|
||||||
|
SAFE_DELETE(myFlip);
|
||||||
|
_target->mPropertiesChangedSinceLastUpdate = true;
|
||||||
}
|
}
|
||||||
_target->mPropertiesChangedSinceLastUpdate = true;
|
|
||||||
currentAbilities.clear();
|
currentAbilities.clear();
|
||||||
testDestroy();
|
testDestroy();
|
||||||
}
|
}
|
||||||
@@ -1642,7 +1685,7 @@ AALifeSet::~AALifeSet()
|
|||||||
//AACloner
|
//AACloner
|
||||||
//cloning...this makes a token thats a copy of the target.
|
//cloning...this makes a token thats a copy of the target.
|
||||||
AACloner::AACloner(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost, int who,
|
AACloner::AACloner(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost, int who,
|
||||||
string abilitiesStringList) :
|
string abilitiesStringList,string TypesList) :
|
||||||
ActivatedAbility(observer, _id, _source, _cost, 0), who(who)
|
ActivatedAbility(observer, _id, _source, _cost, 0), who(who)
|
||||||
{
|
{
|
||||||
aType = MTGAbility::CLONING;
|
aType = MTGAbility::CLONING;
|
||||||
@@ -1653,6 +1696,10 @@ AACloner::AACloner(GameObserver* observer, int _id, MTGCardInstance * _source, M
|
|||||||
PopulateAbilityIndexVector(awith, abilitiesStringList);
|
PopulateAbilityIndexVector(awith, abilitiesStringList);
|
||||||
PopulateColorIndexVector(colors, abilitiesStringList);
|
PopulateColorIndexVector(colors, abilitiesStringList);
|
||||||
}
|
}
|
||||||
|
if (TypesList.size())
|
||||||
|
{
|
||||||
|
PopulateSubtypesIndexVector(typesToAdd,TypesList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1688,6 +1735,10 @@ int AACloner::resolve()
|
|||||||
{
|
{
|
||||||
spell->source->setColor(*it);
|
spell->source->setColor(*it);
|
||||||
}
|
}
|
||||||
|
for (it = typesToAdd.begin(); it != typesToAdd.end(); it++)
|
||||||
|
{
|
||||||
|
spell->source->addType(*it);
|
||||||
|
}
|
||||||
delete spell;
|
delete spell;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -2241,6 +2292,28 @@ AAWinGame * AAWinGame::clone() const
|
|||||||
|
|
||||||
//Generic Abilities
|
//Generic Abilities
|
||||||
|
|
||||||
|
//a new affinity
|
||||||
|
ANewAffinity::ANewAffinity(GameObserver* observer, int _id, MTGCardInstance * _source, string Tc, string mana) :
|
||||||
|
MTGAbility(observer, _id, _source), tcString(Tc), manaString(mana)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ANewAffinity::Update(float dt)
|
||||||
|
{
|
||||||
|
testDestroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ANewAffinity::testDestroy()
|
||||||
|
{
|
||||||
|
if(this->source->isInPlay(game))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ANewAffinity * ANewAffinity::clone() const
|
||||||
|
{
|
||||||
|
return NEW ANewAffinity(*this);
|
||||||
|
}
|
||||||
|
|
||||||
//IfThenEffect
|
//IfThenEffect
|
||||||
IfThenAbility::IfThenAbility(GameObserver* observer, int _id, MTGAbility * delayedAbility, MTGCardInstance * _source, Targetable * _target, int type,string Cond) :
|
IfThenAbility::IfThenAbility(GameObserver* observer, int _id, MTGAbility * delayedAbility, MTGCardInstance * _source, Targetable * _target, int type,string Cond) :
|
||||||
@@ -3713,7 +3786,7 @@ APhaseAction::~APhaseAction()
|
|||||||
|
|
||||||
// the main ability
|
// the main ability
|
||||||
APhaseActionGeneric::APhaseActionGeneric(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions, int _phase,bool forcedestroy,bool next,bool myturn,bool opponentturn,bool once) :
|
APhaseActionGeneric::APhaseActionGeneric(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * target, string sAbility, int restrictions, int _phase,bool forcedestroy,bool next,bool myturn,bool opponentturn,bool once) :
|
||||||
InstantAbility(observer, _id, source, target)
|
InstantAbility(observer, _id, card, target)
|
||||||
{
|
{
|
||||||
MTGCardInstance * _target = target;
|
MTGCardInstance * _target = target;
|
||||||
ability = NEW APhaseAction(game, _id, card,_target, sAbility, restrictions, _phase,forcedestroy,next,myturn,opponentturn,once);
|
ability = NEW APhaseAction(game, _id, card,_target, sAbility, restrictions, _phase,forcedestroy,next,myturn,opponentturn,once);
|
||||||
|
|||||||
@@ -37,6 +37,21 @@ bool Counter::cancels(int _power, int _toughness)
|
|||||||
return (power == -_power && toughness == -_toughness);
|
return (power == -_power && toughness == -_toughness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Counter::cancelCounter(int power, int toughness)
|
||||||
|
{
|
||||||
|
while(this->target->counters->hasCounter(power,toughness) && this->target->counters->hasCounter(power*-1,toughness*-1))
|
||||||
|
{
|
||||||
|
GameObserver *g = this->target->getObserver();
|
||||||
|
this->removed();
|
||||||
|
this->nb--;
|
||||||
|
WEvent * t = NEW WEventCounters(NULL,"",power*-1,toughness*-1,false,true);
|
||||||
|
dynamic_cast<WEventCounters*>(t)->targetCard = this->target;
|
||||||
|
g->receiveEvent(t);
|
||||||
|
this->target->counters->removeCounter(power,toughness);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int Counter::added()
|
int Counter::added()
|
||||||
{
|
{
|
||||||
if (power != 0 || toughness != 0)
|
if (power != 0 || toughness != 0)
|
||||||
@@ -78,19 +93,6 @@ int Counters::addCounter(const char * _name, int _power, int _toughness)
|
|||||||
dynamic_cast<WEventCounters*>(e)->targetCard = this->target;
|
dynamic_cast<WEventCounters*>(e)->targetCard = this->target;
|
||||||
if (e == g->replacementEffects->replace(e))
|
if (e == g->replacementEffects->replace(e))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
|
||||||
{
|
|
||||||
if (counters[i]->cancels(_power, _toughness) && !counters[i]->name.size() && counters[i]->nb > 0)
|
|
||||||
{
|
|
||||||
counters[i]->removed();
|
|
||||||
counters[i]->nb--;
|
|
||||||
WEvent * t = NEW WEventCounters(this,_name,_power*-1,_toughness*-1,false,true);
|
|
||||||
dynamic_cast<WEventCounters*>(t)->targetCard = this->target;
|
|
||||||
g->receiveEvent(t);
|
|
||||||
delete(e);
|
|
||||||
return mCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
{
|
{
|
||||||
if (counters[i]->sameAs(_name, _power, _toughness))
|
if (counters[i]->sameAs(_name, _power, _toughness))
|
||||||
@@ -111,6 +113,8 @@ int Counters::addCounter(const char * _name, int _power, int _toughness)
|
|||||||
dynamic_cast<WEventCounters*>(w)->targetCard = this->target;
|
dynamic_cast<WEventCounters*>(w)->targetCard = this->target;
|
||||||
g->receiveEvent(w);
|
g->receiveEvent(w);
|
||||||
mCount++;
|
mCount++;
|
||||||
|
this->target->doDamageTest = 1;
|
||||||
|
this->target->afterDamage();
|
||||||
}
|
}
|
||||||
delete(e);
|
delete(e);
|
||||||
return mCount;
|
return mCount;
|
||||||
|
|||||||
@@ -533,6 +533,13 @@ ExtraCost("Select unblocked attacker", _tc)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Ninja::canPay()
|
||||||
|
{
|
||||||
|
if(source->getObserver()->getCurrentGamePhase() != MTG_PHASE_COMBATBLOCKERS)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int Ninja::isPaymentSet()
|
int Ninja::isPaymentSet()
|
||||||
{
|
{
|
||||||
if (target && ((target->isAttacker() && target->isBlocked()) ||
|
if (target && ((target->isAttacker() && target->isBlocked()) ||
|
||||||
|
|||||||
@@ -893,6 +893,48 @@ void GameObserver::Affinity()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int reducem = 0;
|
||||||
|
bool resetCost = false;
|
||||||
|
for(unsigned int na = 0; na < card->cardsAbilities.size();na++)
|
||||||
|
{
|
||||||
|
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
|
||||||
|
if(newAff)
|
||||||
|
{
|
||||||
|
if(!resetCost)
|
||||||
|
{
|
||||||
|
resetCost = true;
|
||||||
|
card->getManaCost()->copy(original);
|
||||||
|
if(card->getManaCost()->extraCosts)
|
||||||
|
{
|
||||||
|
for(unsigned int i = 0; i < card->getManaCost()->extraCosts->costs.size();i++)
|
||||||
|
{
|
||||||
|
card->getManaCost()->extraCosts->costs[i]->setSource(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TargetChooserFactory tf(this);
|
||||||
|
TargetChooser * tcn = tf.createTargetChooser(newAff->tcString,card,NULL);
|
||||||
|
|
||||||
|
for (int w = 0; w < 2; ++w)
|
||||||
|
{
|
||||||
|
Player *p = this->players[w];
|
||||||
|
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile };
|
||||||
|
for (int k = 0; k < 6; k++)
|
||||||
|
{
|
||||||
|
MTGGameZone * z = zones[k];
|
||||||
|
if (tcn->targetsZone(z))
|
||||||
|
{
|
||||||
|
reducem += z->countByCanTarget(tcn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SAFE_DELETE(tcn);
|
||||||
|
ManaCost * removingCost = ManaCost::parseManaCost(newAff->manaString);
|
||||||
|
for(int j = 0; j < reducem; j++)
|
||||||
|
card->getManaCost()->remove(removingCost);
|
||||||
|
SAFE_DELETE(removingCost);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(card->has(Constants::AFFINITYARTIFACTS)||
|
if(card->has(Constants::AFFINITYARTIFACTS)||
|
||||||
card->has(Constants::AFFINITYFOREST)||
|
card->has(Constants::AFFINITYFOREST)||
|
||||||
card->has(Constants::AFFINITYGREENCREATURES)||
|
card->has(Constants::AFFINITYGREENCREATURES)||
|
||||||
@@ -930,6 +972,13 @@ void GameObserver::Affinity()
|
|||||||
type = "creature";
|
type = "creature";
|
||||||
}
|
}
|
||||||
card->getManaCost()->copy(original);
|
card->getManaCost()->copy(original);
|
||||||
|
if(card->getManaCost()->extraCosts)
|
||||||
|
{
|
||||||
|
for(unsigned int i = 0; i < card->getManaCost()->extraCosts->costs.size();i++)
|
||||||
|
{
|
||||||
|
card->getManaCost()->extraCosts->costs[i]->setSource(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
int reduce = 0;
|
int reduce = 0;
|
||||||
if(card->has(Constants::AFFINITYGREENCREATURES))
|
if(card->has(Constants::AFFINITYGREENCREATURES))
|
||||||
{
|
{
|
||||||
@@ -947,6 +996,7 @@ void GameObserver::Affinity()
|
|||||||
if(card->getManaCost()->getCost(color) > 0)
|
if(card->getManaCost()->getCost(color) > 0)
|
||||||
card->getManaCost()->remove(color,1);
|
card->getManaCost()->remove(color,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
SAFE_DELETE(original);
|
SAFE_DELETE(original);
|
||||||
}
|
}
|
||||||
|
|||||||
+144
-36
@@ -118,13 +118,19 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card, Player * playe
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t typeRelated = restriction[i].find("type(");
|
size_t typeRelated = restriction[i].find("type(");
|
||||||
|
size_t seenType = restriction[i].find("lastturn(");
|
||||||
|
size_t seenRelated = restriction[i].find("lastturn(");
|
||||||
|
if(seenRelated == string::npos)
|
||||||
|
seenRelated = restriction[i].find("thisturn(");
|
||||||
|
size_t compRelated = restriction[i].find("compare(");
|
||||||
|
|
||||||
size_t check = 0;
|
size_t check = 0;
|
||||||
if(typeRelated != string::npos)
|
if(typeRelated != string::npos || seenRelated != string::npos || compRelated != string::npos)
|
||||||
{
|
{
|
||||||
int firstAmount = 0;
|
int firstAmount = 0;
|
||||||
int secondAmount = 0;
|
int secondAmount = 0;
|
||||||
int mod=0;
|
int mod=0;
|
||||||
string type;
|
string rtc;
|
||||||
vector<string> comparasion = split(restriction[i],'~');
|
vector<string> comparasion = split(restriction[i],'~');
|
||||||
if(comparasion.size() != 3)
|
if(comparasion.size() != 3)
|
||||||
return 0;//it was incorrectly coded, user should proofread card code.
|
return 0;//it was incorrectly coded, user should proofread card code.
|
||||||
@@ -134,16 +140,26 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card, Player * playe
|
|||||||
for(unsigned int i = 0; i < comparasion.size(); i++)
|
for(unsigned int i = 0; i < comparasion.size(); i++)
|
||||||
{
|
{
|
||||||
check = comparasion[i].find("type(");
|
check = comparasion[i].find("type(");
|
||||||
|
if(check == string::npos)
|
||||||
|
check = comparasion[i].find("lastturn(");
|
||||||
|
if(check == string::npos)
|
||||||
|
check = comparasion[i].find("thisturn(");
|
||||||
|
if(check == string::npos)
|
||||||
|
check = comparasion[i].find("compare(");
|
||||||
if( check != string::npos)
|
if( check != string::npos)
|
||||||
{
|
{
|
||||||
size_t end = 0;
|
size_t end = 0;
|
||||||
size_t found = comparasion[i].find("type(");
|
size_t foundType = comparasion[i].find("type(");
|
||||||
if (found != string::npos)
|
size_t foundComp = comparasion[i].find("compare(");
|
||||||
|
size_t foundSeen = comparasion[i].find("lastturn(");
|
||||||
|
if(foundSeen == string::npos)
|
||||||
|
foundSeen = comparasion[i].find("thisturn(");
|
||||||
|
if (foundType != string::npos)
|
||||||
{
|
{
|
||||||
end = comparasion[i].find(")", found);
|
end = comparasion[i].find(")", foundType);
|
||||||
type = comparasion[i].substr(found + 5, end - found - 5).c_str();
|
rtc = comparasion[i].substr(foundType + 5, end - foundType - 5).c_str();
|
||||||
TargetChooserFactory tcf(observer);
|
TargetChooserFactory tcf(observer);
|
||||||
TargetChooser * ttc = tcf.createTargetChooser(type,card);
|
TargetChooser * ttc = tcf.createTargetChooser(rtc,card);
|
||||||
mod = atoi(comparasion[i].substr(end+1).c_str());
|
mod = atoi(comparasion[i].substr(end+1).c_str());
|
||||||
if(i == 2)
|
if(i == 2)
|
||||||
{
|
{
|
||||||
@@ -158,6 +174,59 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card, Player * playe
|
|||||||
|
|
||||||
SAFE_DELETE(ttc);
|
SAFE_DELETE(ttc);
|
||||||
}
|
}
|
||||||
|
if (foundComp != string::npos)
|
||||||
|
{
|
||||||
|
end = comparasion[i].find(")", foundComp);
|
||||||
|
rtc = comparasion[i].substr(foundComp + 8, end - foundComp - 8).c_str();
|
||||||
|
mod = atoi(comparasion[i].substr(end+1).c_str());
|
||||||
|
if(i == 2)
|
||||||
|
{
|
||||||
|
WParsedInt * newAmount = NEW WParsedInt(rtc,card);
|
||||||
|
secondAmount = newAmount->getValue();
|
||||||
|
secondAmount += mod;
|
||||||
|
SAFE_DELETE(newAmount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WParsedInt * newAmount = NEW WParsedInt(rtc,card);
|
||||||
|
firstAmount = newAmount->getValue();
|
||||||
|
firstAmount += mod;
|
||||||
|
SAFE_DELETE(newAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (foundSeen != string::npos)
|
||||||
|
{
|
||||||
|
end = comparasion[i].find(")", foundSeen);
|
||||||
|
rtc = comparasion[i].substr(foundSeen + 9, end - foundSeen - 9).c_str();
|
||||||
|
mod = atoi(comparasion[i].substr(end+1).c_str());
|
||||||
|
|
||||||
|
TargetChooserFactory tcf(observer);
|
||||||
|
TargetChooser * stc = tcf.createTargetChooser(rtc,card);
|
||||||
|
for (int w = 0; w < 2; ++w)
|
||||||
|
{
|
||||||
|
Player *p = observer->players[w];
|
||||||
|
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile };
|
||||||
|
for (int k = 0; k < 6; k++)
|
||||||
|
{
|
||||||
|
MTGGameZone * z = zones[k];
|
||||||
|
if (stc->targetsZone(z))
|
||||||
|
{
|
||||||
|
if(i == 2)
|
||||||
|
{
|
||||||
|
secondAmount += seenType != string::npos ? z->seenLastTurn(rtc,Constants::CAST_ALL):z->seenThisTurn(rtc,Constants::CAST_ALL);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
firstAmount += seenType != string::npos ? z->seenLastTurn(rtc,Constants::CAST_ALL):z->seenThisTurn(rtc,Constants::CAST_ALL);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i == 2 ? secondAmount += mod:firstAmount += mod;
|
||||||
|
SAFE_DELETE(stc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (i == 2)
|
else if (i == 2)
|
||||||
{
|
{
|
||||||
@@ -1094,8 +1163,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
return parseMagicLine(s.substr(kAlternateCostKeywords[i].length()), id, spell, card);
|
return parseMagicLine(s.substr(kAlternateCostKeywords[i].length()), id, spell, card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//if/ifnot COND then DO EFFECT.
|
//if/ifnot COND then DO EFFECT.
|
||||||
const string ifKeywords[] = {"if ", "ifnot "};
|
const string ifKeywords[] = {"if ", "ifnot "};
|
||||||
int checkIf[] = { 1, 2 };
|
int checkIf[] = { 1, 2 };
|
||||||
@@ -1175,24 +1242,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
{
|
{
|
||||||
return parsePhaseActionAbility(s,card,spell,target,restrictions,id);
|
return parsePhaseActionAbility(s,card,spell,target,restrictions,id);
|
||||||
}
|
}
|
||||||
//Multiple abilities for ONE cost
|
|
||||||
found = s.find("&&");
|
|
||||||
if (found != string::npos)
|
|
||||||
{
|
|
||||||
SAFE_DELETE(tc);
|
|
||||||
vector<string> multiEffects = split(s,'&');
|
|
||||||
MultiAbility * multi = NEW MultiAbility(observer, id, card, target, NULL);
|
|
||||||
for(unsigned int i = 0;i < multiEffects.size();i++)
|
|
||||||
{
|
|
||||||
if(!multiEffects[i].empty())
|
|
||||||
{
|
|
||||||
MTGAbility * addAbility = parseMagicLine(multiEffects[i], id, spell, card, activated);
|
|
||||||
multi->Add(addAbility);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
multi->oneShot = 1;
|
|
||||||
return multi;
|
|
||||||
}
|
|
||||||
|
|
||||||
int forcedalive = 0;
|
int forcedalive = 0;
|
||||||
//force an ability to ignore destroy while source is still valid.
|
//force an ability to ignore destroy while source is still valid.
|
||||||
@@ -1300,6 +1349,26 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Multiple abilities for ONE cost
|
||||||
|
found = s.find("&&");
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
SAFE_DELETE(tc);
|
||||||
|
vector<string> multiEffects = split(s,'&');
|
||||||
|
MultiAbility * multi = NEW MultiAbility(observer, id, card, target, NULL);
|
||||||
|
for(unsigned int i = 0;i < multiEffects.size();i++)
|
||||||
|
{
|
||||||
|
if(!multiEffects[i].empty())
|
||||||
|
{
|
||||||
|
MTGAbility * addAbility = parseMagicLine(multiEffects[i], id, spell, card, activated);
|
||||||
|
multi->Add(addAbility);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
multi->oneShot = 1;
|
||||||
|
return multi;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Lord, foreach, aslongas
|
//Lord, foreach, aslongas
|
||||||
|
|
||||||
found = string::npos;
|
found = string::npos;
|
||||||
@@ -1710,12 +1779,18 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
string with = "";
|
string with = "";
|
||||||
|
string types = "";
|
||||||
vector<string> splitWith = parseBetween(s, "with(", ")");
|
vector<string> splitWith = parseBetween(s, "with(", ")");
|
||||||
if (splitWith.size())
|
if (splitWith.size())
|
||||||
{
|
{
|
||||||
with = splitWith[1];
|
with = splitWith[1];
|
||||||
}
|
}
|
||||||
MTGAbility * a = NEW AACloner(observer, id, card, target, 0, who, with);
|
vector<string> splitTypes = parseBetween(s, "addtype(", ")");
|
||||||
|
if (splitTypes.size())
|
||||||
|
{
|
||||||
|
types = splitTypes[1];
|
||||||
|
}
|
||||||
|
MTGAbility * a = NEW AACloner(observer, id, card, target, 0, who, with,types);
|
||||||
a->oneShot = 1;
|
a->oneShot = 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -1988,7 +2063,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
//combat damage spirit link
|
//combat damage spirit link
|
||||||
if (s.find("spiritlink") != string::npos)
|
if (s.find("spiritlink") != string::npos)
|
||||||
{
|
{
|
||||||
bool combatOnly = (s.find("combatspiritlink") != string::npos);
|
bool combatOnly = false;
|
||||||
|
if(s.find("combatspiritlink") != string::npos)
|
||||||
|
{
|
||||||
|
combatOnly = true;
|
||||||
|
}
|
||||||
return NEW ASpiritLinkAbility(observer, id, card, combatOnly);
|
return NEW ASpiritLinkAbility(observer, id, card, combatOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1996,13 +2075,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
vector<string> splitBushido = parseBetween(s, "bushido(", ")");
|
vector<string> splitBushido = parseBetween(s, "bushido(", ")");
|
||||||
if (splitBushido.size())
|
if (splitBushido.size())
|
||||||
{
|
{
|
||||||
int power, toughness;
|
string power, toughness;
|
||||||
if (!parsePowerToughness(splitBushido[1], &power, &toughness))
|
vector<string>splitPT = split(splitBushido[1],'/');
|
||||||
{
|
if(!splitPT.size())
|
||||||
DebugTrace("MTGAbility Parse error in bushido" << s);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
return NEW ABushidoAbility(observer, id, card,splitBushido[1]);
|
||||||
return NEW ABushidoAbility(observer, id, card, power, toughness);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//loseAbilities
|
//loseAbilities
|
||||||
@@ -2271,7 +2348,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
{
|
{
|
||||||
if (card->hasType(Subtypes::TYPE_INSTANT) || card->hasType(Subtypes::TYPE_SORCERY) || forceUEOT)
|
if (card->hasType(Subtypes::TYPE_INSTANT) || card->hasType(Subtypes::TYPE_SORCERY) || forceUEOT)
|
||||||
{
|
{
|
||||||
return NULL; //TODO
|
MTGAbility * aPF = NEW AProtectionFrom(observer, id, card, target, fromTc, splitProtection[1]);
|
||||||
|
return NEW GenericInstantAbility(observer, 1, card, (Damageable *) target, aPF);
|
||||||
}
|
}
|
||||||
return NEW AProtectionFrom(observer, id, card, target, fromTc, splitProtection[1]);
|
return NEW AProtectionFrom(observer, id, card, target, fromTc, splitProtection[1]);
|
||||||
}
|
}
|
||||||
@@ -2317,6 +2395,20 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
}
|
}
|
||||||
return NULL; //TODO
|
return NULL; //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//affinity based on targetchooser
|
||||||
|
vector<string> splitNewAffinity = parseBetween(s, "affinity(", ")");
|
||||||
|
if (splitNewAffinity.size())
|
||||||
|
{
|
||||||
|
string tcString = splitNewAffinity[1];
|
||||||
|
string manaString = "";
|
||||||
|
vector<string> splitNewAffinityMana = parseBetween(splitNewAffinity[2], "reduce(", ")");
|
||||||
|
if(splitNewAffinityMana.size())
|
||||||
|
manaString = splitNewAffinityMana[1];
|
||||||
|
if(!manaString.size())
|
||||||
|
return NULL;
|
||||||
|
return NEW ANewAffinity(observer, id, card, tcString, manaString);
|
||||||
|
}
|
||||||
|
|
||||||
//proliferate
|
//proliferate
|
||||||
found = s.find("proliferate");
|
found = s.find("proliferate");
|
||||||
@@ -2444,6 +2536,15 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
a->oneShot = 1;
|
a->oneShot = 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
found = s.find("steal");
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
MTGAbility * a = NEW AInstantControlSteal(observer, id, card, target);
|
||||||
|
a->oneShot = 1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
DebugTrace(" no matching ability found. " << s);
|
DebugTrace(" no matching ability found. " << s);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -2910,6 +3011,13 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
a->addToGame();
|
a->addToGame();
|
||||||
|
if (a->source)
|
||||||
|
a->source->cardsAbilities.push_back(a);
|
||||||
|
else if(spell && spell->source)
|
||||||
|
spell->source->cardsAbilities.push_back(a);
|
||||||
|
|
||||||
|
//keep track of abilities being added to the game on each card it belongs to, this ignores p/t bonuses given
|
||||||
|
//from other cards, or ability bonuses, making it generally easier to strip a card of it's abilities.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,16 +88,17 @@ void MTGCardInstance::copy(MTGCardInstance * card)
|
|||||||
delete spell;
|
delete spell;
|
||||||
mtgid = backupid;
|
mtgid = backupid;
|
||||||
castMethod = castMethodBackUP;
|
castMethod = castMethodBackUP;
|
||||||
|
backupTargets = this->backupTargets;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTGCardInstance::~MTGCardInstance()
|
MTGCardInstance::~MTGCardInstance()
|
||||||
{
|
{
|
||||||
SAFE_DELETE(counters);
|
SAFE_DELETE(counters);
|
||||||
if (previous != NULL)
|
if (previous != NULL)
|
||||||
{
|
{
|
||||||
//DebugTrace("MTGCardInstance::~MTGCardInstance(): deleting " << ToHex(previous));
|
//DebugTrace("MTGCardInstance::~MTGCardInstance(): deleting " << ToHex(previous));
|
||||||
SAFE_DELETE(previous);
|
SAFE_DELETE(previous);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int MTGCardInstance::init()
|
int MTGCardInstance::init()
|
||||||
@@ -147,6 +148,7 @@ void MTGCardInstance::initMTGCI()
|
|||||||
suspended = false;
|
suspended = false;
|
||||||
castMethod = Constants::NOT_CAST;
|
castMethod = Constants::NOT_CAST;
|
||||||
mPropertiesChangedSinceLastUpdate = false;
|
mPropertiesChangedSinceLastUpdate = false;
|
||||||
|
stillNeeded = true;
|
||||||
kicked = 0;
|
kicked = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -171,6 +173,7 @@ void MTGCardInstance::initMTGCI()
|
|||||||
regenerateTokens = 0;
|
regenerateTokens = 0;
|
||||||
blocked = false;
|
blocked = false;
|
||||||
currentZone = NULL;
|
currentZone = NULL;
|
||||||
|
cardsAbilities = vector<MTGAbility *>();
|
||||||
data = this; //an MTGCardInstance point to itself for data, allows to update it without killing the underlying database item
|
data = this; //an MTGCardInstance point to itself for data, allows to update it without killing the underlying database item
|
||||||
|
|
||||||
if (basicAbilities[(int)Constants::CHANGELING])
|
if (basicAbilities[(int)Constants::CHANGELING])
|
||||||
@@ -487,7 +490,11 @@ int MTGCardInstance::stillInUse()
|
|||||||
return 1;
|
return 1;
|
||||||
if (!previous)
|
if (!previous)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (previous->stillNeeded)
|
||||||
|
{
|
||||||
|
previous->stillNeeded = false;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return previous->stillInUse();
|
return previous->stillInUse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ const char* Constants::MTGBasicAbilities[] = {
|
|||||||
"snowislandlandwalk",
|
"snowislandlandwalk",
|
||||||
"snowswamplandwalk",
|
"snowswamplandwalk",
|
||||||
"canattack",
|
"canattack",
|
||||||
"hydra"
|
"hydra",
|
||||||
|
"undying"
|
||||||
};
|
};
|
||||||
|
|
||||||
map<string,int> Constants::MTGBasicAbilitiesMap;
|
map<string,int> Constants::MTGBasicAbilitiesMap;
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ MTGPlayerCards::~MTGPlayerCards()
|
|||||||
|
|
||||||
void MTGPlayerCards::beforeBeginPhase()
|
void MTGPlayerCards::beforeBeginPhase()
|
||||||
{
|
{
|
||||||
delete garbage;
|
SAFE_DELETE(garbageLastTurn);
|
||||||
garbage = NEW MTGGameZone();
|
garbageLastTurn = garbage = NEW MTGGameZone();
|
||||||
garbage->setOwner(this->owner);
|
garbage->setOwner(this->owner);
|
||||||
|
|
||||||
library->beforeBeginPhase();
|
library->beforeBeginPhase();
|
||||||
@@ -104,6 +104,7 @@ void MTGPlayerCards::setOwner(Player * player)
|
|||||||
removedFromGame->setOwner(player);
|
removedFromGame->setOwner(player);
|
||||||
stack->setOwner(player);
|
stack->setOwner(player);
|
||||||
garbage->setOwner(player);
|
garbage->setOwner(player);
|
||||||
|
garbageLastTurn->setOwner(player);
|
||||||
temp->setOwner(player);
|
temp->setOwner(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +244,8 @@ void MTGPlayerCards::drawFromLibrary()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
putInZone(toMove, library, hand);
|
if(putInZone(toMove, library, hand))
|
||||||
|
toMove->currentZone = hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTGPlayerCards::resetLibrary()
|
void MTGPlayerCards::resetLibrary()
|
||||||
@@ -264,6 +266,7 @@ void MTGPlayerCards::init()
|
|||||||
removedFromGame = NEW MTGRemovedFromGame();
|
removedFromGame = NEW MTGRemovedFromGame();
|
||||||
exile = removedFromGame;
|
exile = removedFromGame;
|
||||||
garbage = NEW MTGGameZone();
|
garbage = NEW MTGGameZone();
|
||||||
|
garbageLastTurn = garbage;
|
||||||
temp = NEW MTGGameZone();
|
temp = NEW MTGGameZone();
|
||||||
|
|
||||||
playRestrictions = NEW PlayRestrictions();
|
playRestrictions = NEW PlayRestrictions();
|
||||||
@@ -298,7 +301,6 @@ MTGCardInstance * MTGPlayerCards::putInHand(MTGCardInstance * card)
|
|||||||
return putInZone(card, card->currentZone, card->owner->game->hand);
|
return putInZone(card, card->currentZone, card->owner->game->hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Moves a card from one zone to another
|
// Moves a card from one zone to another
|
||||||
// If the card is not actually in the expected "from" zone, does nothing and returns null
|
// If the card is not actually in the expected "from" zone, does nothing and returns null
|
||||||
MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to)
|
MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to)
|
||||||
@@ -410,6 +412,8 @@ MTGGameZone::~MTGGameZone()
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < cards.size(); i++)
|
for (size_t i = 0; i < cards.size(); i++)
|
||||||
{
|
{
|
||||||
|
cards[i]->stillNeeded = false;
|
||||||
|
SAFE_DELETE(cards[i]->previous);
|
||||||
SAFE_DELETE( cards[i] );
|
SAFE_DELETE( cards[i] );
|
||||||
}
|
}
|
||||||
cards.clear();
|
cards.clear();
|
||||||
@@ -419,6 +423,11 @@ MTGGameZone::~MTGGameZone()
|
|||||||
|
|
||||||
void MTGGameZone::beforeBeginPhase()
|
void MTGGameZone::beforeBeginPhase()
|
||||||
{
|
{
|
||||||
|
cardsSeenLastTurn.clear();
|
||||||
|
for(size_t k = 0; k < cardsSeenThisTurn.size(); k++)
|
||||||
|
{
|
||||||
|
cardsSeenLastTurn.push_back(cardsSeenThisTurn[k]);
|
||||||
|
}
|
||||||
cardsSeenThisTurn.clear();
|
cardsSeenThisTurn.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -631,18 +640,30 @@ bool MTGGameZone::hasAbility(int ability)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MTGGameZone::seenThisTurn(TargetChooser * tc, int castMethod)
|
int MTGGameZone::seenThisTurn(TargetChooser * tc, int castMethod, bool lastTurn)
|
||||||
{
|
{
|
||||||
//The following 2 lines modify the passed TargetChooser. Call this function with care :/
|
//The following 2 lines modify the passed TargetChooser. Call this function with care :/
|
||||||
tc->setAllZones(); // This is to allow targetting cards without caring about the actual zone
|
tc->setAllZones(); // This is to allow targetting cards without caring about the actual zone
|
||||||
tc->targetter = NULL;
|
tc->targetter = NULL;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (vector<MTGCardInstance *>::iterator iter = cardsSeenThisTurn.begin(); iter != cardsSeenThisTurn.end(); ++iter)
|
if (lastTurn)
|
||||||
{
|
{
|
||||||
MTGCardInstance * c = (*iter);
|
for (vector<MTGCardInstance *>::iterator iter = cardsSeenLastTurn.begin(); iter != cardsSeenLastTurn.end(); ++iter)
|
||||||
if (c->matchesCastFilter(castMethod) && tc->canTarget(c))
|
{
|
||||||
count++;
|
MTGCardInstance * c = (*iter);
|
||||||
|
if (c && c->matchesCastFilter(castMethod) && tc->canTarget(c))
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (vector<MTGCardInstance *>::iterator iter = cardsSeenThisTurn.begin(); iter != cardsSeenThisTurn.end(); ++iter)
|
||||||
|
{
|
||||||
|
MTGCardInstance * c = (*iter);
|
||||||
|
if (c->matchesCastFilter(castMethod) && tc->canTarget(c))
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@@ -651,11 +672,19 @@ int MTGGameZone::seenThisTurn(string targetChooserDefinition, int castMethod)
|
|||||||
{
|
{
|
||||||
TargetChooserFactory tcf(owner->getObserver());
|
TargetChooserFactory tcf(owner->getObserver());
|
||||||
TargetChooser *tc = tcf.createTargetChooser(targetChooserDefinition, NULL);
|
TargetChooser *tc = tcf.createTargetChooser(targetChooserDefinition, NULL);
|
||||||
int result = seenThisTurn(tc, castMethod);
|
int result = seenThisTurn(tc, castMethod,false);
|
||||||
delete(tc);
|
SAFE_DELETE(tc);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MTGGameZone::seenLastTurn(string targetChooserDefinition, int castMethod)
|
||||||
|
{
|
||||||
|
TargetChooserFactory tcf(owner->getObserver());
|
||||||
|
TargetChooser *tc = tcf.createTargetChooser(targetChooserDefinition, NULL);
|
||||||
|
int result = seenThisTurn(tc, castMethod,true);
|
||||||
|
SAFE_DELETE(tc);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void MTGGameZone::cleanupPhase()
|
void MTGGameZone::cleanupPhase()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1822,9 +1822,10 @@ int MTGPersistRule::receiveEvent(WEvent * event)
|
|||||||
{
|
{
|
||||||
WEventZoneChange * e = (WEventZoneChange *) event;
|
WEventZoneChange * e = (WEventZoneChange *) event;
|
||||||
MTGCardInstance * card = e->card->previous;
|
MTGCardInstance * card = e->card->previous;
|
||||||
if (card && card->basicAbilities[(int)Constants::PERSIST] && !card->counters->hasCounter(-1, -1))
|
if (!card) return 0;
|
||||||
|
int ok = 0;
|
||||||
|
if((card->basicAbilities[(int)Constants::PERSIST] && !card->counters->hasCounter(-1, -1))||(card->basicAbilities[(int)Constants::UNDYING] && !card->counters->hasCounter(1, 1)))
|
||||||
{
|
{
|
||||||
int ok = 0;
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
Player * p = game->players[i];
|
Player * p = game->players[i];
|
||||||
@@ -1833,20 +1834,24 @@ int MTGPersistRule::receiveEvent(WEvent * event)
|
|||||||
}
|
}
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
Player * p = game->players[i];
|
Player * p = game->players[i];
|
||||||
if (e->to == p->game->graveyard)
|
if (e->to == p->game->graveyard)
|
||||||
{
|
{
|
||||||
MTGCardInstance * copy = p->game->putInZone(e->card, p->game->graveyard, e->card->owner->game->temp);
|
MTGCardInstance * copy = p->game->putInZone(e->card, p->game->graveyard, e->card->owner->game->temp);
|
||||||
if (!copy)
|
if (!copy)
|
||||||
{
|
{
|
||||||
DebugTrace("MTGRULES: couldn't move card for persist");
|
DebugTrace("MTGRULES: couldn't move card for persist/undying");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Spell * spell = NEW Spell(game, copy);
|
Spell * spell = NEW Spell(game, copy);
|
||||||
spell->resolve();
|
spell->resolve();
|
||||||
spell->source->counters->addCounter(-1, -1);
|
if(card->basicAbilities[(int)Constants::PERSIST])
|
||||||
|
spell->source->counters->addCounter(-1, -1);
|
||||||
|
else
|
||||||
|
spell->source->counters->addCounter(1,1);
|
||||||
delete spell;
|
delete spell;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -371,6 +371,20 @@ int ManaCost::hasX()
|
|||||||
return cost[Constants::NB_Colors];
|
return cost[Constants::NB_Colors];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ManaCost::hasAnotherCost()
|
||||||
|
{
|
||||||
|
if (cost.size() <= (size_t)Constants::NB_Colors)
|
||||||
|
{
|
||||||
|
DebugTrace("Seems ManaCost was not properly initialized");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int result = 0;
|
||||||
|
if(kicker)
|
||||||
|
result = 1;
|
||||||
|
//kicker is the only one ai knows for now, later hasAnotherCost() can be used to determine other cost types.
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void ManaCost::init()
|
void ManaCost::init()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -26,6 +26,19 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
|
|||||||
return NEW CardTargetChooser(observer, target, card);
|
return NEW CardTargetChooser(observer, target, card);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
found = s.find("targetedplayer");
|
||||||
|
if (found == 0)
|
||||||
|
{
|
||||||
|
if(card && card->backupTargets.size())
|
||||||
|
{
|
||||||
|
Player * pTarget = dynamic_cast<Player*>(card->backupTargets[0]);
|
||||||
|
if (ability)
|
||||||
|
pTarget = dynamic_cast<Player*>(ability->target);
|
||||||
|
if(pTarget)
|
||||||
|
return NEW PlayerTargetChooser(observer, card, 1, pTarget);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
found = s.find("opponent");
|
found = s.find("opponent");
|
||||||
if (found == 0)
|
if (found == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user