Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<root version="3.0">
<properties>
<name>CT Scroll 5e Extension</name>
<version>0.4.1</version>
<version>0.4.1-rc1</version>
<author>fxg42</author>
<description>Increment and decrement NPC combat tracker entry attack bonuses and damage die with the scroll wheel.</description>
<loadorder>100</loadorder>
</properties>

<announcement text="CT Scroll v0.4.1" font="emotefont" icon="raven"/>
<announcement text="CT Scroll v0.4.1-rc1" font="emotefont" icon="raven"/>

<base>
<icon name="raven" file="raven-circ-30x30.png"/>
<icon name="raven" file="raven-circ-30x30.webp"/>
<includefile source="ct/ct_host.xml" />
<script name="CombatManager__proxy" file="scripts/manager_combat2.lua" />
</base>
Expand Down
Binary file removed raven-circ-30x30.png
Binary file not shown.
Binary file added raven-circ-30x30.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 20 additions & 9 deletions scripts/manager_combat2.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
--
-- Different way to call custom functions when adding entry to CT in 5E ruleset
--

local fonRecordTypeEvent;
function onInit()
CombatRecordManager.setRecordTypePostAddCallback("npc", proxy(CombatManager2.onNPCPostAdd, upcastCantrips));
if Session.IsHost then
fonRecordTypeEvent = CombatRecordManager.onRecordTypeEvent;
CombatRecordManager.onRecordTypeEvent = onRecordTypeEventNS;
end
end
function onClose()
if Session.IsHost then
CombatRecordManager.onRecordTypeEvent = fonRecordTypeEvent;
end
end

--
-- Intercepts calls to subject function and executes an advice after the call.
--

function proxy(subjectFn, afterAdvice)
return function(...)
local returnValue = subjectFn(...);
afterAdvice(...);
return returnValue;
end
function onRecordTypeEventNS(sRecordType, tCustom)
fonRecordTypeEvent(sRecordType, tCustom);
upcastCantrips(tCustom);
end

--
Expand All @@ -23,7 +33,7 @@ function upcastCantrips(tCustom)
local nodeEntry = tCustom.nodeCT;
local notches = getNbNotches(getSpellcasterLevel(nodeEntry));
if notches < 1 then return end

forEachCantrip(nodeEntry, function(attackLine, setValue)
if attackLine:find("DMG:") or attackLine:find("HEAL:") then
setValue(updateNbDice(notches, attackLine));
Expand Down Expand Up @@ -74,7 +84,8 @@ function forEachCantrip(nodeEntry, f)
for _, spellTrait in pairs({"spells", "innatespells"}) do
for _, nodePower in pairs(DB.getChildren(nodeEntry, spellTrait)) do
local attackLine = DB.getValue(nodePower, "value", "");
if attackLine:find("cantrip") then
local attackLineLower = string.lower(attackLine);
if attackLineLower:find("cantrip") then
local setValue = function(...) DB.setValue(nodePower, "value", "string", ...) end
f(attackLine, setValue);
end
Expand Down