6399917d25
added abilities:
proliferate
ProliferateChooser:new targetchooser for cards with counter and poison counters "proliferation".
MenuAbility:new internal ability to create custom menus of abilities which can be activated in sequence one after another.
multikicker, syntax kicker=multi{b}
works with variable word "kicked", the amount of times it was kicked.
target=<number>tc,target=<upto:>tc,target=<anyamount>tc,target(<number>tc),target(<upto:>tc),target(<anynumber>tc);
multitarget is now supported with the exception of "devided any way you choose" which can not be supported becuase we allow detoggling of targeted cards with a "second" click....so you can not click the same card 2 times to add it to the targets list twice for example.
this is minor, as the bulk of multitarget is not "devided"
removed 's' parsing for multitarget, added a limit of 1000 to "unlimited" for easier handling; we currently can't handle activation of an ability on a 1000 cards very well on any platform(infact i don't suggest it)
Countershroud(counterstring), this MTGAbility allows you to denote that a card can not have counters of the type "counterstring" put on it.
"any" is for no counters allowed at all. this is a replacement effect. cards state that they can still be the targets of counter effects, however on resolve nothing is placed on them instead.
@counteradded(counterstring) from(target):,@counterremoved(counterstring) from(target):: these are triggers for cards which state "whenever you add a counter of "counterstring" to "target"; added counterEvents struct;
other changes:
added support for ai handling of multitargeted spells.
changed a few of delete( into SAFE_DELETE(, safed up a couple areas where they did not seem safe to me;
added better handling of menus presented to ai, it will try to select the best based on eff returns.
added varible lastactioncontroller for ai use, it keeps it truely from ever tripping over itself and brings ai more inline with MTG rules.
converted TC into a protected member.
added "abilitybelongsto" string to tc, and set "owner" of the tc. a tc should never belong to "no one" it should always have a owner.
abilitybelongs to string is solely for easier debugging, i found it was a pain to never know what ability created a tc while i coded multitarget. the owner of the tc is the only one that should be using it, if an ability needs to declare the opponent as the owner (choose discard which is currently unsupported for example) this will allow us to better handle that situation by setting the tc owner in the ability which called it.
rewrote the logic of "checkonly" in ai choose targets, the only time it is "checkonly" is when it is trying to see if it had a target for a spell before it cast it, i now set this in the actual function call instead, the old method was far to error prone.
wrote logic for ai checking of menu objects presented to it,
ai will now make better choices when a menu is presented to it based on what it already knows. this changes it from it's old method of "just click the first option".
taught ai how to use multi-mana producers such as birds and duel lands by adding a method for it to find it's mana for a payment. it can effectively use cards like birds of paradise and sol ring(without locking up). It's primary method of pMana searching was maintain for performance(no need to deep search if we have it in pMana).
added a vector to actionlayer to store mana abilities for pMana. this provides us with a dramatic improvement when mana lords are present by reducing the amount of objects that need checking when ai checks pMana.
with 80 mana objects and a ton of lords one instance i checked went from 8000ish checks down to 80<===big difference.
added "tapped" green coloring(sorry i missed that!)...added red coloring to current actionLayers current action card (usually the source).
changed "type(" restrictions second amount from atoi into wparsedint for more flexiable coding.
add "&" parsing to CD targetchooser, removed "iscolorandcolor" variables and functions becuase they were a hack the real fix was this.
cretaure[dragon&black&blue] a creature that is a dragon, and black and also blue.
changed some of the ai computeactions and
removed unneeded gaurds in ai chooseblockers, they did more harm then good.
793 lines
16 KiB
C++
793 lines
16 KiB
C++
#include "PrecompiledHeader.h"
|
|
|
|
#include "ExtraCost.h"
|
|
#include "TargetChooser.h"
|
|
#include "MTGCardInstance.h"
|
|
#include "Translate.h"
|
|
#include "Player.h"
|
|
#include "Counters.h"
|
|
|
|
SUPPORT_OBJECT_ANALYTICS(ExtraCost)
|
|
|
|
ExtraCost::ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc)
|
|
: tc(_tc), source(NULL), target(NULL), mCostRenderString(inCostRenderString)
|
|
{
|
|
if (tc)
|
|
tc->targetter = NULL;
|
|
}
|
|
|
|
ExtraCost::~ExtraCost()
|
|
{
|
|
SAFE_DELETE(tc);
|
|
}
|
|
|
|
int ExtraCost::setSource(MTGCardInstance * _source)
|
|
{
|
|
source = _source;
|
|
if (tc)
|
|
{
|
|
tc->source = _source;
|
|
// this keeps the target chooser from being unable to select a creature with shroud/protections.
|
|
tc->targetter = NULL;
|
|
}
|
|
else
|
|
{
|
|
target = _source;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void ExtraCost::Render()
|
|
{
|
|
if (!mCostRenderString.empty())
|
|
{
|
|
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
|
mFont->SetColor(ARGB(255,255,255,255));
|
|
mFont->DrawString(mCostRenderString, 20, 20, JGETEXT_LEFT);
|
|
}
|
|
}
|
|
|
|
int ExtraCost::setPayment(MTGCardInstance * card)
|
|
{
|
|
int result = 0;
|
|
if (tc)
|
|
{
|
|
result = tc->addTarget(card);
|
|
if (result)
|
|
{
|
|
target = card;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
//life cost
|
|
LifeCost * LifeCost::clone() const
|
|
{
|
|
LifeCost * ec = NEW LifeCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
LifeCost::LifeCost(TargetChooser *_tc)
|
|
: ExtraCost("Life", _tc)
|
|
{
|
|
}
|
|
|
|
int LifeCost::canPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
if(_target->controller()->life <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int LifeCost::doPay()
|
|
{
|
|
if (!target)
|
|
return 0;
|
|
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
|
|
_target->controller()->loseLife(1);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
|
|
//life or Mana cost
|
|
LifeorManaCost * LifeorManaCost::clone() const
|
|
{
|
|
LifeorManaCost * ec = NEW LifeorManaCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
LifeorManaCost::LifeorManaCost(TargetChooser *_tc,string manaType)
|
|
: ExtraCost("Phyrexian Mana", _tc), manaType(manaType)
|
|
{
|
|
}
|
|
|
|
int LifeorManaCost::canPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
string buildType ="{";
|
|
buildType.append(manaType);
|
|
buildType.append("}");
|
|
ManaCost * newCost = ManaCost::parseManaCost(buildType);
|
|
if(_target->controller()->getManaPool()->canAfford(newCost) || _target->controller()->life > 1)
|
|
{
|
|
SAFE_DELETE(newCost);
|
|
return 1;
|
|
}
|
|
SAFE_DELETE(newCost);
|
|
return 0;
|
|
}
|
|
|
|
int LifeorManaCost::doPay()
|
|
{
|
|
if (!target)
|
|
return 0;
|
|
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
string buildType ="{";
|
|
buildType.append(manaType);
|
|
buildType.append("}");
|
|
ManaCost * newCost = ManaCost::parseManaCost(buildType);
|
|
if(_target->controller()->getManaPool()->canAfford(newCost))
|
|
{
|
|
_target->controller()->getManaPool()->pay(newCost);
|
|
}
|
|
else
|
|
{
|
|
_target->controller()->loseLife(2);
|
|
}
|
|
SAFE_DELETE(newCost);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
//discard a card at random as a cost
|
|
//DiscardRandom cost
|
|
DiscardRandomCost * DiscardRandomCost::clone() const
|
|
{
|
|
DiscardRandomCost * ec = NEW DiscardRandomCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc)
|
|
: ExtraCost("Discard Random", _tc)
|
|
{
|
|
}
|
|
|
|
int DiscardRandomCost::canPay()
|
|
{
|
|
MTGGameZone * z = target->controller()->game->hand;
|
|
int nbcards = z->nb_cards;
|
|
if (nbcards < 1)
|
|
return 0;
|
|
if (nbcards == 1 && z->hasCard(source))
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
int DiscardRandomCost::doPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
if (target)
|
|
{
|
|
_target->controller()->game->discardRandom(_target->controller()->game->hand, source);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
//a choosen discard
|
|
|
|
DiscardCost * DiscardCost::clone() const
|
|
{
|
|
DiscardCost * ec = NEW DiscardCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
DiscardCost::DiscardCost(TargetChooser *_tc) :
|
|
ExtraCost("Choose card to Discard", _tc)
|
|
{
|
|
}
|
|
|
|
int DiscardCost::doPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
if (target)
|
|
{
|
|
WEvent * e = NEW WEventCardDiscard(target);
|
|
GameObserver * game = GameObserver::GetInstance();
|
|
game->receiveEvent(e);
|
|
_target->controller()->game->putInGraveyard(_target);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
//to library cost
|
|
|
|
ToLibraryCost * ToLibraryCost::clone() const
|
|
{
|
|
ToLibraryCost * ec = NEW ToLibraryCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
ToLibraryCost::ToLibraryCost(TargetChooser *_tc)
|
|
: ExtraCost("Put a card on top of Library", _tc)
|
|
{
|
|
}
|
|
|
|
int ToLibraryCost::doPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
if (target)
|
|
{
|
|
_target->controller()->game->putInLibrary(target);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//Mill yourself as a cost
|
|
MillCost * MillCost::clone() const
|
|
{
|
|
MillCost * ec = NEW MillCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
MillCost::MillCost(TargetChooser *_tc)
|
|
: ExtraCost("Deplete", _tc)
|
|
{
|
|
}
|
|
|
|
int MillCost::canPay()
|
|
{
|
|
MTGGameZone * z = target->controller()->game->library;
|
|
int nbcards = z->nb_cards;
|
|
if (nbcards < 1)
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
int MillCost::doPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
if (target)
|
|
{
|
|
_target->controller()->game->putInZone(
|
|
_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1],
|
|
_target->controller()->game->library, _target->controller()->game->graveyard);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
MillExileCost::MillExileCost(TargetChooser *_tc)
|
|
: MillCost(_tc)
|
|
{
|
|
// override the base string here
|
|
mCostRenderString = "Deplete To Exile";
|
|
}
|
|
|
|
int MillExileCost::doPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
if (target)
|
|
{
|
|
_target->controller()->game->putInZone(
|
|
_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1],
|
|
_target->controller()->game->library, _target->controller()->game->exile);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//Tap cost
|
|
TapCost * TapCost::clone() const
|
|
{
|
|
TapCost * ec = NEW TapCost(*this);
|
|
return ec;
|
|
}
|
|
|
|
TapCost::TapCost()
|
|
: ExtraCost("Tap")
|
|
{
|
|
}
|
|
|
|
int TapCost::isPaymentSet()
|
|
{
|
|
if (source && (source->isTapped() || source->hasSummoningSickness()))
|
|
{
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int TapCost::canPay()
|
|
{
|
|
return isPaymentSet();
|
|
}
|
|
|
|
int TapCost::doPay()
|
|
{
|
|
MTGCardInstance * _source = (MTGCardInstance *) source;
|
|
if (_source)
|
|
{
|
|
_source->tap();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
//unTap cost
|
|
UnTapCost * UnTapCost::clone() const
|
|
{
|
|
UnTapCost * ec = NEW UnTapCost(*this);
|
|
return ec;
|
|
}
|
|
|
|
UnTapCost::UnTapCost() :
|
|
ExtraCost("UnTap")
|
|
{
|
|
}
|
|
|
|
int UnTapCost::isPaymentSet()
|
|
{
|
|
if (source && !source->isTapped())
|
|
{
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int UnTapCost::canPay()
|
|
{
|
|
return isPaymentSet();
|
|
}
|
|
|
|
int UnTapCost::doPay()
|
|
{
|
|
MTGCardInstance * _source = (MTGCardInstance *) source;
|
|
if (_source)
|
|
{
|
|
_source->untap();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//Tap target cost
|
|
TapTargetCost * TapTargetCost::clone() const
|
|
{
|
|
TapTargetCost * ec = NEW TapTargetCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
TapTargetCost::TapTargetCost(TargetChooser *_tc)
|
|
: ExtraCost("Tap Target", _tc)
|
|
{
|
|
}
|
|
|
|
int TapTargetCost::isPaymentSet()
|
|
{
|
|
if (target && target->isTapped())
|
|
{
|
|
tc->removeTarget(target);
|
|
target->isExtraCostTarget = false;
|
|
target = NULL;
|
|
return 0;
|
|
}
|
|
if (target)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
int TapTargetCost::doPay()
|
|
{
|
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
|
if (target)
|
|
{
|
|
_target->tap();
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//exile as cost
|
|
ExileTargetCost * ExileTargetCost::clone() const
|
|
{
|
|
ExileTargetCost * ec = NEW ExileTargetCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
ExileTargetCost::ExileTargetCost(TargetChooser *_tc)
|
|
: ExtraCost("Exile Target", _tc)
|
|
{
|
|
}
|
|
|
|
int ExileTargetCost::doPay()
|
|
{
|
|
|
|
if (target)
|
|
{
|
|
target->controller()->game->putInExile(target);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//Bounce as cost
|
|
BounceTargetCost * BounceTargetCost::clone() const
|
|
{
|
|
BounceTargetCost * ec = NEW BounceTargetCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
BounceTargetCost::BounceTargetCost(TargetChooser *_tc)
|
|
: ExtraCost("Return Target to Hand", _tc)
|
|
{
|
|
}
|
|
|
|
int BounceTargetCost::doPay()
|
|
{
|
|
|
|
if (target)
|
|
{
|
|
target->controller()->game->putInHand(target);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//Bounce as cost for ninja
|
|
Ninja * Ninja::clone() const
|
|
{
|
|
Ninja * ec = NEW Ninja(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
Ninja::Ninja(TargetChooser *_tc) :
|
|
ExtraCost("Select unblocked attacker", _tc)
|
|
{
|
|
}
|
|
|
|
int Ninja::isPaymentSet()
|
|
{
|
|
GameObserver * g = GameObserver::GetInstance();
|
|
int currentPhase = g->getCurrentGamePhase();
|
|
if (target && ((target->isAttacker() && target->blocked) || target->isAttacker() < 1 || currentPhase
|
|
!= Constants::MTG_PHASE_COMBATBLOCKERS))
|
|
{
|
|
tc->removeTarget(target);
|
|
target = NULL;
|
|
return 0;
|
|
}
|
|
if (target)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
int Ninja::doPay()
|
|
{
|
|
if (target)
|
|
{
|
|
target->controller()->game->putInHand(target);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//endbouncetargetcostforninja
|
|
//------------------------------------------------------------
|
|
|
|
SacrificeCost * SacrificeCost::clone() const
|
|
{
|
|
SacrificeCost * ec = NEW SacrificeCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
return ec;
|
|
}
|
|
|
|
SacrificeCost::SacrificeCost(TargetChooser *_tc)
|
|
: ExtraCost("Sacrifice", _tc)
|
|
{
|
|
}
|
|
|
|
int SacrificeCost::doPay()
|
|
{
|
|
if (target)
|
|
{
|
|
WEvent * e = NEW WEventCardSacrifice(target);
|
|
GameObserver * game = GameObserver::GetInstance();
|
|
game->receiveEvent(e);
|
|
target->controller()->game->putInGraveyard(target);
|
|
target = NULL;
|
|
if (tc)
|
|
tc->initTargets();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//Counter costs
|
|
|
|
CounterCost * CounterCost::clone() const
|
|
{
|
|
CounterCost * ec = NEW CounterCost(*this);
|
|
if (tc)
|
|
ec->tc = tc->clone();
|
|
if (counter)
|
|
ec->counter = NEW Counter(counter->target, counter->name.c_str(), counter->power, counter->toughness);
|
|
ec->counter->nb = counter->nb;
|
|
return ec;
|
|
}
|
|
|
|
CounterCost::CounterCost(Counter * _counter, TargetChooser *_tc) :
|
|
ExtraCost("Counters", _tc)
|
|
{
|
|
counter = _counter;
|
|
hasCounters = 0;
|
|
}
|
|
|
|
int CounterCost::setPayment(MTGCardInstance *card)
|
|
{
|
|
if (tc)
|
|
{
|
|
int result = tc->addTarget(card);
|
|
if (result)
|
|
{
|
|
if (counter->nb >= 0)
|
|
return 1; //add counters always possible
|
|
target = card;
|
|
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(), counter->power, counter->toughness);
|
|
if (targetCounter && targetCounter->nb >= -counter->nb)
|
|
{
|
|
hasCounters = 1;
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int CounterCost::isPaymentSet()
|
|
{
|
|
if (!target)
|
|
return 0;
|
|
if (counter->nb >= 0)
|
|
return 1; //add counters always possible
|
|
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(), counter->power, counter->toughness);
|
|
if (targetCounter && targetCounter->nb >= -counter->nb)
|
|
{
|
|
hasCounters = 1;
|
|
}
|
|
if (target && hasCounters)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
int CounterCost::canPay()
|
|
{
|
|
// if target needs to be chosen, then move on.
|
|
if (tc)
|
|
return 1;
|
|
if (counter->nb >= 0)
|
|
return 1; //add counters always possible
|
|
// otherwise, move on only if target has enough counters
|
|
Counter * targetCounter = target->counters->hasCounter(counter->name.c_str(), counter->power, counter->toughness);
|
|
if (targetCounter && targetCounter->nb >= -counter->nb)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
int CounterCost::doPay()
|
|
{
|
|
if (!target)
|
|
return 0;
|
|
|
|
if (counter->nb >= 0)
|
|
{ //Add counters as a cost
|
|
for (int i = 0; i < counter->nb; i++)
|
|
{
|
|
target->counters->addCounter(counter->name.c_str(), counter->power, counter->toughness);
|
|
}
|
|
if (tc)
|
|
tc->initTargets();
|
|
target = NULL;
|
|
return 1;
|
|
}
|
|
|
|
//remove counters as a cost
|
|
if (hasCounters)
|
|
{
|
|
for (int i = 0; i < -counter->nb; i++)
|
|
{
|
|
target->counters->removeCounter(counter->name.c_str(), counter->power, counter->toughness);
|
|
}
|
|
hasCounters = 0;
|
|
if (tc)
|
|
tc->initTargets();
|
|
target = NULL;
|
|
return 1;
|
|
}
|
|
if (tc)
|
|
tc->initTargets();
|
|
target = NULL;
|
|
return 0;
|
|
}
|
|
|
|
CounterCost::~CounterCost()
|
|
{
|
|
SAFE_DELETE(counter);
|
|
}
|
|
|
|
//
|
|
//Container
|
|
//
|
|
ExtraCosts::ExtraCosts()
|
|
{
|
|
action = NULL;
|
|
source = NULL;
|
|
}
|
|
|
|
ExtraCosts * ExtraCosts::clone() const
|
|
{
|
|
ExtraCosts * ec = NEW ExtraCosts(*this);
|
|
ec->costs.clear();
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
ec->costs.push_back(costs[i]->clone());
|
|
}
|
|
return ec;
|
|
}
|
|
|
|
void ExtraCosts::Render()
|
|
{
|
|
//TODO cool window and stuff...
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
costs[i]->Render();
|
|
}
|
|
}
|
|
|
|
int ExtraCosts::setAction(MTGAbility * _action, MTGCardInstance * _card)
|
|
{
|
|
action = _action;
|
|
source = _card;
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
costs[i]->setSource(_card);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int ExtraCosts::reset()
|
|
{
|
|
action = NULL;
|
|
source = NULL;
|
|
//TODO set all payments to "unset"
|
|
return 1;
|
|
}
|
|
|
|
int ExtraCosts::tryToSetPayment(MTGCardInstance * card)
|
|
{
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
if(!costs[i]->isPaymentSet())
|
|
{
|
|
for(size_t k = 0; k < costs.size(); k++)
|
|
{
|
|
if(card == costs[k]->target)
|
|
return 0;
|
|
}
|
|
if (int result = costs[i]->setPayment(card))
|
|
{
|
|
card->isExtraCostTarget = true;
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int ExtraCosts::isPaymentSet()
|
|
{
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
if (!costs[i]->isPaymentSet())
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int ExtraCosts::canPay()
|
|
{
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
if (!costs[i]->canPay())
|
|
{
|
|
costs[i]->target->isExtraCostTarget = false;
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int ExtraCosts::doPay()
|
|
{
|
|
int result = 0;
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
if(costs[i]->target)
|
|
costs[i]->target->isExtraCostTarget = false;
|
|
result += costs[i]->doPay();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
ExtraCosts::~ExtraCosts()
|
|
{
|
|
for (size_t i = 0; i < costs.size(); i++)
|
|
{
|
|
SAFE_DELETE(costs[i]);
|
|
}
|
|
}
|
|
|
|
void ExtraCosts::Dump()
|
|
{
|
|
DebugTrace("=====\nDumping ExtraCosts=====\n");
|
|
DebugTrace("NbElements: " << costs.size());
|
|
}
|