diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index 1e1bf173c..3d83c4fa2 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -8,6 +8,7 @@ generic/hybrid_mana.txt generic/hybrid_mana_2.txt generic/hybrid_mana_3.txt generic/legendary.txt +generic/lifelink.txt generic/persist.txt generic/persist2.txt generic/sacrifice.txt @@ -89,6 +90,7 @@ siege_gang_commander.txt shivan_hellkite.txt shock.txt spark_elemental.txt +spirit_link.txt stasis.txt sword_to_plowshares.txt terror.txt diff --git a/projects/mtg/bin/Res/test/generic/lifelink.txt b/projects/mtg/bin/Res/test/generic/lifelink.txt new file mode 100644 index 000000000..e28cc98c6 --- /dev/null +++ b/projects/mtg/bin/Res/test/generic/lifelink.txt @@ -0,0 +1,19 @@ +#Testing Lifelink +[INIT] +COMBATATTACKERS +[PLAYER1] +inplay:Rhox War Monk +[PLAYER2] +[DO] +Rhox War Monk +next +next +next +[ASSERT] +COMBATEND +[PLAYER1] +inplay:Rhox War Monk +life:23 +[PLAYER2] +life:17 +[END] \ No newline at end of file diff --git a/projects/mtg/bin/Res/test/spirit_link.txt b/projects/mtg/bin/Res/test/spirit_link.txt new file mode 100644 index 000000000..909db1f31 --- /dev/null +++ b/projects/mtg/bin/Res/test/spirit_link.txt @@ -0,0 +1,31 @@ +#Testing spirit link on grizzly bears +[INIT] +FIRSTMAIN +[PLAYER1] +hand:spirit link +inplay:grizzly bears +manapool:{W} +[PLAYER2] +[DO] +spirit link +grizzly bears +next +#combat begin +next +#attackers +grizzly bears +next +#blockers +next +#combat damage +next +#combat end +[ASSERT] +COMBATEND +[PLAYER1] +inplay:grizzly bears,spirit link +manapool:{0} +life:22 +[PLAYER2] +life:18 +[END] \ No newline at end of file diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 9130eac6e..030e93082 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -715,38 +715,6 @@ class ASpellCounterEnchantment:public TargetAbility{ }; - -/* Lifelink Ability */ -class ALifeLink:public MTGAbility{ - public: - int nbdamagesthisturn; - Damage * lastDamage; - ALifeLink(int _id, MTGCardInstance * _source):MTGAbility(_id, _source){ - nbdamagesthisturn = 0; - lastDamage = NULL; - } - - void Update(float dt){ - ActionStack * as = game->mLayers->stackLayer(); - int totaldamages = as->count(ACTION_DAMAGE,RESOLVED_OK); - if ( totaldamages > nbdamagesthisturn){ - Damage * damage = ((Damage * )as->getNext(lastDamage,ACTION_DAMAGE, RESOLVED_OK)); - while(damage){ - lastDamage = damage; - if (damage->source == source){ - source->controller()->life+= damage->damage; - } - damage = ((Damage * )as->getNext(lastDamage,ACTION_DAMAGE, RESOLVED_OK)); - } - }else if (totaldamages ==0){ - lastDamage = NULL; - } - nbdamagesthisturn = totaldamages; - } - -}; - - //Circle of Protections class ACircleOfProtection: public TargetAbility{ public: diff --git a/projects/mtg/include/MTGRules.h b/projects/mtg/include/MTGRules.h index 10a18bab7..f2a7644b2 100644 --- a/projects/mtg/include/MTGRules.h +++ b/projects/mtg/include/MTGRules.h @@ -134,4 +134,28 @@ public: const char * getMenuText(){return "Momir";} }; + +/* LifeLink */ +class MTGLifelinkRule:public MTGAbility{ + public: + MTGLifelinkRule(int _id):MTGAbility(_id,NULL){}; + + int receiveEvent(WEvent * event){ + if (event->type == WEvent::DAMAGE){ + WEventDamage * e = (WEventDamage *) event; + Damage * d = e->damage; + MTGCardInstance * card = d->source; + if (d->damage>0 && card && card->basicAbilities[Constants::LIFELINK]){ + card->controller()->life+= d->damage; + return 1; + } + } + return 0; + } + + int testDestroy(){return 0;} + +}; + + #endif diff --git a/projects/mtg/include/WEvent.h b/projects/mtg/include/WEvent.h index 96ac4a9a9..c45f9de68 100644 --- a/projects/mtg/include/WEvent.h +++ b/projects/mtg/include/WEvent.h @@ -3,11 +3,13 @@ class MTGCardInstance; class MTGGameZone; +class Damage; class WEvent{ public: enum{ CHANGE_ZONE = 1, + DAMAGE = 2, }; int type; WEvent(int _type); @@ -21,4 +23,11 @@ public: WEventZoneChange(MTGCardInstance * _card, MTGGameZone * _from, MTGGameZone *_to); }; + +class WEventDamage: public WEvent{ +public: + Damage * damage; + WEventDamage(Damage * _damage); +}; + #endif \ No newline at end of file diff --git a/projects/mtg/src/Damage.cpp b/projects/mtg/src/Damage.cpp index 34cf1df0b..f42e8e41f 100644 --- a/projects/mtg/src/Damage.cpp +++ b/projects/mtg/src/Damage.cpp @@ -2,6 +2,7 @@ #include "../include/Damage.h" #include "../include/MTGCardInstance.h" #include "../include/Counters.h" +#include "../include/WEvent.h" Damage::Damage(int id, MTGCardInstance * _source, Damageable * _target): Interruptible(id){ init(_source, _target, _source->getPower()); @@ -44,6 +45,12 @@ int Damage::resolve(){ } int a = target->dealDamage(damage); + + //Send Damage event to listeners + WEventDamage * e = NEW WEventDamage(this); + GameObserver::GetInstance()->mLayers->actionLayer()->receiveEvent(e); + delete e; + return a; } diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 099f7e416..c4a4eaadc 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -24,6 +24,7 @@ void DuelLayers::init(){ actionLayer->Add(NEW MTGBlockRule(-1)); actionLayer->Add(NEW MTGLegendRule(-1)); actionLayer->Add(NEW MTGPersistRule(-1)); + actionLayer->Add(NEW MTGLifelinkRule(-1)); //2 Hand Layer MTGGuiHand * mGuiHand = NEW MTGGuiHand(3, GameObserver::GetInstance()); diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index f04ba6b99..44a43f4c5 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -460,9 +460,9 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ } //gain/lose life - found = s.find("life"); + found = s.find("life:"); if (found != string::npos){ - unsigned int start = s.find(":",found); + unsigned int start = found+4; unsigned int end = s.find(" ",start); int life; if (end != string::npos){ @@ -1516,10 +1516,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ * For example, setting LIFELINK for a creature is not enough right now... * It shouldn't be necessary to add an object. State based abilities could do the trick */ - if (card->basicAbilities[Constants::LIFELINK]){ - ALifeLink * ability = NEW ALifeLink(_id, card); - game->addObserver(ability); - } + for (int i=Constants::PROTECTIONGREEN; i <= Constants::PROTECTIONWHITE; i++){ if (card->basicAbilities[i]){ diff --git a/projects/mtg/src/WEvent.cpp b/projects/mtg/src/WEvent.cpp index e5fe72616..106962934 100644 --- a/projects/mtg/src/WEvent.cpp +++ b/projects/mtg/src/WEvent.cpp @@ -1,6 +1,7 @@ #include "../include/WEvent.h" #include "../include/MTGCardInstance.h" #include "../include/MTGGameZones.h" +#include "../include/Damage.h" WEvent::WEvent(int _type){ type=_type; @@ -10,4 +11,8 @@ WEventZoneChange::WEventZoneChange(MTGCardInstance * _card, MTGGameZone * _from, card = _card; from = _from; to = _to; +} + +WEventDamage::WEventDamage(Damage *_damage):WEvent(DAMAGE){ + damage = _damage; } \ No newline at end of file