Skip to content

Apply and Undo

TheGenieOfTheCode edited this page Nov 4, 2026 · 1 revision

Apply and Undo

On Draw Steel 1.2, every ability chat message has a section for each target, with the system's own buttons to apply damage, effects and resources. CTLib adds an undo to each of those buttons, an Apply All Damage button, and a way for players to apply through the Director.

This page is for Draw Steel 1.2. On Draw Steel 1.1, Draw Steel: Target Damage has its own apply and undo; see Target Damage Panel.

On the chat message

  • Undo: each damage, effect and resource button in a target's section gets a small undo button beside it. It takes back that apply: Stamina and Temporary Stamina go back to what they were, effects it added are removed, and resources it changed go back to what they were.
  • Applied buttons show a check: once applied, a button is dimmed with a check until it's undone. Before anything is applied, the undo button's tooltip reads Nothing to undo.
  • Apply All Damage: a chat message with two or more targets taking damage gets an Apply All Damage button with the ability's buttons. It applies each target's damage that isn't applied yet, and reads All Damage Applied once all of it is. Shift-click applies half damage.
  • Squads: damage to a minion in a squad is recorded against the squad's Stamina pool, so undoing it puts the pool back.

The Director can undo anything. A player can undo what they applied, and anything on their own chat messages, while Players Apply Through the Director is on.

Players Apply Through the Director

Players Apply Through the Director (on by default) lets players press the apply buttons on their own chat messages for creatures they don't own. The Director's machine makes the change, so a Director has to be connected; without one, the player is told so and nothing is applied.

Off, players apply only to creatures they own, as the system does on its own.

Target Damage on Draw Steel 1.2

When a world on Draw Steel 1.2 loads with Draw Steel: Target Damage on, the Director gets a chat message saying it isn't needed there. Turn Off Target Damage turns it off and reloads the world for everyone. Keep It On stops the reminder. If another module needs Target Damage, it stays on and a notification names that module.

For developers

Apply hooks

ctlib.preApplyTargetResult and ctlib.applyTargetResult fire around each apply button in a target section. Their names are exported as PRE_APPLY and APPLY.

Hooks.on(ctlib.PRE_APPLY, (part, action, context) => {
  if (action === 'applyDamage' && shouldBlock(context.targets[0])) return false;
});

Hooks.on(ctlib.APPLY, (part, action, context) => {
  if (action === 'applyDamage') logDamage(part.message, context.applied);
});
Argument What it is
part The target's section: a message part of type targetResult. part.message is its ChatMessage and part.actorTarget the target's actor.
action 'applyDamage', 'applyEffect' or 'gainResource'.
context What's being applied, below.

Return false from ctlib.preApplyTargetResult to stop the apply. ctlib.applyTargetResult runs after the change, on the machine that made it.

action context
'applyDamage' targets (actors), roll (the damage roll), halfDamage. After the apply, applied lists each target as { actor, before, after }, with Stamina as { value, temporary }, or for a squad as { group, actors, before, after }, with the pool as { value }.
'applyEffect' targets, effect, effectId
'gainResource' targets, effect

When a player's press goes to the Director, ctlib.preApplyTargetResult fires first on the player's machine with { targets, relay: true }. Both hooks then fire on the Director's machine for the apply itself.

applyHooksMode() says how the hooks are fed: 'wrapped' when CTLib wraps the system's buttons, 'system' when the system fires its own ds.preApplyTargetResult and ds.applyTargetResult and CTLib passes them on with the system's context, or 'none' on Draw Steel 1.1.

The journal

Every apply in a target section is saved on its chat message, under the journal flag of draw-steel-ctlib, and the undo buttons read it.

Function What it does
journal(message) The message's entries, oldest first.
undoJournalEntry(message, entryId) Undoes the entry with replayUndo and marks it undone. Returns false when there's no such entry, it's already undone, or the user is a player who didn't make it.

Each entry has id, at (the time), userId, partId (the target section), action, ability (its name), undone, undo (the operations that take it back) and targets. Damage entries add amount, type, half and index, the roll's place in the section. Effect entries add effect, the effect's id.

ctlib.journalRecorded fires with (message, entry) when an entry is saved, and ctlib.journalUndone with (message, entry) when one is undone. Their names are exported as JOURNAL_RECORDED and JOURNAL_UNDONE.

One target's damage

key is the target's token or actor UUID. __ in place of each dot works too.

Function What it does
targetResultFor(message, key) The target's section, or null.
applyTargetDamage(message, key, { halfDamage = false }) Applies the target's damage. Returns false when it's already applied or there's none.
undoTargetDamage(message, key) Undoes every damage apply on the target, newest first. An apply that changed no Stamina, such as a hit another module held back, is only marked undone. Returns whether anything was undone.
applyAllDamage(message, { halfDamage = false, again = false }) What the Apply All Damage button does. Returns how many targets it applied to. With again, targets already applied get their damage again.
appliedDamageParts(message) A Set of the section ids whose damage is applied and not undone.

On Draw Steel 1.2 with Target Damage off, CTLib also offers these as services, under the names Combat Tools uses for Target Damage rows on 1.1. Each takes (message, key).

Service What it does
undoDamageRow undoTargetDamage
reapplyDamageRow Undoes the target's damage, if any, then applies it again.
redealDamageRow The same, but only when the damage is already applied. Returns false otherwise.

Reading target sections

These read Draw Steel 1.1 messages too, from the rolls' targets.

Function Returns
rolledTargets(message) Each target the ability rolled against, as { actorUuid, tokenUuid, tier, part }. tokenUuid is null on 1.1.
tierFor(message, target) The tier, 1 to 3, the target got, or null. target is an actor, a token or a UUID.
powerRollFor(message, target) The target's power roll, or else the message's power roll with no target, or null.
addTargetResult(message, token, { rolls = null, tier = null }) Adds a section for a token that hasn't got one, copying the rolls and tier of an existing section unless you give them. Returns the new section, or null on 1.1 or when the token already has one.

ctlib.getResultPartContextOptions fires with (part, options) when the system builds the right-click menu of an ability result or a target section. Add entries to options to put them in the menu. The name is exported as RESULT_MENU.

Related Pages

Clone this wiki locally