Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Parker committed Jul 28, 2022
2 parents f00b0aa + e5c3b50 commit 7c53e6e
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 144 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ The following targetable Effects have been added:
* **[R1]TO[R2]: types** - Damage dealt by the bearer of this effect will treat R1 as R2 for any of the damage types, where R1 and R2 may be one of ABSORB, IGNORE, RESIST, or VULN. e.g. "IMMUNETORESIST: radiant" would cause the damage dealt by a paladin's divine smite to treat radiant immunity as radiant resistance instead.
* **MAKEVULN: types** - Damage dealt by the bearer of this effect will treat a creature without any sort of resistance to the damage types as if they were vulnerable. e.g. "MAKEVULN: slashing" would cause a wraith to take double damage from magic swords, but still take half damage from nonmagical, unsilvered swords.
* **REDUCE: n, types** - This functions exactly as RESIST: n, except it will also stack with normal resistance.
* **UNHEALABLE: (types)** - The bearer of this effect cannot benefit from any healing of the associated types. types is optional and may be any combination of "heal", "hitdice", and "rest", seperated by commas. If types is not provided, then all types of healing are prevented.
* **UNHEALABLE: (types)** - The bearer of this effect cannot benefit from any healing of the associated types. types is optional and may be any combination of "heal", "hitdice", and "rest", separated by commas. If types is not provided, then all types of healing are prevented.
* **DMGMULT: n** - The bearer of this effect has all of their damage dealt multiplied by n.
* **HEALMULT: n** - The bearer of this effect has all of their healing done multiplied by n.
* **HEALEDMULT: n, (types)** - The bearer of this effect has all of their healing received multiplied by n. types is optional and may be any combination of "heal", "hitdice", and "rest", seperated by commas. If types is not provided, then all types of healing are multiplied.
* **HEALEDMULT: n, (types)** - The bearer of this effect has all of their healing received multiplied by n. types is optional and may be any combination of "heal", "hitdice", and "rest", separated by commas. If types is not provided, then all types of healing are multiplied.

## Installation
Download [BlissfulIgnorance.ext](https://github.com/MeAndUnique/BlissfulIgnorance/releases) and place in the extensions subfolder of the Fantasy Grounds data folder.
Expand Down
1 change: 1 addition & 0 deletions extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SOFTWARE.

<base>
<script name="ActionDamageBI" file="scripts/manager_action_damage_bi.lua" />
<script name="ActorManagerBI" file="scripts/manager_actor_bi.lua" />
<script name="CharManagerBI" file="scripts/manager_char_bi.lua" />
<script name="CombatManagerBI" file="scripts/manager_combat_bi.lua" />

Expand Down
169 changes: 27 additions & 142 deletions scripts/manager_action_damage_bi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
-- attribution and copyright information.
--

local getReductionTypeOriginal;
local checkReductionTypeHelperOriginal;
local checkNumericalReductionTypeHelperOriginal;
local getDamageAdjustOriginal;
local applyDamageOriginal;
local messageDamageOriginal;

local rActiveTarget;
local bAdjusted = false;
local bIgnored = false;
local tReductions = {};
local bPreventCalculateRecursion = false;
local nAbsorbed = 0;

function onInit()
getReductionTypeOriginal = ActionDamage.getReductionType;
ActionDamage.getReductionType = getReductionType;

checkReductionTypeHelperOriginal = ActionDamage.checkReductionTypeHelper;
ActionDamage.checkReductionTypeHelper = checkReductionTypeHelper;

Expand All @@ -40,139 +36,14 @@ function onInit()
end
end

function getReductionType(rSource, rTarget, sEffectType)
local aFinal = getReductionTypeOriginal(rSource, rTarget, sEffectType);
tReductions[sEffectType] = aFinal;

addExtras(rSource, rTarget, "IGNORE" .. sEffectType, addIgnoredDamageType, sEffectType);

if sEffectType == "IMMUNE" and aFinal["all"] then
local rReduction = aFinal["all"];
aFinal["all"] = nil;
for _,sDamage in ipairs(DataCommon.dmgtypes) do
aFinal[sDamage] = rReduction;
end
end

if sEffectType == "RESIST" then -- Represents the last set
local aAbsorb = getReductionType(rSource, rTarget, "ABSORB");
for _,rAbsorb in pairs(aAbsorb) do
if rAbsorb.mod == 0 then
rAbsorb.mod = 1;
end
rAbsorb.mod = rAbsorb.mod + 1;
rAbsorb.bIsAbsorb = true;
end

local aReduce = getReductionType(rSource, rTarget, "REDUCE");
for sType,rReduce in pairs(aReduce) do
local rResist = tReductions["RESIST"][sType];
if not rResist then
tReductions["RESIST"][sType] = rReduce;
else
rResist.nReduceMod = rReduce.mod;
rResist.aReduceNegatives = rReduce.aNegatives;
end
end

for sOriginalType,_ in pairs(tReductions) do
for sNewType,_ in pairs(tReductions) do
addExtras(rSource, rTarget, sOriginalType .. "TO" .. sNewType, addDemotedDamagedType, sOriginalType, sNewType);
end
end

addExtras(rSource, rTarget, "MAKEVULN", addVulnerableDamageType);
end

return aFinal;
end

function addExtras(rSource, rTarget, sEffect, fAdd, sPrimaryReduction, sSecondaryReduction)
local bHandledAll = false;
local aEffects = EffectManager5E.getEffectsByType(rSource, sEffect, {}, rTarget);
for _,rEffect in pairs(aEffects) do
for _,sType in pairs(rEffect.remainder) do
if sType == "all" then
for _,sDamage in ipairs(DataCommon.dmgtypes) do
fAdd(sDamage, sPrimaryReduction, sSecondaryReduction);
end
bHandledAll = true;
break;
end
fAdd(sType, sPrimaryReduction, sSecondaryReduction);
end
if bHandledAll then
break;
end
end
end

function addIgnoredDamageType(sDamageType, sIgnoredType)
local aEffects = tReductions[sIgnoredType];
local rReduction = aEffects[sDamageType];
if rReduction then
if not rReduction.aIgnored then
rReduction.aIgnored = {};
end
table.insert(rReduction.aIgnored, sDamageType);
end

rReduction = aEffects["all"];
if rReduction then
if not rReduction.aIgnored then
rReduction.aIgnored = {};
end
table.insert(rReduction.aIgnored, sDamageType);
end
end

function addDemotedDamagedType(sDamageType, sOriginalType, sNewType)
local aOriginalEffects = tReductions[sOriginalType];
local aNewEffects = tReductions[sNewType]
local rReduction = aOriginalEffects[sDamageType];
if rReduction and not (rReduction.aIgnored and StringManager.contains(rReduction.aIgnored, sDamageType)) then
rReduction.bDemoted = true;
local rDemoted = getDemotedEffect(aNewEffects, sDamageType);
rDemoted.sDemotedFrom = sOriginalType;
end

rReduction = aOriginalEffects["all"];
if rReduction and not (rReduction.aIgnored and StringManager.contains(rReduction.aIgnored, sDamageType)) then
rReduction.bDemoted = true;
local rDemoted = getDemotedEffect(aNewEffects, sDamageType);
rDemoted.sDemotedFrom = sOriginalType;
end
end

function getDemotedEffect(aDemotedEffects, sDamageType)
local rDemoted = aDemotedEffects[sDamageType];
if not rDemoted then
rDemoted = {
mod = 0;
aNegatives = {}
};
aDemotedEffects[sDamageType] = rDemoted;
end
return rDemoted;
end

function addVulnerableDamageType(sDamageType)
local aEffects = tReductions["VULN"];
aEffects[sDamageType] = {
mod = 0,
aNegatives = {},
bAddIfUnresisted = true
};
end

function checkReductionTypeHelper(rMatch, aDmgType)
local result = checkReductionTypeHelperOriginal(rMatch, aDmgType);
if bPreventCalculateRecursion then
return result;
end

if result then
if ActionDamage.checkNumericalReductionType(tReductions["ABSORB"], aDmgType) ~= 0 then
if ActionDamage.checkNumericalReductionType(rActiveTarget.tReductions["ABSORB"], aDmgType) ~= 0 then
result = false;
elseif rMatch.aIgnored then
for _,sIgnored in pairs(rMatch.aIgnored) do
Expand All @@ -187,14 +58,14 @@ function checkReductionTypeHelper(rMatch, aDmgType)
result = false;
elseif rMatch.bAddIfUnresisted then
bPreventCalculateRecursion = true;
result = not ActionDamage.checkReductionType(tReductions["RESIST"], aDmgType) and
not ActionDamage.checkReductionType(tReductions["IMMUNE"], aDmgType) and
not ActionDamage.checkReductionType(tReductions["ABSORB"], aDmgType);
result = not ActionDamage.checkReductionType(rActiveTarget.tReductions["RESIST"], aDmgType) and
not ActionDamage.checkReductionType(rActiveTarget.tReductions["IMMUNE"], aDmgType) and
not ActionDamage.checkReductionType(rActiveTarget.tReductions["ABSORB"], aDmgType);
bPreventCalculateRecursion = false;
end
elseif rMatch and (rMatch.mod ~= 0) then
if rMatch.sDemotedFrom then
local aMatches = tReductions[rMatch.sDemotedFrom];
local aMatches = rActiveTarget.tReductions[rMatch.sDemotedFrom];
bPreventCalculateRecursion = true;
result = ActionDamage.checkReductionType(aMatches, aDmgType) or
ActionDamage.checkNumericalReductionType(aMatches, aDmgType) ~= 0;
Expand Down Expand Up @@ -247,7 +118,8 @@ function checkNumericalReductionTypeHelper(rMatch, aDmgType, nLimit)
end

function getDamageAdjust(rSource, rTarget, nDamage, rDamageOutput)
tReductions = {
rActiveTarget = rTarget;
rTarget.tReductions = {
["VULN"] = {},
["RESIST"] = {},
["IMMUNE"] = {},
Expand All @@ -269,7 +141,7 @@ function getDamageAdjust(rSource, rTarget, nDamage, rDamageOutput)
end
end

local nLocalAbsorb = ActionDamage.checkNumericalReductionType(tReductions["ABSORB"], aSrcDmgClauseTypes);
local nLocalAbsorb = ActionDamage.checkNumericalReductionType(rTarget.tReductions["ABSORB"], aSrcDmgClauseTypes);
if nLocalAbsorb ~= 0 then
nDamageAdjust = nDamageAdjust - (v * nLocalAbsorb);
for _,sDamageType in ipairs(aSrcDmgClauseTypes) do
Expand Down Expand Up @@ -328,7 +200,12 @@ function multiplyDamage(rSource, rTarget, rDamageOutput)
rDamageOutput.nVal = math.max(math.floor(rDamageOutput.nVal * nMult), 1);
end

function applyDamage(rSource, rTarget, bSecret, sDamage, nTotal)
function applyDamage(rSource, rTarget, vRollOrSecret, sDamage, nTotal)
if type(vRollOrSecret) == "table" then
sDamage = vRollOrSecret.sDesc;
nTotal = vRollOrSecret.nTotal;
end

if string.match(sDamage, "%[RECOVERY")
or string.match(sDamage, "%[HEAL")
or nTotal < 0 then
Expand Down Expand Up @@ -358,14 +235,22 @@ function applyDamage(rSource, rTarget, bSecret, sDamage, nTotal)
end
end

applyDamageOriginal(rSource, rTarget, bSecret, sDamage, nTotal);
applyDamageOriginal(rSource, rTarget, vRollOrSecret, sDamage, nTotal);
end

function messageDamage(rSource, rTarget, bSecret, sDamageType, sDamageDesc, sTotal, sExtraResult)
function messageDamage(rSource, rTarget, vRollOrSecret, sDamageText, sDamageDesc, sTotal, sExtraResult)
if type(vRollOrSecret) == "table" then
local rRoll = vRollOrSecret;
sDamageText = rRoll.sDamageText;
sDamageDesc = rRoll.sDesc;
sTotal = rRoll.nTotal;
sExtraResult = rRoll.sResults;
end

if nAbsorbed < 0 then
local nDamage = nAbsorbed;
nAbsorbed = 0;
ActionDamage.applyDamage(rSource, rTarget, bSecret, sDamageType, nDamage);
ActionDamage.applyDamage(rSource, rTarget, vRollOrSecret, sDamageText, nDamage);
else
if string.match(sDamageDesc, "%[UNHEALABLE") then
if sExtraResult ~= "" then
Expand All @@ -377,6 +262,6 @@ function messageDamage(rSource, rTarget, bSecret, sDamageType, sDamageDesc, sTot
if sMult then
sExtraResult = sExtraResult .. sMult;
end
messageDamageOriginal(rSource, rTarget, bSecret, sDamageType, sDamageDesc, sTotal, sExtraResult);
messageDamageOriginal(rSource, rTarget, vRollOrSecret, sDamageText, sDamageDesc, sTotal, sExtraResult);
end
end
Loading

0 comments on commit 7c53e6e

Please sign in to comment.