Granting resistance penetration via debuffs

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Razakai
Uruivellas
Posts: 889
Joined: Tue May 14, 2013 3:45 pm

Granting resistance penetration via debuffs

#1 Post by Razakai »

I'm trying to write a debuff that grants all attackers resistance penetration - like Dominate, except the source doesn't need to know the talent. Tried doing this via DamageProjector:base but no luck. Is there a way to do it that won't involve messing around with overwrites and superloads? Code that I attempted below:

Code: Select all

newTalent{
	name = "Enervate", short_name = "ENERVATE_RAZ",
	type = {"spell/dread_raz", 1},
	require = spells_req1,
	points = 5,
	mode = "passive",
	autolearn_talent = "T_NECROTIC_AURA_RAZ",
	getBonusRadius = function(self, t) return math.floor(self:combatTalentScale(t, 1, 5)) end,
	getPower = function(self, t)
		return (self:combatTalentScale(t, 1, 5) )
	end,
	getResists = function(self, t)
		return (self:combatTalentScale(t, 2, 10) )
	end,
	callbackOnActBase = function(self, t)
		if self:isTalentActive(self.T_NECROTIC_AURA_RAZ) then
			local tAura = self:getTalentFromId(self.T_NECROTIC_AURA_RAZ)
			local radius = tAura.getRadius(self, tAura)
			local grids = core.fov.circle_grids(self.x, self.y, radius, true)
			for x, yy in pairs(grids) do
				for y, _ in pairs(grids[x]) do
					local target = game.level.map(x, y, Map.ACTOR)
					if target and self:reactionToward(target) < 0 then
						target:setEffect(target.EFF_ENERVATE_RAZ, 2, {src = self, power = t.getPower(self, t), resists=t.getResists(self,t), max_stacks = 5, stacks = 1})
					end
			end
		end
		end
	end,
	info = function(self, t)
	local radius = t.getBonusRadius(self,t)
	local power = t.getPower(self,t)
	local resists = t.getResists(self,t)
		return ([[Your necrotic aura grows in size and power, increasing it’s radius by %d. Enemies within are enervated, reducing all saves by %d and granting attackers %d%% resistance penetration against them. This stacks up to 5 times.]]):
		format(radius, power, resists)
	end,
}

Code: Select all

class:bindHook("DamageProjector:base", function(self, data)
	local target = game.level.map(data.x, data.y, Map.ACTOR)
	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 not target then return end

	if target.resists then
		local pen = 0
		if data.src.combatGetResistPen then pen = data.src:combatGetResistPen(type)
		elseif data.src.resists_pen then pen = (data.src.resists_pen.all or 0) + (data.src.resists_pen[type] or 0)
		end
		local dominated = target:hasEffect(target.EFF_DOMINATED)
		if dominated and dominated.data.src == data.src then pen = pen + (dominated.resistPenetration or 0) end
		local enervated = target:hasEffect(target.EFF_ENERVATE_RAZ)
		if enervated then pen = pen + (enervated.resists*enervated.stacks or 0) end
		pen = 100
		if target:attr("sleep") and data.src.attr and data.src:attr("night_terror") then pen = pen + data.src:attr("night_terror") end
		local res = target:combatGetResist(type)
		pen = util.bound(pen, 0, 100)
		if res > 0 then	res = res * (100 - pen) / 100 end
		print("[PROJECTOR] res", res, (100 - res) / 100, " on dam", data.dam)
		if res >= 100 then data.dam = 0
		elseif res <= -100 then data.dam = data.dam * 2
		else data.dam = data.dam * ((100 - res) / 100)
		end
	end
	
	return data
end)

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Granting resistance penetration via debuffs

#2 Post by HousePet »

Maybe just apply a resistance reduction that recalculates every turn?
My feedback meter decays into coding. Give me feedback and I make mods.

Post Reply