diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 5443a27e0..15a6bc351 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -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: diff --git a/projects/mtg/include/Damage.h b/projects/mtg/include/Damage.h index 9680f3e42..c4ecfcdee 100644 --- a/projects/mtg/include/Damage.h +++ b/projects/mtg/include/Damage.h @@ -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;}; }; diff --git a/projects/mtg/include/GuiStatic.h b/projects/mtg/include/GuiStatic.h index 67f94dd55..24defead6 100644 --- a/projects/mtg/include/GuiStatic.h +++ b/projects/mtg/include/GuiStatic.h @@ -24,6 +24,7 @@ struct GuiAvatar : public GuiStatic{ protected: int avatarRed; int currentLife; + int currentpoisonCount; Corner corner; public: Player * player; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 20365de8d..e30974879 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -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); diff --git a/projects/mtg/include/MTGDefinitions.h b/projects/mtg/include/MTGDefinitions.h index fd6b349a3..b991e3912 100644 --- a/projects/mtg/include/MTGDefinitions.h +++ b/projects/mtg/include/MTGDefinitions.h @@ -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 diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index 76b91a001..21a121b8e 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -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(); diff --git a/projects/mtg/include/Rules.h b/projects/mtg/include/Rules.h index 8e2f78606..86fc437b0 100644 --- a/projects/mtg/include/Rules.h +++ b/projects/mtg/include/Rules.h @@ -25,6 +25,7 @@ class RulesPlayerData{ public: vector extraRules; int life; + int poisonCount; string avatar; ManaCost * manapool; RulesPlayerZone zones[5]; diff --git a/projects/mtg/src/Damage.cpp b/projects/mtg/src/Damage.cpp index 3d908e344..bd17acb2a 100644 --- a/projects/mtg/src/Damage.cpp +++ b/projects/mtg/src/Damage.cpp @@ -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); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 6e20a9aaf..74b98743c 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -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]; } diff --git a/projects/mtg/src/GuiStatic.cpp b/projects/mtg/src/GuiStatic.cpp index 5251ee2d0..0f99b7bd7 100644 --- a/projects/mtg/src/GuiStatic.cpp +++ b/projects/mtg/src/GuiStatic.cpp @@ -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; } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 8f994df14..9d19c7d39 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -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){ diff --git a/projects/mtg/src/MTGDefinitions.cpp b/projects/mtg/src/MTGDefinitions.cpp index 5753dbd72..6a6a4657c 100644 --- a/projects/mtg/src/MTGDefinitions.cpp +++ b/projects/mtg/src/MTGDefinitions.cpp @@ -56,6 +56,11 @@ const char* Constants::MTGBasicAbilities[] = { "horsemanship", "cantregen", "oneblocker", +"infect", +"poisondamage", +"poisontwodamage", +"poisonthreedamage", + }; diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index 4c7d7aed3..de91b0c62 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -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(); diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index 804e7a8e7..6f3505eae 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -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(){