Repository: PathOfBuildingCommunity/PathOfBuilding
File: src/Modules/CalcOffence.lua (Lua)

Code before:
				slotName = skillCfg.slotName,
				flags = bor(ModFlag.Dot, ModFlag.Ailment, band(cfg.flags, ModFlag.WeaponMask), band(cfg.flags, ModFlag.Melee) ~= 0 and ModFlag.MeleeHit or 0),
				keywordFlags = bor(band(cfg.keywordFlags, bnot(KeywordFlag.Hit)), KeywordFlag.Bleed, KeywordFlag.Ailment, KeywordFlag.PhysicalDot),
				skillCond = setmetatable({["CriticalStrike"] = true }, { __index = function(table, key) return skillCfg.skillCond[key] or cfg.skillCond[key] end } ),
				skillDist = skillCfg.skillDist,
			}
			local dotCfg = pass.label ~= "Off Hand" and activeSkill.bleedCfg or activeSkill.OHbleedCfg
			checkWeapon1HFlags(dotCfg)
			local avgCritBleedDmg, sourceMinCritDmg, sourceMaxCritDmg, avgHitBleedDmg, sourceMinHitDmg, sourceMaxHitDmg
			if breakdown then
				breakdown.BleedPhysical = { damageTypes = { } }
			end

			-- For bleeds we will be using a weighted average calculation
			local configStacks = enemyDB:Sum("BASE", nil, "Multiplier:BleedStacks")
			local maxStacks = skillModList:Override(cfg, "BleedStacksMax") or skillModList:Sum("BASE", cfg, "BleedStacksMax")
			local overrideStackPotential = skillModList:Override(nil, "BleedStackPotentialOverride") and skillModList:Override(nil, "BleedStackPotentialOverride") / maxStacks
			globalOutput.BleedStacksMax = maxStacks
			local durationBase = skillData.bleedDurationIsSkillDuration and skillData.duration or data.misc.BleedDurationBase
			local durationMod = calcLib.mod(skillModList, dotCfg, "EnemyBleedDuration", "EnemyAilmentDuration", "SkillAndDamagingAilmentDuration", skillData.bleedIsSkillEffect and "Duration" or nil) * calcLib.mod(enemyDB, nil, "SelfBleedDuration", "SelfAilmentDuration") / calcLib.mod(enemyDB, dotCfg, "BleedExpireRate")
			durationMod = m_max(durationMod, 0)
			local rateMod = calcLib.mod(skillModList, cfg, "BleedFaster") + enemyDB:Sum("INC", nil, "SelfBleedFaster")  / 100
			globalOutput.BleedDuration = durationBase * durationMod / rateMod * debuffDurationMult

			-- The average number of bleeds that will be active on the enemy at once
			local bleedStacks = (output.HitChance / 100) * (output.BleedChanceOnHit / 100) * (globalOutput.BleedDuration / (output.HitTime or output.Time) * skillData.dpsMultiplier)
			local activeTotems = env.modDB:Override(nil, "TotemsSummoned") or skillModList:Sum("BASE", skillCfg, "ActiveTotemLimit", "ActiveBallistaLimit")
			if skillFlags.totem then
				bleedStacks = (output.HitChance / 100) * (output.BleedChanceOnHit / 100) * (globalOutput.BleedDuration / (output.HitTime or output.Time) * skillData.dpsMultiplier) * activeTotems
			end
			if configStacks > 0 then
				bleedStacks =  configStacks
			end

			if bleedStacks < 1 and (overrideStackPotential or 0) <= 1 then
				skillModList:NewMod("Condition:SingleBleed", "FLAG", true, "bleed")
			end

			-- ratio of bleeds applied : max effective bleeds
			globalOutput.BleedStackPotential = overrideStackPotential or (bleedStacks / maxStacks)

			if globalBreakdown then
				globalBreakdown.BleedStackPotential = {"Ratio of bleed stacks to maximum active bleeds:"}
				if overrideStackPotential then
					t_insert(globalBreakdown.BleedStackPotential, s_format("= %g ^8(stack potential override)", overrideStackPotential))
				else
					t_insert(globalBreakdown.BleedStackPotential, s_format("%.2f ^8(chance to hit)", output.HitChance / 100))
					t_insert(globalBreakdown.BleedStackPotential, s_format("* %.2f ^8(chance to bleed)", output.BleedChanceOnHit / 100))
					t_insert(globalBreakdown.BleedStackPotential, s_format("* (%.2f / %.2f) ^8(Bleed duration / Attack Time)", globalOutput.BleedDuration, (output.HitTime or output.Time)))
					if skillData.dpsMultiplier ~= 1 then
						t_insert(globalBreakdown.BleedStackPotential, s_format("* %g ^8(DPS multiplier for this skill)", skillData.dpsMultiplier))

Review comment (suggestion):
output.HitChance is not the right multiplier if you have perfect agony. it should probably be replaced by some mix of output.HitChance * output.BleedChanceOnHit and output.CritChance * output.BleedChanceOnCrit.

Code after:
				end
			end
			return baseVal
		end

		-- Calculate bleeding chance and damage
		if canDeal.Physical and (output.BleedChanceOnHit + output.BleedChanceOnCrit) > 0 then
			activeSkill[pass.label ~= "Off Hand" and "bleedCfg" or "OHbleedCfg"] = {
				skillName = skillCfg.skillName,
				skillPart = skillCfg.skillPart,
				skillTypes = skillCfg.skillTypes,
				slotName = skillCfg.slotName,
				flags = bor(ModFlag.Dot, ModFlag.Ailment, band(cfg.flags, ModFlag.WeaponMask), band(cfg.flags, ModFlag.Melee) ~= 0 and ModFlag.MeleeHit or 0),
				keywordFlags = bor(band(cfg.keywordFlags, bnot(KeywordFlag.Hit)), KeywordFlag.Bleed, KeywordFlag.Ailment, KeywordFlag.PhysicalDot),
				skillCond = setmetatable({["CriticalStrike"] = true }, { __index = function(table, key) return skillCfg.skillCond[key] or cfg.skillCond[key] end } ),
				skillDist = skillCfg.skillDist,
			}
			local dotCfg = pass.label ~= "Off Hand" and activeSkill.bleedCfg or activeSkill.OHbleedCfg
			checkWeapon1HFlags(dotCfg)
			local avgCritBleedDmg, sourceMinCritDmg, sourceMaxCritDmg, avgHitBleedDmg, sourceMinHitDmg, sourceMaxHitDmg
			if breakdown then
				breakdown.BleedPhysical = { damageTypes = { } }
			end

			-- For bleeds we will be using a weighted average calculation
			local configStacks = enemyDB:Sum("BASE", nil, "Multiplier:BleedStacks")
			local maxStacks = skillModList:Override(cfg, "BleedStacksMax") or skillModList:Sum("BASE", cfg, "BleedStacksMax")
			local overrideStackPotential = skillModList:Override(nil, "BleedStackPotentialOverride") and skillModList:Override(nil, "BleedStackPotentialOverride") / maxStacks
			globalOutput.BleedStacksMax = maxStacks
			local durationBase = skillData.bleedDurationIsSkillDuration and skillData.duration or data.misc.BleedDurationBase
			local durationMod = calcLib.mod(skillModList, dotCfg, "EnemyBleedDuration", "EnemyAilmentDuration", "SkillAndDamagingAilmentDuration", skillData.bleedIsSkillEffect and "Duration" or nil) * calcLib.mod(enemyDB, nil, "SelfBleedDuration", "SelfAilmentDuration") / calcLib.mod(enemyDB, dotCfg, "BleedExpireRate")
			durationMod = m_max(durationMod, 0)
			local rateMod = calcLib.mod(skillModList, cfg, "BleedFaster") + enemyDB:Sum("INC", nil, "SelfBleedFaster")  / 100
			globalOutput.BleedDuration = durationBase * durationMod / rateMod * debuffDurationMult

			-- The chance any given hit applies bleed
			local bleedChance = output.BleedChanceOnHit / 100 * (1 - output.CritChance / 100) + output.BleedChanceOnCrit / 100 * output.CritChance / 100
			-- The average number of bleeds that will be active on the enemy at once
			local bleedStacks = output.HitChance / 100 * bleedChance * skillData.dpsMultiplier
			if (globalOutput.HitSpeed or globalOutput.Speed) > 0 then
				--assume skills with no cast, attack, or cooldown time are single cast
				bleedStacks = bleedStacks * globalOutput.BleedDuration * (globalOutput.HitSpeed or globalOutput.Speed)
			end
			local activeTotems = env.modDB:Override(nil, "TotemsSummoned") or skillModList:Sum("BASE", skillCfg, "ActiveTotemLimit", "ActiveBallistaLimit")
			if skillFlags.totem then
				bleedStacks = bleedStacks * activeTotems
			end
			if configStacks > 0 then
				bleedStacks =  configStacks
			end