Skip to content

Commit

Permalink
Fixed: Immunity to Contamination not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rhagelstrom committed Jan 21, 2024
1 parent 529d9a1 commit 3c0ee0d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Build FG Extension](https://github.com/rhagelstrom/Contaminated/actions/workflows/create-release.yml/badge.svg)](https://github.com/rhagelstrom/Contaminated/actions/workflows/create-release.yml) [![Luacheckrc](https://github.com/rhagelstrom/Contaminated/actions/workflows/luacheck.yml/badge.svg)](https://github.com/rhagelstrom/Contaminated/actions/workflows/luacheck.yml)
# Contaminated

**Current Version:** 1.2
**Last Updated:** 09/12/23
**Current Version:** 1.3
**Last Updated:** 01/21/23

5E extension for FantasyGrounds that adds contamination as a condition as well as immunities to the contamination condition for support of [Dungeons of Drakkenheim](https://ghostfiregaming.com/dungeons-of-drakkenheim/)

Expand Down
4 changes: 2 additions & 2 deletions extension.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<root release="3.0" version="3">
<announcement text="Contaminated v1.2\rby Ryan Hagelstrom 2022-2023" font="emotefont" icon="Contaminated" />
<announcement text="Contaminated v1.3\rby Ryan Hagelstrom 2022-2024" font="emotefont" icon="Contaminated" />
<properties>
<loadorder>120</loadorder>
<name>Feature: Contaminated</name>
<version>1.2</version>
<version>1.3</version>
<author>Ryan Hagelstrom</author>
<description>Adds contamination as a 5E condition and automates the contamination stack</description>
<ruleset>
Expand Down
66 changes: 49 additions & 17 deletions scripts/contaminated.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,56 @@ function sumContamination(rActor, nContaminationLevel)
return nSummed;
end

function cleanContaminationEffect(rNewEffect)
function cleanContaminationEffect(sUser, _, nodeCT, rNewEffect, bShowMsg)
local nContaminationLevel = 0;
local rTarget = ActorManager.resolveActor(nodeCT);
local rSource = ActorManager.resolveActor(rNewEffect.sSource);
local sOriginal = rNewEffect.sName;
local aImmuneConditions = ActorManager5E.getConditionImmunities(rTarget, rSource);
local aNewEffectComps = {};
local aIgnoreComps = {};
local bImmune = false;
if StringManager.contains(aImmuneConditions, 'contamination') then
bImmune = true;
end
local aEffectComps = EffectManager.parseEffect(rNewEffect.sName);
for i, sEffectComp in ipairs(aEffectComps) do
for _, sEffectComp in ipairs(aEffectComps) do
local rEffectComp = EffectManager.parseEffectCompSimple(sEffectComp);
if rEffectComp.type:lower() == 'contamination' or rEffectComp.original:lower() == 'contamination' then
if rEffectComp.mod == 0 then
rEffectComp.mod = 1;
sEffectComp = sEffectComp .. ': 1';
if bImmune then
table.insert(aIgnoreComps, sEffectComp);
else
if rEffectComp.mod == 0 then
rEffectComp.mod = 1;
sEffectComp = sEffectComp .. ': 1';
end
nContaminationLevel = rEffectComp.mod;
table.insert(aNewEffectComps, sEffectComp:upper())
end
else
table.insert(aNewEffectComps, sEffectComp);
end
end
rNewEffect.sName = EffectManager.rebuildParsedEffect(aNewEffectComps);
if next(aIgnoreComps) then
if bShowMsg then
local bSecret = ((rNewEffect.nGMOnly or 0) == 1);
local sMessage;
if rNewEffect.sName == '' then
sMessage = string.format('%s [\'%s\'] -> [%s]', Interface.getString('effect_label'), sOriginal,
Interface.getString('effect_status_targetimmune'));
else
sMessage = string.format('%s [\'%s\'] -> [%s] [%s]', Interface.getString('effect_label'), sOriginal,
Interface.getString('effect_status_targetpartialimmune'), table.concat(aIgnoreComps, ','));
end
if bSecret then
EffectManager.message(sMessage, nodeCT, true);
else
EffectManager.message(sMessage, nodeCT, false, sUser);
end
aEffectComps[i] = sEffectComp:upper();
nContaminationLevel = rEffectComp.mod;
end
end

rNewEffect.sName = EffectManager.rebuildParsedEffect(aEffectComps);
return nContaminationLevel;
end

Expand Down Expand Up @@ -213,17 +247,15 @@ function customAddEffect(sUser, sIdentity, nodeCT, rNewEffect, bShowMsg)
return addEffect(sUser, sIdentity, nodeCT, rNewEffect, bShowMsg);
end
local nContaminated = nil;
local nContaminationLevel = cleanContaminationEffect(rNewEffect);
local nContaminationLevel = cleanContaminationEffect(sUser, sIdentity, nodeCT, rNewEffect, bShowMsg);
-- Immune casued an empty effect so ignore
if rNewEffect.sName == '' then
return;
end
if nContaminationLevel > 0 then
local rActor = ActorManager.resolveActor(nodeCT);
local aCancelled = EffectManager5E.checkImmunities(nil, rActor, rNewEffect);
local bGMOnly = false
if #aCancelled > 0 then
local sMessage = string.format('%s [\'%s\'] -> [%s]', Interface.getString('effect_label'), rNewEffect.sName,
Interface.getString('effect_status_targetimmune'));
EffectManager.message(sMessage, nodeCT, false, sUser);
return
end
local bGMOnly = false;

nContaminated = sumContamination(rActor, nContaminationLevel)
if nContaminated then
nContaminationLevel = nContaminated;
Expand Down

0 comments on commit 3c0ee0d

Please sign in to comment.