Erwan
- moved all "loseLife/gainLife" duplicated code into 1 Player method
This commit is contained in:
@@ -719,11 +719,8 @@ public:
|
||||
return 0;
|
||||
if (!tc->canTarget(e->player)) return 0;
|
||||
if (fromTc && !fromTc->canTarget(e->player)) return 0;
|
||||
if (type == 1 && (e->amount > 0 || e->Ltype == 0)) return 0;
|
||||
if (type == 0 && (e->amount < 0 || e->Ltype == 1)) return 0;
|
||||
if(type != 1)
|
||||
e->player->thatmuch = e->amount;
|
||||
else
|
||||
if (type == 1 && (e->amount > 0)) return 0;
|
||||
if (type == 0 && (e->amount < 0)) return 0;
|
||||
e->player->thatmuch = abs(e->amount);
|
||||
return 1;
|
||||
}
|
||||
@@ -5742,12 +5739,7 @@ public:
|
||||
MTGCardInstance * card = d->source;
|
||||
if (d->damage > 0 && card && (card == source || card == source->target))
|
||||
{
|
||||
source->owner->life += d->damage;
|
||||
source->owner->thatmuch = d->damage;
|
||||
WEvent * lifed = NULL;
|
||||
lifed = NEW WEventLife(source->owner,d->damage);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
source->owner->gainLife(d->damage);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,11 @@ public:
|
||||
}
|
||||
|
||||
int afterDamage();
|
||||
|
||||
int gainLife(int value);
|
||||
int loseLife(int value);
|
||||
int gainOrLoseLife(int value);
|
||||
|
||||
int poisoned();
|
||||
int damaged();
|
||||
int prevented();
|
||||
|
||||
@@ -54,8 +54,7 @@ struct WEventDamage : public WEvent {
|
||||
struct WEventLife : public WEvent {
|
||||
Player * player;
|
||||
int amount;
|
||||
int Ltype;
|
||||
WEventLife(Player * player,int amount,int Ltype = 0);
|
||||
WEventLife(Player * player,int amount);
|
||||
virtual Targetable * getTarget(int target);
|
||||
};
|
||||
|
||||
|
||||
@@ -1254,25 +1254,19 @@ ActivatedAbilityTP(_id, card, _target, _cost, _tap, who),life_s(life_s), life(li
|
||||
}
|
||||
|
||||
int AALifer::resolve()
|
||||
{
|
||||
RefreshedLife = NEW WParsedInt(life_s, NULL, source);
|
||||
{
|
||||
Damageable * _target = (Damageable *) getTarget();
|
||||
if (_target)
|
||||
if (!_target)
|
||||
return 0;
|
||||
|
||||
RefreshedLife = NEW WParsedInt(life_s, NULL, source);
|
||||
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
||||
{
|
||||
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
||||
{
|
||||
_target = ((MTGCardInstance *) _target)->controller();
|
||||
}
|
||||
Player *player = (Player*)_target;
|
||||
player->thatmuch = abs(RefreshedLife->getValue());
|
||||
WEvent * lifed = NULL;
|
||||
lifed = NEW WEventLife(player,RefreshedLife->getValue());
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
_target->life += RefreshedLife->getValue();
|
||||
if(life->getValue() < 0)
|
||||
_target->lifeLostThisTurn += abs(RefreshedLife->getValue());
|
||||
_target = ((MTGCardInstance *) _target)->controller();
|
||||
}
|
||||
Player *player = (Player*)_target;
|
||||
player->gainOrLoseLife(RefreshedLife->getValue());
|
||||
|
||||
delete RefreshedLife;
|
||||
return 1;
|
||||
}
|
||||
@@ -1307,30 +1301,23 @@ AALifeSet::AALifeSet(int _id, MTGCardInstance * _source, Targetable * _target, W
|
||||
int AALifeSet::resolve()
|
||||
{
|
||||
Damageable * _target = (Damageable *) getTarget();
|
||||
if (_target)
|
||||
{
|
||||
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
||||
{
|
||||
_target = ((MTGCardInstance *) _target)->controller();
|
||||
}
|
||||
if (!_target)
|
||||
return 0;
|
||||
|
||||
int lifeDiff = life->getValue() - _target->life ;
|
||||
WEvent * lifed = NULL;
|
||||
if(lifeDiff < 0)
|
||||
{
|
||||
_target->lifeLostThisTurn += abs(lifeDiff);
|
||||
lifed = NEW WEventLife((Player*)_target,lifeDiff,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lifed = NEW WEventLife((Player*)_target,lifeDiff,0);
|
||||
}
|
||||
_target->thatmuch = abs(lifeDiff);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
_target->life = life->getValue();
|
||||
Player * p = NULL;
|
||||
if (_target->type_as_damageable == DAMAGEABLE_MTGCARDINSTANCE)
|
||||
{
|
||||
p = ((MTGCardInstance *) _target)->controller();
|
||||
}
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
p = (Player*)_target;
|
||||
}
|
||||
|
||||
int lifeDiff = life->getValue() - p->life ;
|
||||
p->gainOrLoseLife(lifeDiff);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char * AALifeSet::getMenuText()
|
||||
|
||||
@@ -76,22 +76,16 @@ LifeCost::LifeCost(TargetChooser *_tc) :
|
||||
|
||||
int LifeCost::doPay()
|
||||
{
|
||||
if (!target)
|
||||
return 0;
|
||||
|
||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||
if (target)
|
||||
{
|
||||
_target->controller()->thatmuch = 1;
|
||||
WEvent * lifed = NULL;
|
||||
lifed = NEW WEventLife(_target->controller(),-1,1);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
_target->controller()->life -= 1;
|
||||
_target->controller()->lifeLostThisTurn += 1;
|
||||
target = NULL;
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
_target->controller()->loseLife(1);
|
||||
target = NULL;
|
||||
if (tc)
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//discard a card at random as a cost
|
||||
|
||||
@@ -3269,12 +3269,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell)
|
||||
game->mLayers->stackLayer()->addDamage(card, target, x);
|
||||
if (target->life < x)
|
||||
x = target->life;
|
||||
game->currentlyActing()->life += x;
|
||||
game->currentlyActing()->thatmuch = x;
|
||||
WEvent * lifed = NULL;
|
||||
lifed = NEW WEventLife(game->currentlyActing(),x);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
game->currentlyActing()->gainLife(x);
|
||||
break;
|
||||
}
|
||||
case 1159: //Erg Raiders
|
||||
@@ -3485,12 +3480,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell)
|
||||
if (current->hasType("Artifact"))
|
||||
{
|
||||
game->players[i]->game->putInGraveyard(current);
|
||||
current->controller()->life += current->getManaCost()->getConvertedCost();
|
||||
current->controller()->thatmuch = current->getManaCost()->getConvertedCost();
|
||||
WEvent * lifed = NULL;
|
||||
lifed = NEW WEventLife(current->controller(),current->getManaCost()->getConvertedCost());
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
current->controller()->gainLife(current->getManaCost()->getConvertedCost());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3603,12 +3593,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell)
|
||||
if (library->nb_cards)
|
||||
player->game->putInZone(library->cards[library->nb_cards - 1], library, player->game->graveyard);
|
||||
}
|
||||
game->currentlyActing()->life += x;
|
||||
game->currentlyActing()->thatmuch = x;
|
||||
WEvent * lifed = NULL;
|
||||
lifed = NEW WEventLife(game->currentlyActing(),x);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
game->currentlyActing()->gainLife(x);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1868,12 +1868,7 @@ int MTGLifelinkRule::receiveEvent(WEvent * event)
|
||||
MTGCardInstance * card = d->source;
|
||||
if (d->damage > 0 && card && card->basicAbilities[Constants::LIFELINK])
|
||||
{
|
||||
card->controller()->thatmuch = d->damage;
|
||||
WEvent * lifed = NULL;
|
||||
lifed = NEW WEventLife(card->controller(),d->damage);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
card->controller()->life += d->damage;
|
||||
card->controller()->gainLife(d->damage);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +116,45 @@ ManaPool * Player::getManaPool()
|
||||
return manaPool;
|
||||
}
|
||||
|
||||
int Player::gainOrLoseLife(int value)
|
||||
{
|
||||
if (!value)
|
||||
return 0; //Don't do anything if there's no actual life change
|
||||
|
||||
thatmuch = abs(value); //What is thatmuch used for?
|
||||
life+=value;
|
||||
if (value<0)
|
||||
lifeLostThisTurn -= value;
|
||||
|
||||
//Send life event to listeners
|
||||
WEvent * lifed = NEW WEventLife(this,value);
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
game->receiveEvent(lifed);
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
int Player::gainLife(int value)
|
||||
{
|
||||
if (value <0)
|
||||
{
|
||||
DebugTrace("PLAYER.CPP: don't call gainLife on a negative value, use loseLife instead");
|
||||
return 0;
|
||||
}
|
||||
return gainOrLoseLife(value);
|
||||
};
|
||||
|
||||
int Player::loseLife(int value)
|
||||
{
|
||||
if (value <0)
|
||||
{
|
||||
DebugTrace("PLAYER.CPP: don't call loseLife on a negative value, use gainLife instead");
|
||||
return 0;
|
||||
}
|
||||
return gainOrLoseLife(-value);
|
||||
};
|
||||
|
||||
|
||||
int Player::afterDamage()
|
||||
{
|
||||
return life;
|
||||
|
||||
@@ -21,8 +21,8 @@ WEventDamage::WEventDamage(Damage *damage) :
|
||||
{
|
||||
}
|
||||
|
||||
WEventLife::WEventLife(Player * player,int amount,int Ltype) :
|
||||
WEvent(), player(player),amount(amount), Ltype(Ltype)
|
||||
WEventLife::WEventLife(Player * player,int amount) :
|
||||
WEvent(), player(player),amount(amount)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user