From 6101c778faf898360eece230f53763f0dce99c3b Mon Sep 17 00:00:00 2001
From: DarkGod <darkgod@net-core.org>
Date: Sat, 17 May 2014 14:15:42 +0200
Subject: [PATCH] fix

---
 game/modules/tome/class/interface/Combat.lua        | 10 ++++++----
 game/modules/tome/data/talents/corruptions/bone.lua | 10 +++++-----
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/game/modules/tome/class/interface/Combat.lua b/game/modules/tome/class/interface/Combat.lua
index b5acdf8ad1..cc75d8f9dc 100644
--- a/game/modules/tome/class/interface/Combat.lua
+++ b/game/modules/tome/class/interface/Combat.lua
@@ -1263,7 +1263,7 @@ end
 -- limit = value approached as x increases
 -- y_high = value to match at when x = x_high
 -- y_low (optional) = value to match when x = x_low
---	returns (limit - add)*x/(x + halfpoint) + add (= add when x = 0 and limit when x = infinity), halfpoint, add
+--	returns (limit - add)*x/(x + halfpoint) + add (= add when x = 0 and limit when x = infinity)
 -- halfpoint and add are internally computed to match the desired high/low values
 -- note that the progression low->high->limit must be monotone, consistently increasing or decreasing
 function _M:combatLimit(x, limit, y_low, x_low, y_high, x_high)
@@ -1272,9 +1272,11 @@ function _M:combatLimit(x, limit, y_low, x_low, y_high, x_high)
 	if y_low and x_low then
 		local p = limit*(x_high-x_low)
 		local m = x_high*y_high - x_low*y_low
-		local halfpoint = (p-m)/(y_high - y_low)
-		local add = (limit*(x_high*y_low-x_low*y_high) + y_high*y_low*(x_low-x_high))/(p-m)
-		return (limit-add)*x/(x + halfpoint) + add
+--		local halfpoint = (p-m)/(y_high - y_low)
+--		local add = (limit*(x_high*y_low-x_low*y_high) + y_high*y_low*(x_low-x_high))/(p-m)
+--		return (limit-add)*x/(x + halfpoint) + add
+		local ah = (limit*(x_high*y_low-x_low*y_high)+ y_high*y_low*(x_low-x_high))/(y_high - y_low) -- add*halfpoint product calculated at once to avoid possible divide by zero
+		return (limit*x + ah)/(x + (p-m)/(y_high - y_low)) --factored version of above formula
 --		return (limit-add)*x/(x + halfpoint) + add, halfpoint, add
 	else
 		local add = 0
diff --git a/game/modules/tome/data/talents/corruptions/bone.lua b/game/modules/tome/data/talents/corruptions/bone.lua
index 5df76b885a..0ee56b08b5 100644
--- a/game/modules/tome/data/talents/corruptions/bone.lua
+++ b/game/modules/tome/data/talents/corruptions/bone.lua
@@ -144,8 +144,8 @@ newTalent{
 				p.nb = p.nb + 1
 				if p.adv_gfx then
 					if p.particles[1] and p.particles[1]._shader and p.particles[1]._shader.shad then
-						p.particles[1]._shader:setUniform("chargesCount", p.nb)
-						p.particles[1].shader.chargesCount = p.nb
+						p.particles[1]._shader:setUniform("chargesCount", util.bound(p.nb, 0, 10))
+						p.particles[1].shader.chargesCount = util.bound(p.nb, 0, 10)
 					end
 				else
 					p.particles[#p.particles+1] = self:addParticles(Particles.new("bone_shield", 1))
@@ -160,8 +160,8 @@ newTalent{
 		p.nb = p.nb - 1
 		if p.adv_gfx then
 			if p.particles[1] and p.particles[1]._shader and p.particles[1]._shader.shad then
-				p.particles[1]._shader:setUniform("chargesCount", p.nb)
-				p.particles[1].shader.chargesCount = p.nb
+				p.particles[1]._shader:setUniform("chargesCount", util.bound(p.nb, 0, 10))
+				p.particles[1].shader.chargesCount = util.bound(p.nb, 0, 10)
 			end
 		else
 			local pid = table.remove(p.particles)
@@ -177,7 +177,7 @@ newTalent{
 		local adv_gfx = core.shader.allow("adv") and true or false
 		local ps = {}
 		if adv_gfx then
-			ps[1] = self:addParticles(Particles.new("shader_ring_rotating", 1, {toback=true, a=0.5, rotation=0, radius=1.5, img="bone_shield"}, {type="boneshield", chargesCount=nb}))
+			ps[1] = self:addParticles(Particles.new("shader_ring_rotating", 1, {toback=true, a=0.5, rotation=0, radius=1.5, img="bone_shield"}, {type="boneshield", chargesCount=util.bound(nb, 0, 10)}))
 		else
 			for i = 1, nb do ps[#ps+1] = self:addParticles(Particles.new("bone_shield", 1)) end
 		end
-- 
GitLab