Erwan
-fixed bugs with lifelink
This commit is contained in:
@@ -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
|
||||
|
||||
19
projects/mtg/bin/Res/test/generic/lifelink.txt
Normal file
19
projects/mtg/bin/Res/test/generic/lifelink.txt
Normal file
@@ -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]
|
||||
31
projects/mtg/bin/Res/test/spirit_link.txt
Normal file
31
projects/mtg/bin/Res/test/spirit_link.txt
Normal file
@@ -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]
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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]){
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user