Frostdev

KilnAPI reference Guide

Action speed: faster or slower attacks, bow draws and tool swings

Since Kiln 0.2.0-dev.31.30 (mod API 0.2.28). Kiln provides the framework for attack and action speed mods: Kiln.ActionSpeed (assembly Kiln.Combat) sets a speed multiplier per player for melee attacks, bow shots and tool swings. Kiln finds the game's code on both executables, tells the server's run from a client's prediction, sends the values to joined clients and keeps unknown actions at the game's timing. Your mod only says what it wants. Service details: ../services/combat.md.

A whole mod in ten lines

using Kiln;

public sealed class FastHands : Mod
{
    public override void OnLoad()
    {
        if (!ActionSpeed.Available) { Log.Warn($"no action speed here: {ActionSpeed.Status.Reason}"); return; }
        if (Client.IsRemote) return;                    // the host or the server decides; Kiln sends it to the guests
        ActionSpeed.SetDefault(ActionKind.Melee, 2.0);  // every player, also players who join later
        ActionSpeed.SetDefault(ActionKind.Tool, 1.5);
    }
}

That is all: no config sync, no hooks, no clean-up. When the mod unloads, its values go with it.

What you can set

Call What
ActionSpeed.SetDefault(kind, m) / ClearDefault(kind) your mod's value for every player
ActionSpeed.Set(player, kind, m) / Clear(player, kind) / Clear(player) your mod's value for one player; it overrides your default there
ActionSpeed.Get(player, kind) the effective value (every mod's value multiplied), on any side
ActionSpeed.Changed an effective value changed: ActionSpeedChanged(Player, Kind, Multiplier)
ActionSpeed.Available, ActionSpeed.Status what works in this game, and why a part does not
  • Kinds: ActionKind.Melee (light and heavy attacks, combos, recovery), ActionKind.Bow (bow draw and fire durations and the shot; staffs and wands keep their timing), ActionKind.Tool (axe, pickaxe and the like).
  • Range: a value is 0.5 to 10 (ActionSpeed.Min, ActionSpeed.Max). 1.0 is the game's timing. Anything else (and NaN or infinity) throws ArgumentOutOfRangeException.
  • Several mods: each mod keeps its own values; Kiln multiplies them and clamps the product to [0.5, 10]. Two mods at 2x and 3x give 6x.
  • Who may set them: the server or the host, on the tick thread (your OnLoad, ticks and handlers). On a joined client the setters throw InvalidOperationException; read Get there instead.
  • Players only: a creature or NPC entity throws ArgumentException. When a player leaves, every mod's values for that player go.

By weapon category (since 0.2.0-dev.32.9)

A multiplier can also apply to one weapon class only (mod API 0.2.37): one-handed swords, greatswords, daggers and the others the game has. They are the game's own weapon categories, read from the game's data, so Kiln has no list of its own; name one by the game's name of it:

using Kiln;

public sealed class OneHandedSpeed : Mod
{
    static readonly WeaponCategory OneHandSword = new("OneHandSword");

    public override void OnLoad()
    {
        if (Client.IsRemote) return;
        ActionSpeed.SetCategoryDefault(OneHandSword, 1.15);   // one-handed swords 15% faster for everyone; greatswords unchanged
    }
}
Call What
ActionSpeed.SetCategoryDefault(category, m) / ClearCategoryDefault(category) your mod's value for that category, every player
ActionSpeed.SetCategory(player, category, m) / ClearCategory(player, category) your mod's value for one player and category
ActionSpeed.GetCategory(player, category) the effective category value (every mod's multiplied)
ActionSpeed.GetEffective(player, kind, category) what an action of that kind with a weapon of that category runs at
ActionSpeed.WeaponCategories the game's categories (Name, DisplayName, Id), once the item catalog was read
ActionSpeed.WeaponCategoryOf(item) an item's category, or null
  • It multiplies the kind. A greatsword swing runs at the Melee multiplier times the GreatSword one (clamped to 0.5 to 10). Items without a category (tools) take the kind's value alone.
  • Names: the game's (OneHandSword, OneHandAxe, OneHandClub, TwoHandAxe, TwoHandClub, TwoHandHammer, GreatSword, Dagger, RangedBow, RangedStaff, RangedWand, ... on the current game builds; list them with ActionSpeed.WeaponCategories). Case does not matter. A name the game does not have changes nothing and kiln.log says so once. You can set one in OnLoad, before a world loaded; it applies once the game's categories are known.
  • Multiplayer and unload work as for the kinds; a joined client gets the server's categories and values.

The game's speed skills

Heavy Hitter and Swift Blades are not speed multipliers in the game. The weapons' own combo data has an earlier hand-over to the next swing for each of them (the swing and its hit keep their time), so a mod that copies one with ActionSpeed gets close, not equal: on a greatsword, ActionSpeed 1.10 makes a three-swing combo 2.783 s where Heavy Hitter makes it 2.733 s (1.12 gives 2.733 s); on a one-handed sword 1.15 and Swift Blades both give 1.667 s. ActionSpeed.GameComboSpeedOf(player, weapon).Factor (since 0.2.0-dev.32.9, mod API 0.2.37) reads what the player's own nodes do to that weapon's combo in the game's data (1.1098 for Heavy Hitter on a greatsword, 1 without a speed node), so a mod can leave its copy off where the player has the original. Details: ../services/combat.md.

What happens in the game

For a player's melee attack, tool swing or bow shot, Kiln scales the action's clock (when its hits, combos and recovery happen) and the animation's speed together, so the swing you see and the hit you get stay in step. For a bow, the draw and fire durations are divided too. A draw already in progress keeps its duration; the next draw uses the new value.

Melee hits at high speed

Above 2x a fast swing can pass through a target between two server ticks: at 10x a sword swing lasts about 68 ms, less than two 41 ms ticks, so the game's own collider sees it at only one or two poses. Since Kiln 0.2.0-dev.31.31 Kiln fills the gap itself while a player's effective melee multiplier is above ActionSpeed.MeleeSamplingAbove (2.0): between two ticks it places the game's own box collider of the swing at up to ten poses along the blade's path (following the hand, so the blade sweeps its arc) and hands whatever it touches to the game's own impact before damage. Blocks, parries and the game's one-hit-per-target rule apply as for any hit. Your mod does nothing for this; ActionSpeed.Status.MeleeSampling says whether it works in this game, and Status.Reason why not. If your mod still has its own contact sampling, drop it when Status.MeleeSampling is true, or both will run.

  • Not yet seen in a real game. It is built from the same game code the Combat And Attack Tweaks mod uses (which works in the real game) and tested on the host against fakes of that code, but nobody has played a swing with it yet.
  • Limits: players only; impacts on the right or left hand (swords, axes, maces and the like); at most 10 extra casts per swing and server tick, 64 per tick for the whole server; up to 16 extra targets per impact; only on the server or the host (a joined client sees the server's hits). On a server whose collision backend is not the game's default (Jolt) it stays off.
  • Server admins can switch it off without touching any mod: kiln/config/combat.json with {"meleeSampling": false} (read when the server starts). Attack speed itself keeps working.

Untested above about 3-5x on busy servers. Max is 10, but values above about 3-5x on busy dedicated servers are untested. In a lab with 4 bots, a mod's 10x melee with its own sampling gave memory errors and frame spikes the 1x run did not (bots never acknowledge replication, so part of it may be the bots). A lab with Combat And Attack Tweaks' beta.6 sampler measured 0.94 sword hits per swing at 1x, 0.19-0.64 at 3x and 0.22 at 10x. Axes stayed at 0.94-0.98.

Multiplayer

Kiln sends the values to every joined client that runs Kiln, by itself, also to a client that was still on its loading screen when they were sent (from 0.2.0-dev.31.32). A client applies them to its own player's swing, so it looks and feels right there. Other players look as the server sends them. A client without Kiln, or on an older Kiln, sees the server's results at the server's timing. The server stays in charge either way.

Detecting it

A mod that also loads on an older Kiln asks for "kiln": ">=0.2.0-dev.31.30" in its manifest (">=0.2.0-dev.32.9" for the weapon categories, GameComboSpeedOf and Combat.OnDamageCalculated). Without that, Kiln refuses the mod at load on an older Kiln and names the missing member. In a game where a part does not work (another game build, another tool that hooks the same places), ActionSpeed.Available or the matching Status field is false and Status.Reason says why. Capabilities: combat.action_speed, combat.bow_timing, combat.melee_sampling, combat.action_speed.prediction.

Enshrouded is a trademark of Keen Games GmbH. Kiln is unofficial.