Issue 525: fixed NPE for ABecomes
Reformatted AllAbilities.h
This commit is contained in:
+5439
-5439
File diff suppressed because it is too large
Load Diff
+358
-211
@@ -1,211 +1,358 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
#include "AllAbilities.h"
|
#include "AllAbilities.h"
|
||||||
|
|
||||||
// BanishCard implementations
|
// BanishCard implementations
|
||||||
|
|
||||||
AABanishCard::AABanishCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = -1) :
|
AABanishCard::AABanishCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL,
|
||||||
ActivatedAbility(_id, _source, _cost), banishmentType(_banishmentType)
|
int _banishmentType = -1) :
|
||||||
{
|
ActivatedAbility(_id, _source, _cost), banishmentType(_banishmentType)
|
||||||
if (_target)
|
{
|
||||||
target = _target;
|
if (_target) target = _target;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * AABanishCard::getMenuText()
|
const char * AABanishCard::getMenuText()
|
||||||
{
|
{
|
||||||
return "Send to graveyard";
|
return "Send to graveyard";
|
||||||
}
|
}
|
||||||
|
|
||||||
int AABanishCard::resolve()
|
int AABanishCard::resolve()
|
||||||
{
|
{
|
||||||
DebugTrace("This is not implemented!");
|
DebugTrace("This is not implemented!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AABanishCard * AABanishCard::clone() const
|
AABanishCard * AABanishCard::clone() const
|
||||||
{
|
{
|
||||||
AABanishCard * a = NEW AABanishCard(*this);
|
AABanishCard * a = NEW AABanishCard(*this);
|
||||||
a->isClone = 1;
|
a->isClone = 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bury
|
// Bury
|
||||||
|
|
||||||
AABuryCard::AABuryCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType =
|
AABuryCard::AABuryCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType =
|
||||||
0) :
|
0) :
|
||||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::BURY)
|
AABanishCard(_id, _source, _target, _cost, AABanishCard::BURY)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int AABuryCard::resolve()
|
int AABuryCard::resolve()
|
||||||
{
|
{
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
if (_target)
|
if (_target)
|
||||||
{
|
{
|
||||||
return _target->bury();
|
return _target->bury();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * AABuryCard::getMenuText()
|
const char * AABuryCard::getMenuText()
|
||||||
{
|
{
|
||||||
return "Bury";
|
return "Bury";
|
||||||
}
|
}
|
||||||
|
|
||||||
AABuryCard * AABuryCard::clone() const
|
AABuryCard * AABuryCard::clone() const
|
||||||
{
|
{
|
||||||
AABuryCard * a = NEW AABuryCard(*this);
|
AABuryCard * a = NEW AABuryCard(*this);
|
||||||
a->isClone = 1;
|
a->isClone = 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy
|
// Destroy
|
||||||
|
|
||||||
AADestroyCard::AADestroyCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = 0) :
|
AADestroyCard::AADestroyCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL,
|
||||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::DESTROY)
|
int _banishmentType = 0) :
|
||||||
{
|
AABanishCard(_id, _source, _target, _cost, AABanishCard::DESTROY)
|
||||||
}
|
{
|
||||||
|
}
|
||||||
int AADestroyCard::resolve()
|
|
||||||
{
|
int AADestroyCard::resolve()
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
{
|
||||||
if (_target)
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
{
|
if (_target)
|
||||||
return _target->destroy();
|
{
|
||||||
}
|
return _target->destroy();
|
||||||
return 0;
|
}
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
const char * AADestroyCard::getMenuText()
|
|
||||||
{
|
const char * AADestroyCard::getMenuText()
|
||||||
return "Destroy";
|
{
|
||||||
}
|
return "Destroy";
|
||||||
|
}
|
||||||
AADestroyCard * AADestroyCard::clone() const
|
|
||||||
{
|
AADestroyCard * AADestroyCard::clone() const
|
||||||
AADestroyCard * a = NEW AADestroyCard(*this);
|
{
|
||||||
a->isClone = 1;
|
AADestroyCard * a = NEW AADestroyCard(*this);
|
||||||
return a;
|
a->isClone = 1;
|
||||||
}
|
return a;
|
||||||
|
}
|
||||||
// Sacrifice
|
|
||||||
AASacrificeCard::AASacrificeCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL, int _banishmentType = 0) :
|
// Sacrifice
|
||||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::SACRIFICE)
|
AASacrificeCard::AASacrificeCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL,
|
||||||
{
|
int _banishmentType = 0) :
|
||||||
}
|
AABanishCard(_id, _source, _target, _cost, AABanishCard::SACRIFICE)
|
||||||
|
{
|
||||||
int AASacrificeCard::resolve()
|
}
|
||||||
{
|
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
int AASacrificeCard::resolve()
|
||||||
if (_target)
|
{
|
||||||
{
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
Player * p = _target->controller();
|
if (_target)
|
||||||
WEvent * e = NEW WEventCardSacrifice(_target);
|
{
|
||||||
GameObserver * game = GameObserver::GetInstance();
|
Player * p = _target->controller();
|
||||||
game->receiveEvent(e);
|
WEvent * e = NEW WEventCardSacrifice(_target);
|
||||||
p->game->putInGraveyard(_target);
|
GameObserver * game = GameObserver::GetInstance();
|
||||||
return 1;
|
game->receiveEvent(e);
|
||||||
}
|
p->game->putInGraveyard(_target);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
const char * AASacrificeCard::getMenuText()
|
}
|
||||||
{
|
|
||||||
return "Sacrifice";
|
const char * AASacrificeCard::getMenuText()
|
||||||
}
|
{
|
||||||
|
return "Sacrifice";
|
||||||
AASacrificeCard * AASacrificeCard::clone() const
|
}
|
||||||
{
|
|
||||||
AASacrificeCard * a = NEW AASacrificeCard(*this);
|
AASacrificeCard * AASacrificeCard::clone() const
|
||||||
a->isClone = 1;
|
{
|
||||||
return a;
|
AASacrificeCard * a = NEW AASacrificeCard(*this);
|
||||||
}
|
a->isClone = 1;
|
||||||
|
return a;
|
||||||
// Discard
|
}
|
||||||
|
|
||||||
AADiscardCard::AADiscardCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL,
|
// Discard
|
||||||
int _banishmentType = 0) :
|
|
||||||
AABanishCard(_id, _source, _target, _cost, AABanishCard::DISCARD)
|
AADiscardCard::AADiscardCard(int _id, MTGCardInstance * _source, MTGCardInstance * _target, ManaCost * _cost = NULL,
|
||||||
{
|
int _banishmentType = 0) :
|
||||||
}
|
AABanishCard(_id, _source, _target, _cost, AABanishCard::DISCARD)
|
||||||
|
{
|
||||||
int AADiscardCard::resolve()
|
}
|
||||||
{
|
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
int AADiscardCard::resolve()
|
||||||
if (_target)
|
{
|
||||||
{
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
Player * p = _target->controller();
|
if (_target)
|
||||||
WEvent * e = NEW WEventCardDiscard(_target);
|
{
|
||||||
GameObserver * game = GameObserver::GetInstance();
|
Player * p = _target->controller();
|
||||||
game->receiveEvent(e);
|
WEvent * e = NEW WEventCardDiscard(_target);
|
||||||
p->game->putInGraveyard(_target);
|
GameObserver * game = GameObserver::GetInstance();
|
||||||
return 1;
|
game->receiveEvent(e);
|
||||||
}
|
p->game->putInGraveyard(_target);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
const char * AADiscardCard::getMenuText()
|
}
|
||||||
{
|
|
||||||
return "Discard";
|
const char * AADiscardCard::getMenuText()
|
||||||
}
|
{
|
||||||
|
return "Discard";
|
||||||
AADiscardCard * AADiscardCard::clone() const
|
}
|
||||||
{
|
|
||||||
AADiscardCard * a = NEW AADiscardCard(*this);
|
AADiscardCard * AADiscardCard::clone() const
|
||||||
a->isClone = 1;
|
{
|
||||||
return a;
|
AADiscardCard * a = NEW AADiscardCard(*this);
|
||||||
}
|
a->isClone = 1;
|
||||||
|
return a;
|
||||||
//Mana Redux
|
}
|
||||||
AManaRedux::AManaRedux(int id, MTGCardInstance * source, MTGCardInstance * target, int amount, int type) :
|
|
||||||
MTGAbility(id, source, target), amount(amount), type(type)
|
//Mana Redux
|
||||||
{
|
AManaRedux::AManaRedux(int id, MTGCardInstance * source, MTGCardInstance * target, int amount, int type) :
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
MTGAbility(id, source, target), amount(amount), type(type)
|
||||||
}
|
{
|
||||||
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
int AManaRedux::addToGame()
|
}
|
||||||
{
|
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
int AManaRedux::addToGame()
|
||||||
if (amount < 0)
|
{
|
||||||
{
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
amount = abs(amount);
|
if (amount < 0)
|
||||||
if (_target->getManaCost()->hasColor(type))
|
{
|
||||||
{
|
amount = abs(amount);
|
||||||
if (_target->getManaCost()->getConvertedCost() >= 1)
|
if (_target->getManaCost()->hasColor(type))
|
||||||
{
|
{
|
||||||
_target->getManaCost()->remove(type, amount);
|
if (_target->getManaCost()->getConvertedCost() >= 1)
|
||||||
if (_target->getManaCost()->alternative > 0)
|
{
|
||||||
{
|
_target->getManaCost()->remove(type, amount);
|
||||||
_target->getManaCost()->alternative->remove(type, amount);
|
if (_target->getManaCost()->alternative > 0)
|
||||||
}
|
{
|
||||||
if (_target->getManaCost()->BuyBack > 0)
|
_target->getManaCost()->alternative->remove(type, amount);
|
||||||
{
|
}
|
||||||
_target->getManaCost()->BuyBack->remove(type, amount);
|
if (_target->getManaCost()->BuyBack > 0)
|
||||||
}
|
{
|
||||||
}
|
_target->getManaCost()->BuyBack->remove(type, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
_target->getManaCost()->add(type, amount);
|
else
|
||||||
if (_target->getManaCost()->alternative > 0)
|
{
|
||||||
{
|
_target->getManaCost()->add(type, amount);
|
||||||
_target->getManaCost()->alternative->add(type, amount);
|
if (_target->getManaCost()->alternative > 0)
|
||||||
}
|
{
|
||||||
if (_target->getManaCost()->BuyBack > 0)
|
_target->getManaCost()->alternative->add(type, amount);
|
||||||
{
|
}
|
||||||
_target->getManaCost()->BuyBack->add(type, amount);
|
if (_target->getManaCost()->BuyBack > 0)
|
||||||
}
|
{
|
||||||
}
|
_target->getManaCost()->BuyBack->add(type, amount);
|
||||||
return MTGAbility::addToGame();
|
}
|
||||||
}
|
}
|
||||||
|
return MTGAbility::addToGame();
|
||||||
AManaRedux * AManaRedux::clone() const
|
}
|
||||||
{
|
|
||||||
AManaRedux * a = NEW AManaRedux(*this);
|
AManaRedux * AManaRedux::clone() const
|
||||||
a->isClone = 1;
|
{
|
||||||
return a;
|
AManaRedux * a = NEW AManaRedux(*this);
|
||||||
}
|
a->isClone = 1;
|
||||||
|
return a;
|
||||||
AManaRedux::~AManaRedux()
|
}
|
||||||
{
|
|
||||||
}
|
AManaRedux::~AManaRedux()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// ABecomes
|
||||||
|
ABecomes::ABecomes(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, WParsedPT * wppt, string sabilities) :
|
||||||
|
MTGAbility(id, source, target), wppt(wppt)
|
||||||
|
{
|
||||||
|
|
||||||
|
aType = MTGAbility::STANDARD_BECOMES;
|
||||||
|
|
||||||
|
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++)
|
||||||
|
{
|
||||||
|
size_t found = sabilities.find(Constants::MTGBasicAbilities[j]);
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
abilities.push_back(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < Constants::MTG_NB_COLORS; j++)
|
||||||
|
{
|
||||||
|
size_t found = sabilities.find(Constants::MTGColorStrings[j]);
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
colors.push_back(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string s = stypes;
|
||||||
|
menu = stypes;
|
||||||
|
while (s.size())
|
||||||
|
{
|
||||||
|
size_t found = s.find(" ");
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
int id = Subtypes::subtypesList->find(s.substr(0, found));
|
||||||
|
types.push_back(id);
|
||||||
|
s = s.substr(found + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int id = Subtypes::subtypesList->find(s);
|
||||||
|
types.push_back(id);
|
||||||
|
s = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int ABecomes::addToGame()
|
||||||
|
{
|
||||||
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
|
list<int>::iterator it;
|
||||||
|
for (it = types.begin(); it != types.end(); it++)
|
||||||
|
{
|
||||||
|
_target->addType(*it);
|
||||||
|
}
|
||||||
|
for (it = colors.begin(); it != colors.end(); it++)
|
||||||
|
{
|
||||||
|
_target->setColor(*it);
|
||||||
|
}
|
||||||
|
for (it = abilities.begin(); it != abilities.end(); it++)
|
||||||
|
{
|
||||||
|
_target->basicAbilities[*it]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wppt)
|
||||||
|
{
|
||||||
|
_target->power = wppt->power.getValue();
|
||||||
|
_target->toughness = wppt->toughness.getValue();
|
||||||
|
_target->life = _target->toughness;
|
||||||
|
}
|
||||||
|
return MTGAbility::addToGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ABecomes::destroy()
|
||||||
|
{
|
||||||
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
|
list<int>::iterator it;
|
||||||
|
for (it = types.begin(); it != types.end(); it++)
|
||||||
|
{
|
||||||
|
_target->removeType(*it);
|
||||||
|
}
|
||||||
|
for (it = colors.begin(); it != colors.end(); it++)
|
||||||
|
{
|
||||||
|
_target->removeColor(*it);
|
||||||
|
}
|
||||||
|
for (it = abilities.begin(); it != abilities.end(); it++)
|
||||||
|
{
|
||||||
|
_target->basicAbilities[*it]--;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char * ABecomes::getMenuText()
|
||||||
|
{
|
||||||
|
string s = menu;
|
||||||
|
sprintf(menuText, "Becomes %s", s.c_str());
|
||||||
|
return menuText;
|
||||||
|
}
|
||||||
|
|
||||||
|
ABecomes * ABecomes::clone() const
|
||||||
|
{
|
||||||
|
ABecomes * a = NEW ABecomes(*this);
|
||||||
|
if (a->wppt) a->wppt = NEW WParsedPT(*(a->wppt));
|
||||||
|
a->isClone = 1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
ABecomes::~ABecomes()
|
||||||
|
{
|
||||||
|
SAFE_DELETE (wppt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ABecomes
|
||||||
|
|
||||||
|
// ABecomesUEOT
|
||||||
|
ABecomesUEOT::ABecomesUEOT(int id, MTGCardInstance * source, MTGCardInstance * target, string types, WParsedPT * wpt, string abilities) :
|
||||||
|
InstantAbility(id, source, target)
|
||||||
|
{
|
||||||
|
ability = NEW ABecomes(id, source, target, types, wpt, abilities);
|
||||||
|
aType = MTGAbility::STANDARD_BECOMES;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ABecomesUEOT::resolve()
|
||||||
|
{
|
||||||
|
ABecomes * a = ability->clone();
|
||||||
|
GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), a);
|
||||||
|
wrapper->addToGame();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char * ABecomesUEOT::getMenuText()
|
||||||
|
{
|
||||||
|
return ability->getMenuText();
|
||||||
|
}
|
||||||
|
|
||||||
|
ABecomesUEOT * ABecomesUEOT::clone() const
|
||||||
|
{
|
||||||
|
ABecomesUEOT * a = NEW ABecomesUEOT(*this);
|
||||||
|
a->ability = this->ability->clone();
|
||||||
|
a->isClone = 1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
ABecomesUEOT::~ABecomesUEOT()
|
||||||
|
{
|
||||||
|
SAFE_DELETE ability;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user