Block Cost Rule

Update rules folder
This commit is contained in:
Anthony Calosa
2016-06-15 22:26:55 +08:00
parent a2249a7392
commit b38275123a
14 changed files with 238 additions and 43 deletions
+57 -2
View File
@@ -5372,8 +5372,8 @@ APhaseActionGeneric::~APhaseActionGeneric()
}
//AAttackSetCost
AAttackSetCost::AAttackSetCost(GameObserver* observer, int _id, MTGCardInstance * _source, string number) :
MTGAbility(observer, _id, _source), number(number)
AAttackSetCost::AAttackSetCost(GameObserver* observer, int _id, MTGCardInstance * _source, string number, bool pw) :
MTGAbility(observer, _id, _source), number(number), pw(pw)
{
}
@@ -5382,6 +5382,8 @@ void AAttackSetCost::Update(float dt)
if(game->getCurrentGamePhase() != MTG_PHASE_COMBATATTACKERS)
{
source->attackCost = source->attackCostBackup;
if(pw)
source->attackPlaneswalkerCost = source->attackPlaneswalkerCostBackup;
MTGAbility::Update(dt);
}
}
@@ -5391,6 +5393,11 @@ int AAttackSetCost::addToGame()
WParsedInt attackcost(number, NULL, source);
source->attackCost += attackcost.getValue();
source->attackCostBackup += attackcost.getValue();
if(pw)
{
source->attackPlaneswalkerCost += attackcost.getValue();
source->attackPlaneswalkerCostBackup += attackcost.getValue();
}
return MTGAbility::addToGame();
}
@@ -5401,6 +5408,11 @@ int AAttackSetCost::destroy()
WParsedInt attackcost(number, NULL, source);
source->attackCost -= attackcost.getValue();
source->attackCostBackup -= attackcost.getValue();
if(pw)
{
source->attackPlaneswalkerCost -= attackcost.getValue();
source->attackPlaneswalkerCostBackup -= attackcost.getValue();
}
return 1;
}
@@ -5415,6 +5427,49 @@ AAttackSetCost * AAttackSetCost::clone() const
return NEW AAttackSetCost(*this);
}
//ABlockSetCost
ABlockSetCost::ABlockSetCost(GameObserver* observer, int _id, MTGCardInstance * _source, string number) :
MTGAbility(observer, _id, _source), number(number)
{
}
void ABlockSetCost::Update(float dt)
{
if(game->getCurrentGamePhase() != MTG_PHASE_COMBATBLOCKERS)
{
source->blockCost = source->blockCostBackup;
MTGAbility::Update(dt);
}
}
int ABlockSetCost::addToGame()
{
WParsedInt blockCost(number, NULL, source);
source->blockCost += blockCost.getValue();
source->blockCostBackup += blockCost.getValue();
return MTGAbility::addToGame();
}
int ABlockSetCost::destroy()
{
WParsedInt blockCost(number, NULL, source);
source->blockCost -= blockCost.getValue();
source->blockCostBackup -= blockCost.getValue();
return 1;
}
const string ABlockSetCost::getMenuText()
{
return "Block Cost";
}
ABlockSetCost * ABlockSetCost::clone() const
{
return NEW ABlockSetCost(*this);
}
//a blink
ABlink::ABlink(GameObserver* observer, int _id, MTGCardInstance * card, MTGCardInstance * _target, bool blinkueot, bool blinkForSource, bool blinkhand, MTGAbility * stored) :
+19
View File
@@ -1193,6 +1193,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
observer->addObserver(NEW MTGBlockRule(observer, -1));
return NULL;
}
//this rule handles blocking cost ability during blocker phase
found = s.find("blockcostrule");
if(found != string::npos)
{
observer->addObserver(NEW MTGBlockCostRule(observer, -1));
return NULL;
}
//this rule handles cards that have soulbond
found = s.find("soulbondrule");
if(found != string::npos)
@@ -2842,6 +2849,18 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
return NEW AAttackSetCost(observer, id, card, s.substr(11));
}
//attack cost + planeswalker
if (s.find("attackpwcost:") != string::npos)
{
return NEW AAttackSetCost(observer, id, card, s.substr(13),true);
}
//block cost
if (s.find("blockcost:") != string::npos)
{
return NEW ABlockSetCost(observer, id, card, s.substr(10));
}
//flanking
if (s.find("flanker") != string::npos)
{
+3
View File
@@ -212,6 +212,9 @@ void MTGCardInstance::initMTGCI()
attackCost = 0;
attackCostBackup = 0;
attackPlaneswalkerCost = 0;
attackPlaneswalkerCostBackup = 0;
blockCost = 0;
blockCostBackup = 0;
imprintG = 0;
imprintU = 0;
imprintR = 0;
+83 -3
View File
@@ -1348,6 +1348,7 @@ MTGOverloadRule * MTGOverloadRule::clone() const
///////////////////////////////////////////////////////////////////////////////////////////////////
//ATTACK COST
MTGAttackCostRule::MTGAttackCostRule(GameObserver* observer, int _id) :
PermanentAbility(observer, _id)
{
@@ -1387,9 +1388,17 @@ int MTGAttackCostRule::reactToClick(MTGCardInstance * card)
ManaCost * attackcost = NEW ManaCost(ManaCost::parseManaCost("{0}",NULL,NULL));
attackcost->add(0,card->attackCostBackup);
ManaCost * playerMana = player->getManaPool();
playerMana->pay(attackcost);
playerMana->pay(attackcost);//I think you can't pay partial cost to attack cost so you pay full (508.1i)
card->attackCost = 0;
card->attackPlaneswalkerCost = 0;
return 1;
/*
508.1g: If any of the chosen creatures require paying costs to attack, the active player determines the total cost to attack.
Costs may include paying mana, tapping permanents, sacrificing permanents, discarding cards, and so on. Once the total cost is determined, it becomes locked in.
If effects would change the total cost after this time, ignore this change.
508.1h: If any of the costs require mana, the active player then has a chance to activate mana abilities (see rule 605, Mana Abilities).
508.1i: Once the player has enough mana in his or her mana pool, he or she pays all costs in any order. Partial payments are not allowed.
*/
}
ostream& MTGAttackCostRule::toString(ostream& out) const
@@ -1409,6 +1418,77 @@ MTGAttackCostRule * MTGAttackCostRule::clone() const
return NEW MTGAttackCostRule(*this);
}
//BLOCK COST
MTGBlockCostRule::MTGBlockCostRule(GameObserver* observer, int _id) :
PermanentAbility(observer, _id)
{
aType = MTGAbility::BLOCK_COST;
scost = "Pay to block";
}
int MTGBlockCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *)
{
if (currentPhase == MTG_PHASE_COMBATBLOCKERS && !game->isInterrupting
&& card->controller() != game->currentPlayer
)
{
if(card->isPhased)
return 0;
if(card->blockCost < 1)
return 0;
ManaCost * playerMana = card->controller()->getManaPool();
ManaCost * blockcost = NEW ManaCost(ManaCost::parseManaCost("{0}",NULL,NULL));
blockcost->add(0,card->blockCostBackup);
if(blockcost->extraCosts)
for(unsigned int i = 0; i < blockcost->extraCosts->costs.size();i++)
{
blockcost->extraCosts->costs[i]->setSource(card);
}
scost = blockcost->getConvertedCost();
if (playerMana->canAfford(blockcost))
return 1;
}
return 0;
}
int MTGBlockCostRule::reactToClick(MTGCardInstance * card)
{
if (!isReactingToClick(card))
return 0;
Player * player = game->currentlyActing();
ManaCost * blockcost = NEW ManaCost(ManaCost::parseManaCost("{0}",NULL,NULL));
blockcost->add(0,card->blockCostBackup);
ManaCost * playerMana = player->getManaPool();
playerMana->pay(blockcost);//I think you can't pay partial cost to block cost so you pay full (509.1f)
card->blockCost = 0;
return 1;
/*
509.1d: If any of the chosen creatures require paying costs to block, the defending player determines the total cost to block.
Costs may include paying mana, tapping permanents, sacrificing permanents, discarding cards, and so on.
Once the total cost is determined, it becomes locked in. If effects would change the total cost after this time, ignore this change.
509.1e: If any of the costs require mana, the defending player then has a chance to activate mana abilities (see rule 605, Mana Abilities).
509.1f: Once the player has enough mana in his or her mana pool, he or she pays all costs in any order. Partial payments are not allowed.
*/
}
ostream& MTGBlockCostRule::toString(ostream& out) const
{
out << "MTGBlockCostRule ::: (";
return MTGAbility::toString(out) << ")";
}
const string MTGBlockCostRule::getMenuText()
{
sprintf(menuText, "Pay to block");
return menuText;
}
MTGBlockCostRule * MTGBlockCostRule::clone() const
{
return NEW MTGBlockCostRule(*this);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
bool MTGAttackRule::select(Target* t)
{
@@ -1780,7 +1860,7 @@ int MTGBlockRule::receiveEvent(WEvent *e)
{
MTGCardInstance * card = z->cards[i];
if ((card->defenser && !card->defenser->has(Constants::LURE))||!card->defenser)
if(card->canBlock(lurer))
if(card->canBlock(lurer) && card->blockCost < 1)
card->setDefenser(lurer);
//force a block on a lurer, the player has a chance to set his own choice on multiple lures
//but this action can not be ignored.
@@ -1798,7 +1878,7 @@ int MTGBlockRule::isReactingToClick(MTGCardInstance * card, ManaCost *)
&& card->controller() != game->currentPlayer
)
{
if (card->canBlock() && !card->isPhased)
if (card->canBlock() && !card->isPhased && card->blockCost < 1)
{
if(card->isDefenser())
blockmenu = "Remove Blocker";