Code: Select all
--for reference, this is designed to convert a percentage of all incoming damage into Physical, if the target has the Blocking effect and has gained a specific attribute from a new talent I am working on.
class:bindHook("DamageProjector:base", function(self, data)
if data.state.no_sw_recurse then return data end
local target = game.level.map(data.x, data.y, Map.ACTOR)
if not target then return data end
if target.dead then return data end
if not target:attr("steel_wall") then return data end
local eff = target:hasEffect(target.EFF_BLOCKING)
if not eff then return data end
local source_talent = data.src.__projecting_for and data.src.__projecting_for.project_type and (data.src.__projecting_for.project_type.talent_id or data.src.__projecting_for.project_type.talent) and data.src.getTalentFromId and data.src:getTalentFromId(data.src.__projecting_for.project_type.talent or data.src.__projecting_for.project_type.talent_id)
if data.src and data.src.__CLASSNAME ~= "mod.class.Grid" and eff and data.type ~= DamageType.PHYSICAL then
data.state.no_sw_recurse = true
local convertedDam = data.dam * target.steel_wall
if convertedDam < 1 then return data end
local baseDam = data.dam - convertedDam
local old_sw = target.steel_wall
target.steel_wall = nil
data.dam = 0
data.dam = data.dam + DamageType:get(data.type).projector(data.src, data.x, data.y, data.type, baseDam, data.state)
data.dam = data.dam + DamageType:get(DamageType.PHYSICAL).projector(data.src, data.x, data.y, DamageType.PHYSICAL, convertedDam, data.state)
target.steel_wall = old_sw
end
return data
end)
Code: Select all
[LOG] Forest Troll Hedge-Wizard casts Flame.
[SPELL CRIT %] 1.6
Adding entity 8388 after 8380
[LOG]
[LOG] Player uses Block.
[PROJECTOR] starting dam FIRE 17.53178929211
[PROJECTOR] starting dam FIRE 12.066451874129
[PROJECTOR] after difficulty dam 12.066451874129
[PROJECTOR] after DamageType increase dam 12.790438986576
[PROJECTOR] res 0 1 on dam 12.790438986576
[PROJECTOR] after resists dam 12.790438986576
[PROJECTOR] after flat damage armor 12.790438986576
[PROJECTOR] final dam after static checks 12.790438986576
[PROJECTOR] final dam after hooks and callbacks 12.790438986576
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[PROJECTOR] starting dam PHYSICAL 5.4653374179816
[PROJECTOR] after difficulty dam 5.4653374179816
[PROJECTOR] res 17.810413038841 0.82189586961159 on dam 0
[PROJECTOR] after resists dam 0
[PROJECTOR] final dam after static checks 0
[PROJECTOR] final dam after hooks and callbacks 0
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[PROJECTOR] after difficulty dam 12.790438986576
[PROJECTOR] after DamageType increase dam 13.557865325771
[PROJECTOR] res 0 1 on dam 13.557865325771
[PROJECTOR] after resists dam 13.557865325771
[PROJECTOR] after flat damage armor 13.557865325771
[PROJECTOR] final dam after static checks 13.557865325771
[PROJECTOR] final dam after hooks and callbacks 13.557865325771
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[LOG] Player is on fire!
Cloned shader 46
[SHADER] setting reset param tick_start 581065
[LOG] Forest Troll Hedge-Wizard's Flame hits #fbd578#player#LAST# for #LIGHT_RED#13 fire#LAST#, #aaaaaa#(5 blocked)#LAST#, #aaaaaa#0 physical#LAST#, #LIGHT_RED#14 fire#LAST# (26 total damage).
[PROJECTOR] starting dam FIRE 5.8439297640368
[PROJECTOR] starting dam FIRE 4.0221506247096
[PROJECTOR] after difficulty dam 4.0221506247096
[PROJECTOR] after DamageType increase dam 4.2634796621922
[PROJECTOR] res 0 1 on dam 4.2634796621922
[PROJECTOR] after resists dam 4.2634796621922
[PROJECTOR] after flat damage armor 4.2634796621922
[PROJECTOR] final dam after static checks 4.2634796621922
[PROJECTOR] final dam after hooks and callbacks 4.2634796621922
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[PROJECTOR] starting dam PHYSICAL 1.8217791393272
[PROJECTOR] after difficulty dam 1.8217791393272
[PROJECTOR] res 17.810413038841 0.82189586961159 on dam 0
[PROJECTOR] after resists dam 0
[PROJECTOR] final dam after static checks 0
[PROJECTOR] final dam after hooks and callbacks 0
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[PROJECTOR] after difficulty dam 4.2634796621922
[PROJECTOR] after DamageType increase dam 4.5192884419237
[PROJECTOR] res 0 1 on dam 4.5192884419237
[PROJECTOR] after resists dam 4.5192884419237
[PROJECTOR] after flat damage armor 4.5192884419237
[PROJECTOR] final dam after static checks 4.5192884419237
[PROJECTOR] final dam after hooks and callbacks 4.5192884419237
[ENGINE] Setting requested FPS to 30 (33 ms)
[ENGINE] Setting requested FPS to 30 (33 ms)
[LOG]
[LOG] Burning from Forest Troll Hedge-Wizard hits #fbd578#player#LAST# for #LIGHT_RED#4 fire#LAST#, #aaaaaa#(2 blocked)#LAST#, #aaaaaa#0 physical#LAST#, #LIGHT_RED#5 fire#LAST# (9 total damage).
I'm very much an amateur at this stuff, and I've hardly touched hooks before this, aside from copying a couple from other folks' work. As far as I can understand it though, it works more or less like a callback. Aside from just being stumped as to how the base damage is getting processed twice, I'm also a little unclear on where exactly the value I return is going to be returned to. That is, there are a few things that fire off in the damage projector before the hook is called; when my hook returns its data, does that start back at the beginning of the damage projector, or is it spit out back into the original loop right after the place where the hook is called? As far as I can tell, it basically gets sent into a new loop, starting from the beginning, because I was getting some recursion before I put a flag into the state to stop it. Unfortunately, this does not shed any light on what's going on for me.
Any help anyone can offer would be greatly appreciated. I spent the entire day yesterday working on this thing to get it to the point where it is now. It's so close to working properly, and yet so not, it's making me crazy.