Turnwise – how I structured a turn-based (JRPG) battle system in Godot 4.5

I’ve been building a turn-based combat system for my own RPG prototypes and cleaned it up into a reusable kit: Turnwise. Sharing how it works in case the structure is useful even if you write your own.

The core idea: everything is a Resource

  • BattlerData: the character sheet (HP, MP, attack, defense, magic, resistance, speed, skills, elemental weaknesses, status immunities, AI, rewards)
  • Skill: physical / magical / heal / revive / support, with target type, MP cost, element, accuracy, crits, multi-hit, statuses to apply or cure
  • StatusEffect: stat multipliers, poison/regen per turn, skip turn (stun/sleep), “wears off on hit” (sleep), blocks skills (silence)
  • BattleAI: RANDOM, AGGRESSIVE, SUPPORT or CAUTIOUS

So designers make .tres files in the Inspector and the code never changes.

The loop

A BattleManager node runs either classic rounds (everyone acts once, fastest first) or a timeline (charge-time: twice the speed = twice the turns). It never touches the UI directly; it only emits signals:

var manager := BattleManager.new()
add_child(manager)
manager.player_input_needed.connect(_on_hero_turn)
manager.action_resolved.connect(_on_action_resolved)   # damage numbers, sounds, camera
manager.battle_ended.connect(_on_battle_ended)
manager.start(heroes, enemies)   # Array[Battler]

func _on_hero_turn(hero: Battler) -> void:
    # your menu decides, then:
    manager.submit_action(BattleAction.use_skill(hero, fireball, [target]))

The damage formula (one function you can override):

damage = power * 2 * attack / (attack + defense)

It equals power when attack == defense, can never go negative, and scales smoothly at both ends, which made balancing much easier than attack - defense. After that: ±10% variance, crit x1.5, Defend x0.5, and the element multiplier (2 weak, 0.5 resist, 0 immune, negative = absorb).

Animation is handled by a separate BattlerView3D/BattlerView2D with exported clip names, so any rig or sprite works, and melee skills make the attacker run to the target and back.

You can try it in the browser here (2 battles, keyboard/mouse): Turnwise demo. The kit itself is on itch (paid, 41 automated tests included).

Disclosure: the code was written with the help of an AI model and tested by hand and with the test suite.

Happy to answer questions about the structure, or how to do status effects / turn order in your own system.

1 Like