Skip to content

Fix combat math: spell mana cost, weapon attack, companion, level-up - #8

Merged
su8 merged 1 commit into
su8:mainfrom
lasers:fix/combat-math
Oct 23, 2026
Merged

su8 merged 1 commit into
su8:mainfrom
lasers:fix/combat-math

Conversation

@lasers

@lasers lasers commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Changes

Spell mana cost (battle()): mana -= 10 - manaCost made 15/20-cost spells add mana. Each attack now costs the base 10 plus the spell's cost:

int manaCost = 10 + hero.equippedSpell.manaCost;

⚠️ This is my guess at the intent; adjust if you meant something else.

Weapon attack: when mana came back mid-battle (auto-potion), the "attack decreased" flag was cleared without giving back the 3 attack, so the loss was permanent. It's now restored when the flag is cleared.

Companion: a dead companion no longer takes damage (its HP stays at 0 instead of going negative), and "has fallen" prints once instead of every enemy turn.

Level-up (gainXP()):

  • XP above the threshold is kept: xp -= level * 50 instead of xp = 0.
  • Max HP/mana are raised before the level-up heal, so the new points get filled.

Testing

A throwaway test (not committed) ran 200 random seeds and checked:

  • XP carry-over and the level-up heal
  • a 20-cost spell lowers mana instead of raising it
  • weapon attack is back to normal after mana returns mid-battle
  • the companion death message prints at most once, and companion HP never goes below 0

It fails on main and passes on this branch.

Question

The shop between floors charges 20 gold for the small potion, while the potion shop sells it for 15. Is that intentional? I didn't change it.

Fixes #4

- Each attack costs 10 + the spell's mana cost; expensive spells used
  to add mana because the cost was subtracted from 10.
- Give the -3 weapon attack back when mana returns mid-battle instead
  of clearing the flag and losing it permanently.
- A dead companion no longer takes damage, and its death is announced
  once instead of every enemy turn.
- Keep XP above the level-up threshold and raise max HP/mana before
  the level-up heal.
Comment thread main.cpp Resolved
@su8
su8 merged commit 6df826b into su8:main Oct 23, 2026
3 checks passed
@lasers
lasers deleted the fix/combat-math branch October 23, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combat math bugs: expensive spells gain mana, weapon permanently loses attack, XP lost on level-up

2 participants