Mana Pool
A mana pool is a store of magic that spells spend and time slowly refills. A spell costs its full price or does not happen at all. The pool refills at a steady rate, faster while the caster stands still, and it never refills in the same moment a spell is cast.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Mana Pool" to my game.
What it should do: A mana pool makes strong spells a choice about when, not just whether. The player spends in bursts and then has to play without magic while it comes back.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> full
full: Pool full
refill: Refilling
cast: Just cast
empty: Pool empty
full --> full: nothing cast
full --> cast: casts a spell
full --> empty: spends it all
cast --> cast: casts again
cast --> refill: pool starts refilling
cast --> empty: spends the last of it
cast --> full: refills in one go
refill --> refill: refilling goes on
refill --> cast: casts a spell
refill --> empty: spends the last of it
refill --> full: pool is full
empty --> refill: pool starts refilling
empty --> full: refills in one go
```
Use these starting values:
- maxMana: 100 units
- regenRate: 4 units/s
- restBonus: 2.5 x
- minCost: 1 units
Watch out for these common mistakes:
- A spell you cannot pay for still goes off: Tell your AI: check the price against the pool first. If it does not fit, cast nothing and spend nothing.
- Discounts make spells free: Tell your AI: cap the total discount at 100 percent and give every spell a minimum price above zero.
- A bigger pool starts out full: Tell your AI: when the top grows, leave the mana as it is. New room is not new mana.
- The pool holds more than its top: Tell your AI: when the top shrinks, cut the mana down to it right away.
- Refilling and spending in the same moment: Tell your AI: decide the spell from the pool as it was, and never refill in the same moment a spell goes through.
- A price of zero or below: Tell your AI: treat a price as a spell only when it is a real number above zero. Anything else casts nothing.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
A mana pool makes strong spells a choice about when, not just whether. The player spends in bursts and then has to play without magic while it comes back.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Pool full → Pool full: nothing cast
- Pool full → Just cast: casts a spell
- Pool full → Pool empty: spends it all
- Just cast → Just cast: casts again
- Just cast → Refilling: pool starts refilling
- Just cast → Pool empty: spends the last of it
- Just cast → Pool full: refills in one go
- Refilling → Refilling: refilling goes on
- Refilling → Just cast: casts a spell
- Refilling → Pool empty: spends the last of it
- Refilling → Pool full: pool is full
- Pool empty → Refilling: pool starts refilling
- Pool empty → Pool full: refills in one go
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| maxMana | 100 units | How big the full pool is. A bigger pool lets the player cast more spells in a row before they must wait. |
| regenRate | 4 units/s | How fast the pool refills while moving about. At 4 an empty pool of 100 takes 25 seconds, slow enough that a spell is a real cost. It is never zero, because a pool that cannot refill would lock the caster out for good. |
| restBonus | 2.5 x | How many times faster the refill is while standing still. It rewards pausing to recover. At 1 there is no bonus. |
| minCost | 1 units | The least any spell can cost, whatever discounts apply. It is never zero, because free spells would never run out. |
What usually goes wrong
A spell you cannot pay for still goes off
With 5 mana left, a spell of 30 empties the pool and still happens, or the pool goes to minus 25. The player gets a spell they could not afford.
Fix: Tell your AI: check the price against the pool first. If it does not fit, cast nothing and spend nothing.
Discounts make spells free
Two discounts of 60 percent stack to 120 percent, and the price drops to zero or below. Spells become free, or even refill the pool.
Fix: Tell your AI: cap the total discount at 100 percent and give every spell a minimum price above zero.
A bigger pool starts out full
A ring raises the top from 100 to 300, and the game fills the pool to 300 at once. Putting the ring on and off becomes a free refill.
Fix: Tell your AI: when the top grows, leave the mana as it is. New room is not new mana.
The pool holds more than its top
The ring comes off while the pool holds 250 of a top of 100. The bar overflows, and the player casts 2 more spells for free.
Fix: Tell your AI: when the top shrinks, cut the mana down to it right away.
Refilling and spending in the same moment
The pool refills first and a spell is paid from the new amount. With 9 mana, a spell of 10 then works. Fast tapping gets a bit of free magic every frame.
Fix: Tell your AI: decide the spell from the pool as it was, and never refill in the same moment a spell goes through.
A price of zero or below
A broken formula hands over a price of minus 10, or not-a-number. The pool is raised by it, or turns into not-a-number and stays that way.
Fix: Tell your AI: treat a price as a spell only when it is a real number above zero. Anything else casts nothing.
How to check it works
- Your pool is full at 100. you cast a spell that costs 30: the pool drops to 70 and the game counts 30 as spent.
- Your pool holds 20. you try a spell that costs 30: nothing is spent and the pool does not drop.
- Your pool holds exactly 30. you cast a spell that costs 30: the spell happens and the pool is exactly empty.
- Your pool holds 10 and you keep moving. two seconds go by: the pool holds 18.
- Your pool is low. you wait two seconds once moving and once standing still: standing still brings back 2.5 times as much.
- Your pool holds 99 of 100. you wait a few seconds: it stops at exactly 100.
- Your pool holds 50 and you stand still. you cast a spell for 10 after a long wait of 5 seconds: the pool holds exactly 40, with no refill added.
- A spell costs 20 and your discounts add up to 100 percent or more. you cast it: it still costs the minimum price.
- Your pool holds 80. the top drops to 50, and in another case grows to 200: the pool holds 50 in the first case and still 80 in the second.
Works well with
- Ability Cooldowns: Two limits on one spell make it feel deliberate: the cooldown spaces the spells out, the pool caps how many in total. Spend mana first, then start the cooldown, and do neither if either one says no.
- Stamina System: Stamina is for the body and mana for the mind. If both refill the same way, one of them is a duplicate. Keep them as two separate bars with different refill speeds.
Common questions
how does a mana system work in games
A pool of points that spells spend and time refills. A spell costs its full price or does not happen. The refill is slow enough that the player has to choose which spells are worth it.
how fast should mana regenerate
Start with a full refill in about 25 seconds of walking, and about 10 seconds standing still. Faster makes spells cheap, slower makes a fight feel like a single shot.
what happens when mana runs out
Spells that cost more than what is left do not happen, and the player waits. Show this clearly, for example with a sound and a flash on the bar, so it never feels like a broken button.
what do i tell my ai to add a mana bar
Paste this: Add a mana pool of 100. A spell costs its full price or does not happen, at least 1. The pool refills 4 per second, 2.5 times faster when standing still, and never in the same moment a spell is cast.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 18 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it