Skip to content

Animation and timing

This page explains how long a unit’s actions take on the server, and how far a moving unit gets in each game frame. Every mode a unit enters (a swing, a cast, a hit recovery, a block, a walk) has an animation record. The record, the unit’s stats and its weapon give a rate, and the rate decides on which game frames the mode’s events fire and when the mode ends. This is where “frames per cast”, “attack speed breakpoints” and “walk speed” come from. The page restates the reviewed specs: the overview in anim, the timing machinery in anim/timing and movement in anim/movement. The specs carry the exact arithmetic, the addresses and the evidence; this page tells the story and says where the specs are less sure. Terms are in the glossary.

Only what the server does is covered. Which cel the client draws and the client’s own animation clock are presentation and stay out. Which mode a unit is asked to enter, and when, is an input: for a player it is the request from the client, for a monster the AI’s command (not yet specified), and the path a unit follows is the planner’s. The specs were compared against recorded runs (tens of thousands of logged mode starts, schedules and steps, no mismatch in the closing check); the evidence sections list the runs. Where a statement is read from the code but no run separates it, this page says so.

When a unit changes mode, the server finds the animation record for that unit, mode and weapon, sets the unit’s frame fields, computes the rate, and then does one of two things:

  • Scheduled modes fix everything at the start. One pass queues an event for each frame-event byte of the record, on the game frame it will fall on, and one event for the mode’s end. Nothing is advanced afterwards. This is how a player’s attacks, casts, get-hits, blocks and deaths run, and most of a monster’s attacks. The queue and the order its events run in are the server frame.
  • Every-frame modes run once per game frame. A monster’s walk, run, knockback and sequence modes (and any attack whose MonStats2 *mv bit is set) step the unit and advance its animation frame by the rate each frame. A player’s walk, run and knockback also run every frame, but they only step the path; they have no animation advance.

Objects, missiles and items get their frame fields at the start; an object’s come from its Objects row, never from its animation record. No advance in the server’s code reaches them: every advance call there is in the monster mode functions. That the remaining call sites belong to the client is read from their names, so “no server advance” for these three types rests on that reading. Monsters in neutral, S3, S4 and dead modes queue nothing.

The animation adds no random seed of its own. The only draw in the whole machinery is an object’s animation start (below); the two other draws near it, the get-hit roll and the Concentration check, belong to hits and mode commands.

The record comes from animdata.d2. Its name is built from the unit’s type token, the mode token and the weapon class: for a player the character’s token, the mode (A1, SC, GH and so on) and the class of the weapon in hand; for a monster its MonStats code, the mode and its MonStats2 base weapon. A record gives a frame count, a base speed and, per frame, an event byte (1 to 4). A name with no record falls back to a default of 2 048 frames at speed 256; no logged case met it. When a name appears twice in the file, the earlier one in its block wins.

A transformed player (werewolf, werebear) uses the form’s record, start frame and rate; the mode is mapped to the monster’s. The name and lookup were met in every logged rate call, and the fallback steps for modes the form lacks were checked by emulation over every stock monster class.

An attack also has a start frame: the Amazon’s and the Sorceress’s attack begins at animation frame 1 or 2 depending on the weapon, and every other class at 0.

For a scheduled mode the server walks the whole animation ahead in steps, in one call when the mode starts on game frame T. Frame fields are in 8.8 fixed point: the record has F frames, so the length is 256 F; the rate r is added per step; step k stands for game frame T + k, and for it the call queues a frame event, due on T + k, for every event byte the position has passed. The queued events then fire as they fall due.

What follows from it:

  • The mode lasts n = max(2, ceil(256 (F - S) / r)) game frames from its start frame T; the end fires at T + n. This length holds at every logged rate (over 25 000 schedules in the first run, 34 000 over both parts).
  • A frame event on animation frame f fires at T + max(1, ceil(256 (f - S) / r)), and only if that is not after the last step. These closed forms equal the logged events and ends of every non-sequence schedule (45 913); the dropped late event and the case with no step, which no logged schedule meets, hold under emulation.
  • A rate change does not move queued events. Once a mode has started, a later change of speed (a weapon swap, an aura, a curse) leaves its events where they were (72 014 logged events fire there), and nothing the rate function calls reaches the queue. Only some skills’ own functions rebuild the list, from the rate at their call: the 893 logged rebuilds equal the spec’s rule for the two kinds used by Inferno, Blade Fury, Charge, Whirlwind and Leap Attack. A third rebuild, used by Dragon Talon, Strafe and Fend, is read from the code; no logged case reaches it.
  • A frozen monster loses its scheduled events, its mode end among them; they are dropped when they fall due (read from the code; no frozen case is logged).

Animation: anim-schedule-cast-fcr20

Step through anim-schedule-cast-fcr20

A scheduled mode, drawn on a toy record with the numbers of the spec’s worked example for a Sorceress cast: 14 animation frames, speed 256, start frame 0, an event on frame 7, and a faster cast rate of 20. The rate comes from the speed bonus, 120 × 20 ÷ (120 + 20) = 17, then X = min(100 + 17, 175) = 117 and r = 256 × 117 ÷ 100 = 299 (timing § J). When the mode starts, one call walks the steps ahead: step k stands for game frame T + k, adds r to the animation position, kept in 1/256 of a frame, and queues the frame events of the frames the position has passed. The event on frame 7 is queued for T + 6 and the end for T + n, n = max(2, ⌈256 (F − S) ÷ r⌉) = 12 (§ E). Not shown: the every-frame advance of monsters, the reschedules of skills, the attack rate and a real record’s data. The picture takes no seed. Every value shown is computed by our model, not observed in the game.

An every-frame monster instead adds the rate to its frame position each game frame and takes the event byte of every frame it passes. That advance reads the rate at its call, so a slowed monster advances at the new rate from its next frame. A monster restarted in the same every-frame mode by a new hit starts its animation again from 0 rather than carrying on.

Events are held in per-type lists. In each game frame the server runs missiles, then players, then monsters, then objects, then items; for each type first its every-frame events (newest first) and then the events due this frame (oldest first). An every-frame event queued in a frame runs in that frame only when it is queued before its type’s list is walked; otherwise it runs in the next one. So a walking unit’s first step sometimes comes in the frame it starts and sometimes a frame later. The first-run rule was confirmed in the run. That a type’s every-frame events run before its slot events of the same frame was seen for monsters in the game’s own runs, and holds for every type in an emulation of the list runners.

The rate is worked out by one function whenever a unit enters a mode, and again when something changes its stats. It takes the record’s base speed spd and multiplies it by a factor in percent. Which factor depends on the kind of mode:

Mode Factor (percent) Stat
cast (SC; a sequence with a cast transition) 100 plus the FCR bonus, at most 175 faster cast rate
attack the attack-rate stat plus the weapon’s speed, kept between 15 and 175 increased attack speed, weapon speed
get-hit 50 plus the FHR bonus faster hit recovery
block 50 plus the FBR bonus (100 plus under Holy Shield) faster block rate
walk, run the movement factor, at least 25 faster run/walk, stat 67
knockback fixed (see movement) none
death the record’s speed as it is none
anything else stat 69 in percent, kept between 15 and 175 none

Three details matter for a reimplementation:

  • The bonuses are diminishing. An item stat s for IAS, FHR, FCR or FBR counts as 120 s / (120 + s) (150 for faster run/walk), rounded toward zero. It rises toward 120 and never reaches it. The map was checked on thousands of emulated values.
  • Attack adds a few terms. Two weapons in the hands (Double Swing, Frenzy, a dual-wield attack) replace the right hand’s weapon term by the mean of the two. A sequence attack of Jab, Double Swing, Frenzy or Fists of Fire takes 30 off. A transformed player’s attack length comes from the human form’s attack frames with the same weapon. Charge and Leap Attack take the default branch.
  • Divisions are unsigned except for movement. A negative factor would wrap to the cap instead of slowing the unit, but no stock item gives a negative bonus, so it is not met.

Every branch was compared at all of the roughly 298 000 logged rate calls. The factor floors (25 for moving, 15 for attack) and the cap that applies to a negative result were never reached in the run; they are read from the code. A new monster’s stats 67, 68 and 69 are 75, 100 and 100 (13 693 logged plain monsters; two others and some modded units start otherwise). A new player’s are 100 each, read from the code. The rate is recalculated from 24 server call sites, a count two tools agree on; their roles (mode starts, equipping, auras, curses, chill, the slowing states) are read from the code.

The “breakpoint” tables the community uses are not in the game. They follow from the schedule’s length and the rate: a stat is worth having only when it lowers ceil(256 (F - S) / r) by a whole game frame. The least item stat that reaches a given length can be derived from the bonus map above. A few of the tool’s illustrations, for stock records (the tool’s model, not a run):

  • a Sorceress’s cast (SOSCHTH, 14 frames) lasts 14, 13, 12, 11, 10, 9, 8 frames at 0, 9, 20, 37, 63, 105, 200 FCR;
  • a Paladin’s hit recovery (PAGHHTH, 5 frames at speed 256) lasts 10, 9, 8, 7, 6, 5, 4 frames at 0, 7, 15, 27, 48, 86, 200 FHR.

Widget fallback: breakpoints-calculator

Choose an action, type a frame count, a start frame, an animation speed and the item stat for that action, and see its length in frames and its breakpoints. The item stat gives a bonus of 120 x s / (120 + s), toward zero; the bonus gives the factor (a cast 100 plus the bonus, at most 175; a get-hit or a block 50 plus it, a block under Holy Shield 100 plus it; an attack the bonus plus stat 68, 100 on a new player with the weapon’s speed term, between 15 and 175); the rate is speed x factor / 100; and the length is the larger of 2 and 256 x (frames - start) / rate, rounded up (timing § J1, J2, K1). Each shorter length has a least factor and, from it, a least item stat (K2, K3), derived, not read from a table. Not shown: the rates of movement and knockback, the dual-wield and sequence terms and the shapeshift base. Computed by our model of the rule, not observed in the game; the starting values are illustrative.

Interactive version: needs JavaScript.

The lengths the formulas give equal the schedule’s lengths at every rate the run logged. The logs hold records with the same frames and speed as these two: a Sorceress’s cast at 0, 20, 40 and 50 FCR lasted 14, 12, 11 and 11 frames, and a Paladin’s hit recovery at 0, 24 and 48 FHR lasted 10, 8 and 6. The formulas for the other rates rest on that and on the bonus map. The runs, the last with level 99 characters, logged hit recovery at FHR 0, 24 and 48, at least 30 get-hits at each, for the Amazon, Necromancer, Sorceress, Druid and Assassin, and every length matched. The runs are short of some rates: three FHR rates of 30 events for the Barbarian and the Paladin, a third FCR rate for three classes and two others. Those breakpoints are derived, not seen.

Counting the end. A mode ends n frames after its start, while the community tables count N = n - 1, the last step. The server starts the next action in the frame its request arrives. The stock client’s held request arrives at T + N for a held ordinary action and at T + n for held Lightning, so the community’s number is the interval a held button gives with this client. The client’s own rule for when it sends a held request is not read.

A Sorceress casts with 20% faster cast rate, using the SOSCHTH record (14 frames, speed 256, event byte 1 on frame 7, start frame 0). The numbers are the spec’s derivation, as the tool prints them; the logs hold the same numbers at 20% FCR on two records with the same frames, speed and event (112 casts), though not on SOSCHTH itself:

  1. The bonus is 120 x 20 / 140 = 17, so the factor is 100 + 17 = 117, under the 175 cap.
  2. The rate is 256 x 117 / 100 = 299.
  3. The length is ceil(3584 / 299) = 12 frames, so the end fires at T + 12. The event on frame 7 fires at T + ceil(1792 / 299) = T + 6, which is when the spell goes off.
  4. At 9% FCR the factor is 108 and the rate 276, giving 13 frames; 20 is the least FCR for 12.

A Paladin being hit with no FHR: the factor is 50, so r = 128 and the 5-frame record takes ceil(1280 / 128) = 10 frames; at 7% FHR it is 9. The logs hold the 0 FHR case on a record with the same frames and speed (rate 128, length 10); 7% FHR is not logged.

What happens on and after the action frame

Section titled “What happens on and after the action frame”
  • The do frame. For a player, the first event with code 1 or 2 runs the used skill’s do function, provided the unit’s action-done bit is still clear (most do functions set it). A normal attack’s hit test, damage build and delivery all happen in that call. A skill’s missile is created in the same call, after the do function. The detail is in skills and missiles and timing § L (partly read from the code).
  • The skill delay runs from the do frame, not from the mode’s start: with Frozen Orb held, the next cast started at the delay-state frame plus the delay in 72 of 73 cases (one 3 frames later).
  • A monster’s attack without a used skill strikes on a scheduled event with code 1: such an event was followed in its frame by the attacker’s hit in 18 160 of 18 637 logged cases. An event with code 2 was followed by no hit in all 2 248 logged cases, though which test drops it is not read; codes 3 and 4 are untested. An every-frame mode strikes on frames whose event byte is 1 (timing § I2, read from the code).
  • Object animation. An object takes its frame count, start frame and rate from its Objects row, not the record. When the row’s Sync is 0, its start draws RangeB(FrameDelta >> 3) on the object’s own seed to vary the rate (490 logged starts agreed, 235 with Sync set drew nothing). A chest’s “opened” mode is set without an animation start, so there is no draw at the operate end.

The specs describe which mode follows which. The runs’ logs hold most of it: every logged player and monster start fell on the clock the tables give, and every logged end was followed by the next mode they give (10 718 player ends, 28 003 monster ends).

  • Players. Neutral, walk, run, attack, cast and skill modes, get-hit, block, knockback and death. An action ends in neutral at its kind-1 end, and death goes to the dead mode (39 logged deaths). A walk or run ends in neutral in the frame its last step arrives. A run at stamina 0 becomes a walk in the frame the drain reaches 0, which also takes the first walk step. Two skill modes were not met, and the town walk and a refused path are read from the code.
  • Monsters. A table per mode says whether it is scheduled, what its frame function does and what ends it; the table was read again with a second tool. A walk or run ends on arrival; a knockback ends in the frame its animation reaches the end of the get-hit record, then a get-hit command (726 logged ends, each followed by that command); ten monster classes override some attack modes. A monster’s frame function’s result is never used.
  • Objects. Mode 1 (operating) becomes mode 2 (opened) at a queued event after the frame count; none of 161 logged operate events was followed by an animation start of the object.

A player’s request is accepted according to the mode tests: during an action, only a get-hit or block request passes while the end is pending (within 5 frames of the queued end); a get-hit or a block cannot be left before its end except for death or neutral; with an item on the cursor only death and the dead mode pass. The pending-end frame matched the queue in 1 027 logged values. The logged requests were passed in every action mode, and 781 were refused, all from get-hit, block or death; no logged get-hit or block was left before its end except by a death. The 5-frame slack, the cursor test and the refusals during an action are read from the code only (none was reached).

Hit recovery is the get-hit mode’s schedule at the FHR rate; the block’s length is the block mode’s schedule at the FBR rate. Both rates and schedules matched in every run, hit recovery at three FHR rates for five classes (not yet for the Barbarian and the Paladin).

Whether a hit makes the unit react. When combat has decided a hit lands, the get-hit code looks at the result:

  • For a blocked hit on a player the block mode starts only if frame - (last block frame) > stat102 / 8 + 15 (stat 102 is the faster block rate; 867 blocked hits, 618 passed the gate, 249 did not). The last block frame is updated whenever the gate passes, whether or not the mode is then accepted.
  • A get-hit that is not already a kill or a knockback goes through the get-hit roll, unless the unit is stunned (stunned units are always staggered: the two logged stunned player get-hits skipped the roll). The roll uses the damage as a share of the defender’s maximum life, in bands set by a divisor D (16 normally, 8 for hit classes 2, 6, 10 and 11, 32 and 64 for a few others). Below one D-th of it the unit is not staggered. From there up to two D-ths, two draws (RangePow2(2), then RangePow2(4)) each can excuse the unit, which leaves a 3 in 8 chance of a stagger. From two to four D-ths one draw (RangePow2(4)) applies, a 3 in 4 chance. From four D-ths up the stagger is certain. The roll draws zero, one or two times on the defender’s seed (7 195 logged calls, none mismatched, and the draws chain). A monster that is not allowed the get-hit mode at all is never staggered (28 logged calls separate it). The band chances are worked out from the draws, read from the code.
  • Stun sets a state until a frame (capped at 250, 13 for a hireling from level 12 up). A monster’s next AI event after a stun comes 45 frames later (timing § M5, read from the code).
  • The hit class is a code in the damage packet (a weapon’s or a monster’s hit class, with an element nibble added by delivery). The server gate found on it is the roll’s divisor; the rest is client presentation.
  • A player’s knockback: 12 of Blood Raven’s 13 knockback results left the player in neutral in the hit’s own frame, and two starts of mode 19 were seen; why the others end at once is not logged. The three sessions aimed at it met none.

The divisor 32 was met and, in 4 of its 38 calls, separated from 16; 64 was met but not separated from 16.

Whether a get-hit, block or knockback may start during a skill is decided by PlayerModeAllowed. A skill with no interrupt flag blocks all of them (12 player skills, among them Kick, Jab, Zeal, Frenzy and Whirlwind); a skill with an interrupt flag is only protected under Concentration, which refuses with a probability of its stat 164 in percent. Both rules and the draw (Range(100) on the player’s seed) are read from the code; the 26 696 logged calls left the seed unchanged and none was under the state.

How fast a unit moves is a second use of the same rate function; the step itself is in anim/movement, and the points it follows are the planners’. Positions are 16.16 subtiles.

  • A player’s path speed is the character’s WalkVelocity (in 1/256 subtile units) times the factor in percent. The factor is the faster run/walk bonus plus stat 67, never under 25. Walk is 1 536 and run 2 304 for every class at the standard factors (movement § A1, compared with the run).
  • The run is a stat, not a base. A run is a walk with a +50 stat-67 list added for the run’s duration (RunVelocity * 100 / WalkVelocity - 100, 50 on stock data) and dropped at the next mode change. The animation paces on a separate base (101 in run, 213 otherwise), which only affects the animation rate.
  • A monster’s path speed is its MonStats Velocity times the factor. Its stat 67 starts at 75 (6 578 logged units with no mod); champion and possessed monsters start at 95, fast ones at a clamp and the two logged fanatic ones at 175, and 74 logged units fit none of these values. A monster’s walk and run share the same path base, so a monster runs faster than it walks only if the AI’s command carries a velocity, which is written into stat 67 until the next mode change (movement § A3, read from the code; the 33 067 logged rate calls after such a command reproduce with the stat 67 they carry).
  • Walk and run animation bases of a monster are worked out at load from its records and scaled to its base class (compared at all logged moving and knockback calls, 54 classes with a run scaling).
  • Two bases, one factor. The path speed moves the unit and the animation base only paces the animation; both take the same factor (over 200 000 logged moving calls with a factor other than 100).
  • Knockback moves at a fixed 4 096 (one subtile per frame on an axis).
  • Charge sets its own path speed from the run speed, max(stat 67, 50) + 150 percent. 160 logged steps ran at 5 760 as that reading gives; the speed is the skill function’s own and was taken as logged, not compared.

Each game frame, a moving unit’s step on an axis is the direction component times the speed, shifted: in effect speed / 16 subtiles along an axis. The walk is 0.375 subtile a frame and the run 0.5625; a diagonal step is shorter on each axis. When the step would reach or pass the next path point it is cut to land exactly on the centre of that subtile (the snap), so a point d subtiles away takes the ceiling of 65536 d / step frames: 8 frames for 3 subtiles walking, 6 running, 3 knocked back.

Animation: anim-move-walk-3-subtiles

Step through anim-move-walk-3-subtiles

A unit with path speed 1536, a player’s walk in the worked example, and one path point three subtiles away along an axis. Each game frame the step is (D × S) >> 12 with S = (speed × 1024) >> 6 and D = 4096 on the axis row, here 24576 in 1/65536 of a subtile. The unit starts at the centre of subtile 0, position 32768. On the eighth frame the distance left is not more than the step, so the step becomes the distance left and the unit lands on the point; the frames taken are the ceiling of 65536 × 3 ÷ 24576, which is 8 (movement § B1, B3). With no point left, the path stops in that same frame (§ B5). Not shown: the collision walk, the diagonal rows and replans. The run and knockback speeds, 2304 and 4096, give 6 and 3 frames the same way. The picture takes no seed. Every value shown is computed by our model, not observed in the game.

When the step enters a new subtile the collision walk tests each subtile it crosses (the test itself is the collision grid’s: levels); a blocked subtile stops the unit at the centre of the last free one, and a monster with a re-plan flag plans again. After ten crossings in one step the rest is taken unchecked. The step and the snap were reproduced for 99 241 consecutive steps; the collision walk is reproduced over the logged test results and under emulation, the tenth-crossing cut included. The step product wraps from a speed of 32 768 on an axis (under emulation; the diagonal does not wrap there). That a player reaches it from a factor of 2 134 is derived from the rate formulas, and whether any stock source does was not surveyed.

A moving unit steps once per game frame from an every-frame event. Players’ and monsters’ walk and run end when the step returns “arrived”.

Each frame of a run takes RunDrain * 2 from stamina (1/256 units), times armour speed / 10 + 1 for body armour with speed 10 or more, plus stat 154 percent, at least 1. 37 434 run frames in the logs agreed. In a town it costs nothing (4 685 logged town drains left stamina unchanged). At 0 stamina the run becomes a walk: a run turned into a walk 81 times in the runs. In the 75 turns that follow the drain’s 0, the walk’s every-frame event is queued in the drain’s frame and the first walk step is taken in that frame. The other 6 are not the drain’s turn: in each, a later mode set in the same frame queued the walk’s event (two after a request, four that set the walk again after the drain’s 0).

A knockback plans a path of (5 / 2) + 1 = 3 subtiles away from the attacker: 575 of 576 unblocked monster plans put the point there, and the cut to the last free subtile on the line matched all 300 recounted plans; 6 subtiles for base class 78 is read from the code. A player’s knockback lasts 3 frames on an axis, fewer if the collision walk stops it (read from the code; two starts logged). A monster’s knockback ends on its animation, not its path: in the frame its get-hit record’s length is reached, however far it got (717 of 717 logged knockbacks advance the number of times that gives).

Slowing states reach movement through stat 67 (chill, the curses, item_slow), each re-running the rate; a change mid-move takes effect at once, since the step reads the speed every frame (212 slowed monster windows and 9 slowed player windows matched; the 32 logged speed changes inside a move took effect at the next step). The Slows Target skill changes only the attack and default rates, not the movement; the run did not report an outcome for it.

Draw When Seed Seen in the run?
RangeB(FrameDelta >> 3) an object starts an animation with Sync 0 the object’s yes, 490 values; no chained pair
RangePow2(2) and/or RangePow2(4) the get-hit roll, by damage band the defender’s yes, 7 195 calls, 102 chained pairs
Range(100) a mode command under Concentration the player’s no (read from the code)

The rate, the schedule, the advance, the sequences, movement and the run drain draw nothing. A second tool walked the functions under the animation machinery and found only the object start’s draw; another walk from movement’s step and drain, with the planners left aside, found none. A replan and the target check reach the planner, and 836 + 889 logged replans (810 of the 836 stock) reproduce with the unit seed unchanged, all with a target unit. They were of types 5, 6, 13 and 15. Of the planners only types 10 and 16 draw: a replan writes neither and plans any other type as it stands, and the logged replans do not separate that. The target check before the call is not compared.

From the specs’ open questions:

  • What ends some monster modes. An every-frame monster attack or skill mode ignores its frame function’s return, and a generic S3 queues nothing; presumably the AI’s next command ends them (monster AI has what ends a mode from the AI’s side, read from the code).
  • The monster AI. What command a monster gets, and when, is an input here; the AI itself is monster AI.
  • Branches the runs left short. Some rates (three FHR rates for the Barbarian and the Paladin, some FBR and FCR rates, a second set of IAS rates), the Druid’s throws (29 of the 30 wanted), a player’s knockback length (two starts in all), the moving-factor floor of 25, Charge at a low stat 67, and Slows Target. The statements stay “read from the code” and none waits on a mismatch.
  • Reading of the code left open. A few functions were not read (one called when a mode is set, part of the sequence mode test), and whether a player’s knockback-to-get-hit branch is ever reached, and the two flags that switch a move-first skill’s rate branch and empty a hand for the dual-wield term.
  • Whether a stock source reaches the step’s wrap. A speed factor of 854 for a Velocity-15 monster or 2 134 for a player.
  • Another player’s unit. Party-wide rate auras on another player’s unit need a two-client run.
  • Differences from community wording. The specs list where community tables for 1.09 and 1.10+ differ from 1.14d (Slows Target, the run factor, Charge’s speed); they are leads only.