]> granicus.if.org Git - nethack/commitdiff
Fix dmonsfree pending when hero was hit with drain-life artifact
authorPasi Kallinen <paxed@alt.org>
Fri, 18 Mar 2022 16:33:32 +0000 (18:33 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 18 Mar 2022 16:33:36 +0000 (18:33 +0200)
When a monster hit hero with an artifact with drain-life attack
(Stormbringer or The Staff of Aesculapius), and hero lost a level
and hero had more max hp in the lower xp level, the math made the
attacker lose hp. This could put the monster hp in the negative,
causing "dmonsfree: 1 removed doesn't match 0 pending"

src/artifact.c

index 18d981b21c4af1b0ea3f7a60a0dda364426a6ad8..7e3ca12a29b9388b64f54e9bd397185c96193e51 100644 (file)
@@ -1589,7 +1589,7 @@ artifact_hit(struct monst *magr, struct monst *mdef, struct obj *otmp,
             }
             losexp("life drainage");
             if (magr && magr->mhp < magr->mhpmax) {
-                magr->mhp += (oldhpmax - u.uhpmax + 1) / 2;
+                magr->mhp += (abs(oldhpmax - u.uhpmax) + 1) / 2;
                 if (magr->mhp > magr->mhpmax)
                     magr->mhp = magr->mhpmax;
             }