added poison support, guicounter, "infect" ability, poisonous ability.

This commit is contained in:
omegablast2002@yahoo.com
2010-08-25 18:56:34 +00:00
parent a9850317ff
commit e644aaae3a
14 changed files with 137 additions and 11 deletions

View File

@@ -2196,7 +2196,36 @@ AADamager(int _id, MTGCardInstance * _source, Targetable * _target, WParsedInt *
};
//poison removel
class AARemovePoison:public ActivatedAbilityTP{
public:
int poison;
AARemovePoison(int _id, MTGCardInstance * _source, Targetable * _target,int poison, ManaCost * _cost=NULL, int doTap = 0, int who = TargetChooser::UNSET):ActivatedAbilityTP(_id,_source,_target,_cost,doTap,who),poison(poison){
}
int resolve(){
Damageable * _target = (Damageable *) getTarget();
if(_target){
_target->poisonCount -= poison;
}
return 0;
}
const char * getMenuText(){
return "Remove Poison";
}
AARemovePoison * clone() const{
AARemovePoison * a = NEW AARemovePoison(*this);
a->isClone = 1;
return a;
}
~AARemovePoison(){
}
};
/* Standard Damager, can choose a NEW target each time the price is paid */
class TADamager:public TargetAbility{
public:

View File

@@ -19,14 +19,15 @@ class GameObserver;
class Damageable:public Targetable {
protected:
public:
int life;
int poisonCount;
int type_as_damageable;
Damageable(int _life){life=_life;};
int getLife(){return life;};
virtual int dealDamage(int damage){life-=damage;return life;};
virtual int afterDamage(){return 0;}
virtual int poisoned(){return 0;}
virtual JQuad * getIcon(){return NULL;};
};

View File

@@ -24,6 +24,7 @@ struct GuiAvatar : public GuiStatic{
protected:
int avatarRed;
int currentLife;
int currentpoisonCount;
Corner corner;
public:
Player * player;

View File

@@ -93,7 +93,6 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable {
MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL);
int nbOpponents();
int stepPower(CombatStep step);
int afterDamage();
int has(int ability);

View File

@@ -103,8 +103,12 @@ class Constants
HORSEMANSHIP = 45,
CANTREGEN = 46,
ONEBLOCKER = 47,
INFECT = 48,
POISONDAMAGE = 49,
POISONTWODAMAGE = 50,
POISONTHREEDAMAGE = 51,
NB_BASIC_ABILITIES = 48,
NB_BASIC_ABILITIES = 52,
RARITY_S = 'S', //Special Rarity

View File

@@ -24,6 +24,7 @@ class Player: public Damageable{
int canPutLandsIntoPlay;
MTGPlayerCards * game;
int afterDamage();
int poisoned();
Player(MTGPlayerCards * deck, string deckFile, string deckFileSmall);
virtual ~Player();
void unTapPhase();

View File

@@ -25,6 +25,7 @@ class RulesPlayerData{
public:
vector <string> extraRules;
int life;
int poisonCount;
string avatar;
ManaCost * manapool;
RulesPlayerZone zones[5];

View File

@@ -65,17 +65,52 @@ int Damage::resolve(){
for (int i = 0; i < damage; i++){
_target->counters->addCounter(-1, -1);
}
}else{ //Normal case
}else{//infect damage---------------------------------------
while(target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE && source->has(Constants::INFECT)){
MTGCardInstance * _target = (MTGCardInstance *)target;
for (int i = 0; i < damage; i++){
_target->counters->addCounter(-1, -1);
}return a;
}while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::INFECT)){
MTGCardInstance * _target = (MTGCardInstance *)target;
for (int i = 0; i < damage; i++){
_target->poisonCount += 1;//this will be changed to poison counters.
}return a;
}//infect end--------------------------------------------------
//poison AND damage
while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::POISONDAMAGE)){
MTGCardInstance * _target = (MTGCardInstance *)target;
for (int i = 0; i < damage; i++){
//this will be changed to poison counters.
a = target->dealDamage(1);
}
_target->poisonCount += 1;
return a;
}
while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::POISONTWODAMAGE)){
MTGCardInstance * _target = (MTGCardInstance *)target;
for (int i = 0; i < damage; i++){
//this will be changed to poison counters.
a = target->dealDamage(1);
}
_target->poisonCount += 2;
return a;
}
while(target->type_as_damageable == DAMAGEABLE_PLAYER && source->has(Constants::POISONTHREEDAMAGE)){
MTGCardInstance * _target = (MTGCardInstance *)target;
for (int i = 0; i < damage; i++){
//this will be changed to poison counters.
a = target->dealDamage(1);
}
_target->poisonCount += 3;
return a;
}
a = target->dealDamage(damage);
}
//Send (Damage/Replaced effect) event to listeners
g->receiveEvent(e);
return a;
}
void Damage::Render(){
WFont * mFont = resources.GetWFont(Constants::MAIN_FONT);
mFont->SetBase(0);

View File

@@ -301,6 +301,8 @@ void GameObserver::stateEffects()
}
for (int i =0; i < 2; i++)
if (players[i]->life <= 0) gameOver = players[i];
for (int i =0; i < 2; i++)
if (players[i]->poisonCount >= 10) gameOver = players[i];
}

View File

@@ -13,7 +13,7 @@ bool GuiStatic::Leaving(JButton key)
return false;
}
GuiAvatar::GuiAvatar(float x, float y, bool hasFocus, Player * player, Corner corner, GuiAvatars* parent) : GuiStatic(GuiAvatar::Height, x, y, hasFocus, parent), avatarRed(255), currentLife(player->life), corner(corner), player(player) {
GuiAvatar::GuiAvatar(float x, float y, bool hasFocus, Player * player, Corner corner, GuiAvatars* parent) : GuiStatic(GuiAvatar::Height, x, y, hasFocus, parent), avatarRed(255), currentLife(player->life),currentpoisonCount(player->poisonCount), corner(corner), player(player) {
type = GUI_AVATAR;
}
@@ -22,6 +22,7 @@ void GuiAvatar::Render()
GameObserver * game = GameObserver::GetInstance();
JRenderer * r = JRenderer::GetInstance();
int life = player->life;
int poisonCount = player->poisonCount;
WFont * mFont = resources.GetWFont(Constants::MAIN_FONT);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
//Avatar
@@ -30,6 +31,12 @@ void GuiAvatar::Render()
avatarRed = 192 + (3* 255 * lifeDiff) / currentLife / 4;
if (avatarRed < 0) avatarRed = 0;
}
int poisonDiff = poisonCount - currentpoisonCount;
if (poisonDiff < 0 && currentpoisonCount > 0){
avatarRed = 192 + (3* 255 * poisonDiff) / currentpoisonCount / 4;
if (avatarRed < 0) avatarRed = 0;
}
currentpoisonCount = poisonCount;
currentLife = life;
r->FillRect(actX+2, actY+2, Width * actZ, Height *actZ, ARGB((int)(actA / 2), 0, 0, 0));
@@ -88,7 +95,21 @@ void GuiAvatar::Render()
mFont->SetColor(ARGB((int)actA, 255, 255, 255));
mFont->DrawString(buffer, actX, actY-10, JGETEXT_RIGHT);
break;
}
}
//poison
char poison[5];
sprintf(poison, "%i",poisonCount);
switch (corner)
{
case TOP_LEFT :
mFont->SetColor(ARGB((int)actA - 75, 0, 255, 0));
mFont->DrawString(poison, actX+2, actY+10);
break;
case BOTTOM_RIGHT :
mFont->SetColor(ARGB((int)actA - 75 ,0, 255, 0));
mFont->DrawString(poison, actX, actY-20, JGETEXT_RIGHT);
break;
}
PlayGuiObject::Render();
}
@@ -96,6 +117,7 @@ ostream& GuiAvatar::toString(ostream& out) const
{
return out << "GuiAvatar ::: avatarRed : " << avatarRed
<< " ; currentLife : " << currentLife
<< " ; currentpoisonCount : " << currentpoisonCount
<< " ; player : " << player;
}

View File

@@ -793,7 +793,24 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
a->oneShot = 1;
return a;
}
//remove poison
found = s.find("removepoison:");
if (found != string::npos){
size_t start = s.find(":",found);
size_t end = s.find(" ",start);
int poison;
if (end != string::npos){
poison = atoi(s.substr(start+1,end-start-1).c_str());
}else{
poison = atoi(s.substr(start+1).c_str());
}
Targetable * t = NULL;
if (spell) t = spell->getNextPlayerTarget();
MTGAbility * a = NEW AARemovePoison (id, card, t,poison,NULL,0,who);
a->oneShot = 1;
return a;
}
//set life total
found = s.find("lifeset");
if (found != string::npos){

View File

@@ -56,6 +56,11 @@ const char* Constants::MTGBasicAbilities[] = {
"horsemanship",
"cantregen",
"oneblocker",
"infect",
"poisondamage",
"poisontwodamage",
"poisonthreedamage",
};

View File

@@ -12,6 +12,7 @@ Player::Player(MTGPlayerCards * deck, string file, string fileSmall) : Damageabl
game->setOwner(this);
manaPool = NEW ManaPool(this);
canPutLandsIntoPlay = 1;
poisonCount = 0;
mAvatar = NULL;
mAvatarTex = NULL;
type_as_damageable = DAMAGEABLE_PLAYER;
@@ -83,7 +84,9 @@ ManaPool * Player::getManaPool(){
int Player::afterDamage(){
return life;
}
int Player::poisoned(){
return poisonCount;
}
//Cleanup phase at the end of a turn
void Player::cleanupPhase(){
game->inPlay->cleanupPhase();

View File

@@ -39,6 +39,7 @@ MTGCardInstance * Rules::getCardByMTGId(int mtgid){
RulesPlayerData::RulesPlayerData(){
life = 20;
poisonCount = 0;
manapool = NEW ManaCost();
avatar = "";
}
@@ -76,6 +77,9 @@ void RulesState::parsePlayerState(int playerId, string s){
area = 3;
}else if(areaS.compare("life") == 0){
playerData[playerId].life = atoi((s.substr(limiter+1)).c_str());
return;
}else if(areaS.compare("poisonCount") == 0){
playerData[playerId].poisonCount = atoi((s.substr(limiter+1)).c_str());
return;
}else if(areaS.compare("avatar") == 0){
playerData[playerId].avatar = s.substr(limiter+1);
@@ -273,6 +277,7 @@ void Rules::initGame(){
for (int i = 0; i < 2; i++){
Player * p = g->players[i];
p->life = initState.playerData[i].life;
p->poisonCount = initState.playerData[i].poisonCount;
p->getManaPool()->copy(initState.playerData[i].manapool);
if (initState.playerData[i].avatar.size()) {
p->loadAvatar(initState.playerData[i].avatar);
@@ -318,6 +323,7 @@ void RulesPlayerData::cleanup(){
zones[i].cleanup();
}
life=20;
poisonCount=0;
}
void RulesState::cleanup(){