A coder's blog.

Ideas, projects, problems and solutions - whatever is interesting.

Spoiling for a Fight

A technical overview about how combat is currently implemented in Little Goblin

Starting a fight

At the moment, to keep things simple, fights happen between one player character (PC) and one monster (mob). When a PC meets an aggressive mob during a QuestStep, a fight is started. A new mob is created from a template and added to the database. A combat object is created and the mob and the PC are added to it.

Combat - Illustration #1

Round-based combat

Combat in Little Goblin is done in rounds, until either the mob or the PC is dead.

Combat - Illustration #2

An attack consists of the following steps:

  1. Check if defender parries the attack (this is currently the comparison of two raw dice rolls, determined by the creature’s parry/strike value)
  2. Each item that the attacker wears that has a damage die rolls this die and adds its damage to the total damage.
  3. The damage sum is multiplied with the damage modifiers of each item.
  4. The relevant damage modifiers of the defender’s items and natural resistance factors are used to reduce the damage dealt.
  5. Total damage is subtracted from hit points.

An Example

A paladin fights against a vampire, using his Holy Sword of Light.

He strikes the monster and damage is checked:

Standard sword damage (3d6 +3 = 14 points) * Light-Attribute (1.05) * Holy Attribute (1.20) = ~18 points of damage.

The vampire is susceptible to light and holy items:

18 * Vampire.Light (2.00) * Vampire.Holy (2.00) = 72 points

But the vampire has a high resistance against weapons and he wears a chain mail armor:

72 * Vampire.armor (0.90 vs standard attack) * Vampire.body(0.80 vs. standard damage) = ~52 points.

Item Use

Between the combat rounds, a player may use one item in his inventory. A usable item has an associated script class which is executed with the Combat as parameter. (This could be made more complex if we had multiple opponents which would require targeted effects). Directly after the use of an item, the next combat round is run.

Fleeing from combat

It is currently always possible to run away. Leaving a combat this way means giving up on the current quest, but has no other negative effects.