Fix calling restore_sp to drain SP from an affect special node
This also adds an Allow Resist flag to determine whether the target's Mage Spells or Priest Spells skill can reduce the amount drained. Thanks to @fosnola for spotting this issue.
This commit is contained in:
@@ -105,6 +105,7 @@ void cCreature::cure(int amt) {
|
||||
|
||||
void cCreature::restore_sp(int amt) {
|
||||
if(!is_alive()) return;
|
||||
if(amt <= 0) return;
|
||||
if(mp >= max_mp) return;
|
||||
mp += amt;
|
||||
if(mp > max_mp)
|
||||
@@ -112,16 +113,17 @@ void cCreature::restore_sp(int amt) {
|
||||
if(mp < 0) mp = 0;
|
||||
}
|
||||
|
||||
void cCreature::drain_sp(int drain) {
|
||||
void cCreature::drain_sp(int drain, bool allow_resist) {
|
||||
drain = magic_adjust(drain);
|
||||
if(drain > 0) {
|
||||
if(drain <= 0) return;
|
||||
if(allow_resist) {
|
||||
if(mu > 0 && mp > 4)
|
||||
drain = min(mp, drain / 3);
|
||||
else if(cl > 0 && mp > 10)
|
||||
drain = min(mp, drain / 2);
|
||||
mp -= drain;
|
||||
if(mp < 0) mp = 0;
|
||||
}
|
||||
mp -= drain;
|
||||
if(mp < 0) mp = 0;
|
||||
}
|
||||
|
||||
void cCreature::poison(int how_much) {
|
||||
|
@@ -46,7 +46,7 @@ public:
|
||||
void scare(int how_much);
|
||||
void sleep(eStatus type, int how_much, int adj);
|
||||
void avatar();
|
||||
void drain_sp(int how_much);
|
||||
void drain_sp(int how_much, bool allow_resist);
|
||||
void restore_sp(int how_much);
|
||||
|
||||
int get_health() const;
|
||||
|
@@ -46,7 +46,7 @@ public:
|
||||
virtual void scare(int how_much) = 0;
|
||||
virtual void sleep(eStatus type, int how_much, int adj) = 0; // Also handles paralysis, charm, and forcecage
|
||||
virtual void avatar() = 0;
|
||||
virtual void drain_sp(int how_much) = 0;
|
||||
virtual void drain_sp(int how_much, bool allow_resist) = 0;
|
||||
virtual void restore_sp(int how_much) = 0;
|
||||
|
||||
virtual int get_health() const = 0;
|
||||
|
@@ -561,9 +561,9 @@ void cParty::avatar() {
|
||||
adven[i]->avatar();
|
||||
}
|
||||
|
||||
void cParty::drain_sp(int how_much) {
|
||||
void cParty::drain_sp(int how_much, bool allow_resist) {
|
||||
for(int i = 0; i < 6; i++)
|
||||
adven[i]->drain_sp(how_much);
|
||||
adven[i]->drain_sp(how_much, allow_resist);
|
||||
}
|
||||
|
||||
void cParty::restore_sp(int how_much) {
|
||||
|
@@ -175,7 +175,7 @@ public:
|
||||
void sleep(eStatus type, int how_much, int adj);
|
||||
void clear_bad_status();
|
||||
void avatar();
|
||||
void drain_sp(int how_much);
|
||||
void drain_sp(int how_much, bool allow_resist);
|
||||
void restore_sp(int how_much);
|
||||
|
||||
int get_health() const;
|
||||
|
@@ -97,17 +97,18 @@ void cPlayer::avatar() {
|
||||
status[eStatus::MARTYRS_SHIELD] = 8;
|
||||
}
|
||||
|
||||
void cPlayer::drain_sp(int drain) {
|
||||
void cPlayer::drain_sp(int drain, bool allow_resist) {
|
||||
if(drain <= 0) return;
|
||||
int mu = skills[eSkill::MAGE_SPELLS];
|
||||
int cl = skills[eSkill::PRIEST_SPELLS];
|
||||
if(drain > 0) {
|
||||
if(allow_resist) {
|
||||
if(mu > 0 && cur_sp > 4)
|
||||
drain = min(cur_sp, drain / 3);
|
||||
else if(cl > 0 && cur_sp > 10)
|
||||
drain = min(cur_sp, drain / 2);
|
||||
cur_sp -= drain;
|
||||
if(cur_sp < 0) cur_sp = 0;
|
||||
}
|
||||
cur_sp -= drain;
|
||||
if(cur_sp < 0) cur_sp = 0;
|
||||
}
|
||||
|
||||
void cPlayer::scare(int) {
|
||||
@@ -300,6 +301,7 @@ void cPlayer::acid(int how_much) {
|
||||
|
||||
void cPlayer::restore_sp(int amt) {
|
||||
if(!is_alive()) return;
|
||||
if(amt <= 0) return;
|
||||
if(cur_sp >= max_sp) return;
|
||||
cur_sp += amt;
|
||||
if(cur_sp > max_sp)
|
||||
|
@@ -134,7 +134,7 @@ public:
|
||||
void scare(int how_much);
|
||||
void sleep(eStatus type, int how_much, int adj);
|
||||
void avatar();
|
||||
void drain_sp(int how_much);
|
||||
void drain_sp(int how_much, bool allow_resist);
|
||||
void restore_sp(int how_much);
|
||||
|
||||
void combine_things();
|
||||
|
Reference in New Issue
Block a user