How do "on weapon hit" effects work for staffs in ToME4?

Short answer: "On weapon hit" things happen on bumps (when you try to move into an enemy), and on many Talents, but not on Channel Staff.

It slows your enemies, not your character. You should see log messages like "#Target# slows down". You can also check by "Look"ing at your enemies as you fight them to see if they get the Slow effect.


In the source code for the current version of ToME, 1.5.10, in modules/tome/data/talents/spells/staff-combat.lua, lines 22-91 define the Channel Staff talent. It computes damage and creates a projectile, which is an entity that flies across the map and does the damage of the appropriate type.

-- Compute damage
local dam = self:combatDamage(combat, {mag=0.2})
local damrange = self:combatDamageRange(combat)
dam = rng.range(dam, dam * damrange)
dam = self:spellCrit(dam)
dam = dam * t.getDamageMod(self, t)

self:projectile(tg, x, y, damtype, dam, {type=explosion})

game:playSoundNear(self, "talents/arcane")
return true

Therefore, the staff itself is not damaging the enemy. You will not see your targets get slowed due to Channel Staff because that Talent only uses the staff's combat damage and type of damage (e.g., fire/cold/acid/light/etc), nothing else.


More generally, "On weapon hit:" is in modules/tome/class/Object.lua, line 1031, in the function descCombat, which returns a list of complex damage types from melee_project and ranged_project, and then any attributes with the key 'special_on_hit'.

"Slows global speed by" is in modules/tome/data/damage_types.lua, line 2312, as part of the ITEM_NATURE_SLOW damage type, which defines a "projector" that actually applies the EFF_SLOW effect to the target. Various egos and random-artifacts can provide ITEM_NATURE_SLOW as either melee_project or ranged_project, e.g., "slime-covered" on line 642 of modules/tome/data/general/objects/egos/weapon.lua.

In modules/tome/class/interface/Combat.lua, line 380 is where the attackTargetWith function starts, which attempts to hit a target with a weapon. On lines 597 & 604 it calls projector (that function that ITEM_NATURE_SLOW defines that applies EFF_SLOW). Then on line 645 it calls attackTargetHitProcs, which handles the various "procs" including special_on_hit.

That single-weapon attacking function, attackTargetWith, is called by attackTarget on line 92 (which calls it for each wielded weapon), and by many Talents (including Blunt Thrust). Finally attackTarget is called in engines/default/modules/boot/class/interface/Combat.lua, on line 34, where targets with a reaction below 0 (i.e., enemies) are attacked when you bump them.