Erwan - fizzle spells that have invalid targets

This commit is contained in:
wagic.the.homebrew@gmail.com
2009-08-09 11:18:05 +00:00
parent 58c90c47ca
commit 4f76f50cdd
9 changed files with 94 additions and 48 deletions
+41 -4
View File
@@ -8,6 +8,7 @@
#include "../include/Damage.h"
#include "../include/ManaCost.h"
#include "../include/GameOptions.h"
#include "../include/TargetChooser.h"
// WALDORF - added to support drawing big cards during interrupts
#include "../include/CardGui.h"
#include "../include/Translate.h"
@@ -98,15 +99,16 @@ ostream& StackAbility::toString(ostream& out) const
/* Spell Cast */
Spell::Spell(MTGCardInstance * _source): Interruptible(0), TargetsList(){
Spell::Spell(MTGCardInstance * _source): Interruptible(0){
source = _source;
mHeight= 40;
type = ACTION_SPELL;
cost = NEW ManaCost();
tc = NULL;
}
Spell::Spell(int id, MTGCardInstance * _source, Targetable * _targets[], int nb_targets, ManaCost * _cost): Interruptible(id), TargetsList(_targets, nb_targets),cost(_cost){
Spell::Spell(int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _cost): Interruptible(id), tc(tc),cost(_cost){
source = _source;
mHeight = 40;
type = ACTION_SPELL;
@@ -119,6 +121,7 @@ const char * Spell::getDisplayName(){
Spell::~Spell(){
SAFE_DELETE(cost);
SAFE_DELETE(tc);
}
int Spell::resolve(){
@@ -145,6 +148,40 @@ int Spell::resolve(){
return 1;
}
MTGCardInstance * Spell::getNextCardTarget(MTGCardInstance * previous){
if (!tc) return NULL;
return tc->getNextCardTarget(previous);
}
Player * Spell::getNextPlayerTarget(Player * previous){
if (!tc) return NULL;
return tc->getNextPlayerTarget(previous);
}
Damageable * Spell::getNextDamageableTarget(Damageable * previous){
if (!tc) return NULL;
return tc->getNextDamageableTarget(previous);
}
Interruptible * Spell::getNextInterruptible(Interruptible * previous, int type){
if (!tc) return NULL;
return tc->getNextInterruptible(previous,type);
}
Spell * Spell::getNextSpellTarget(Spell * previous){
if (!tc) return NULL;
return tc->getNextSpellTarget(previous);
}
Damage * Spell::getNextDamageTarget(Damage * previous){
if (!tc) return NULL;
return tc->getNextDamageTarget(previous);
}
Targetable * Spell::getNextTarget(Targetable * previous, int type ){
if (!tc) return NULL;
return tc->getNextTarget(previous,type);
}
int Spell::getNbTargets(){
if (!tc) return 0;
return tc->cursor;
}
void Spell::Render(){
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
mFont->SetBase(0);
@@ -343,13 +380,13 @@ int ActionStack::addAction(Interruptible * action){
return 1;
}
Spell * ActionStack::addSpell(MTGCardInstance * _source, Targetable * _targets[], int _nbtargets, ManaCost * mana){
Spell * ActionStack::addSpell(MTGCardInstance * _source, TargetChooser * tc, ManaCost * mana){
#if defined (WIN32) || defined (LINUX)
char buf[4096], *p = buf;
sprintf(buf, "Add spell\n");
OutputDebugString(buf);
#endif
Spell * spell = NEW Spell(mCount,_source,_targets,_nbtargets, mana);
Spell * spell = NEW Spell(mCount,_source,tc, mana);
addAction(spell);
if (!game->players[0]->isAI() &&
_source->controller()==game->players[0] &&
-32
View File
@@ -478,29 +478,6 @@ Player * GameObserver::currentlyActing(){
return currentActionPlayer;
}
int GameObserver::tryToTapOrUntap(MTGCardInstance * card){
int reaction = mLayers->actionLayer()->isReactingToClick(card);
if (reaction){
if (reaction == 1){
mLayers->actionLayer()->reactToClick(card);
}else{
//TODO, what happens when several abilities react to the click ?
}
return reaction;
}else{
if (card->isTapped() && card->controller() == currentPlayer){
int a = ConstraintResolver::untap(this, card);
return a;
}else{
//TODO Check Spells
//card->tap();
return 0;
}
return 0;
}
}
//TODO CORRECT THIS MESS
int GameObserver::targetListIsSet(MTGCardInstance * card){
if (targetChooser == NULL){
@@ -514,12 +491,3 @@ int GameObserver::targetListIsSet(MTGCardInstance * card){
return (targetChooser->targetListSet());
}
int GameObserver::checkManaCost(MTGCardInstance * card){
ManaCost * playerMana = currentlyActing()->getManaPool();
ManaCost * cost = card->getManaCost();
if (playerMana->canAfford(cost)){
return 1;
}
return 0;
}
+9 -2
View File
@@ -838,7 +838,14 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
MTGCardInstance * card = spell->source;
if (spell->cursor==1) card->target = spell->getNextCardTarget();
if (spell->getNbTargets()==1){
card->target = spell->getNextCardTarget();
if (card->target && !spell->tc->canTarget(card->target)){
MTGPlayerCards * zones = card->controller()->game;
zones->putInGraveyard(card);
return; //fizzle
}
}
_id = magicText(_id, spell);
GameObserver * game = GameObserver::GetInstance();
@@ -1242,7 +1249,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
}
case 1192: //BrainGeyser
{
Player * player = ((Player * )spell->targets[0]);
Player * player = spell->getNextPlayerTarget();
int x = spell->cost->getConvertedCost() - 2;
for (int i = 0; i < x ; i++){
player->game->drawFromLibrary();
+3 -3
View File
@@ -62,10 +62,10 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){
}else{
Spell * spell = NULL;
if (game->targetChooser){
spell = game->mLayers->stackLayer()->addSpell(card,game->targetChooser->targets,game->targetChooser->cursor, spellCost);
SAFE_DELETE(game->targetChooser);
spell = game->mLayers->stackLayer()->addSpell(card,game->targetChooser, spellCost);
game->targetChooser = NULL;
}else{
spell = game->mLayers->stackLayer()->addSpell(card,NULL,0, spellCost);
spell = game->mLayers->stackLayer()->addSpell(card,NULL, spellCost);
}
MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->stack);
spell->source = copy;