Skip to content

Commit

Permalink
Merge pull request #2 from JustinFreitas/v1.2
Browse files Browse the repository at this point in the history
V1.2 - Works with FGU 4.1.14+ and won't double the bonus again.
  • Loading branch information
JustinFreitas authored Mar 16, 2022
2 parents 229a763 + 0d2b590 commit 8d92a7e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

https://github.com/JustinFreitas/AspectOfTheBeastBear

Aspect Of The Beast: Bear v1.1, by Justin Freitas
Aspect Of The Beast: Bear v1.2, by Justin Freitas

ReadMe and Usage Notes

The purpose of this Fantasy Grounds 5e extension is to apply an additional 2x multiplier to encumbrance limits to barbarians of level 6 or higher that have the Aspect of the Beast: Bear listed in their features. The 'Bear' designation can be separated from the main feature with a dash or colon (i.e. - or :). Any amount of white space is also fine as it's matched via a flexible regular expression.
The purpose of this Fantasy Grounds 5e extension is to apply an additional 2x multiplier to encumbrance limits to barbarians of level 6 or higher that have the Aspect of the Beast: Bear listed in their features. The 'Bear' designation can be separated from the main feature with a dash or colon (i.e. - or :). Any amount of white space is also fine as it's matched via a flexible regular expression. Note, that if the client is FGU of 4.1.14 or greater, this functionality is built in and works off of 'Aspect of the Bear' by default, so the extension will be smart and not double up the bonus a second time if both are found.

Future Enhancements:
- Have the barbarian class and level filtering be an option instead of always enabled, defaulting to enabled.

Changelist:
- v1.0 - Initial version.
- v1.1 - Improvements to conform to FGU and upcoming standards. Improvements in code structure. Matching/regex improvements for flexibility and reliability. Function renaming for clarity.
- v1.2 - Fixed the extension to work with the FGU 4.1.14+ Aspect of the Bear functionality and not double the bonus a second time.
4 changes: 2 additions & 2 deletions extension.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<root version="3.3">
<announcement text="Aspect of the Beast: Bear v1.1, FGC/FGU, 5E\rCopyright 2021 Justin Freitas (11/17/21)" font="emotefont" icon="bear_icon" />
<announcement text="Aspect of the Beast: Bear v1.2, 3/15/22\r2021-22 Justin Freitas, FGC/FGU 5E" font="emotefont" icon="bear_icon" />
<properties>
<name>Feature: Aspect of the Beast - Bear</name>
<version>1.1</version>
<version>1.2</version>
<loadorder>998</loadorder>
<author>Justin Freitas</author>
<description>Double encumbrance limits if character is a barbarian of level six or higher and has Aspect of the Beast: Bear in their Features.</description>
Expand Down
52 changes: 34 additions & 18 deletions scripts/aspect_of_the_beast_bear.lua
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
-- (c) Copyright Justin Freitas 2021+ except where explicitly stated otherwise.
-- Fantasy Grounds is Copyright (c) 2004-2021 SmiteWorks USA LLC.
-- Copyright to other material within this file may be held by other Individuals and/or Entities.
-- Nothing in or from this LUA file in printed, electronic and/or any other form may be used, copied,
-- transmitted or otherwise manipulated in ANY way without the explicit written consent of
-- Justin Freitas or, where applicable, any and all other Copyright holders.
local getEncumbranceMult_orig
local bBearFromFGU

function onInit()
CharManager.getEncumbranceMultAspectOfTheBeastBear = CharManager.getEncumbranceMult
getEncumbranceMult_orig = CharManager.getEncumbranceMult
CharManager.getEncumbranceMult = getEncumbranceMultOverride

local featureNamePath = "charsheet.*.featurelist.*.name"
DB.addHandler(featureNamePath, "onAdd", onFeatureNameAddOrUpdate)
DB.addHandler(featureNamePath, "onUpdate", onFeatureNameAddOrUpdate)
bBearFromFGU = checkBearFromFGU()
end

-- This is entered on strength change or trait change (not feature) due to the way record_char_inventory.xml works.
function checkBearFromFGU()
local nMajor, nMinor, nPatch = Interface.getVersion()
return nMajor >= 4 and nMinor >= 1 and nPatch >= 14
end

-- This is entered on strength change or trait change (not feature)
-- due to the way record_char_inventory.xml works.
-- See: <number_linked name="encumbrancebase" source="encumbrance.encumbered">
function getEncumbranceMultOverride(nodeChar)
local mult = CharManager.getEncumbranceMultAspectOfTheBeastBear(nodeChar)
if isBarbarianOfLevelSixOrHigher(nodeChar) and hasAspectOfTheBeastBear(nodeChar) then
local mult = getEncumbranceMult_orig(nodeChar)
if isBarbarianOfLevelSixOrHigher(nodeChar) and
hasAspectOfTheBeastBearIndependentOfFGU(nodeChar) then
mult = mult * 2
end

return mult
end

function hasAspectOfTheBeastBear(nodeChar)
function hasAspectOfTheBeastBearIndependentOfFGU(nodeChar)
local bBear, bBeastBear
for _, nodeFeature in pairs(DB.getChildren(nodeChar, "featurelist")) do
if string.match(DB.getValue(nodeFeature, "name", ""):lower(), "^%W*aspect%W+of%W+the%W+beast%W*bear%W*$") then
return true
local name = DB.getValue(nodeFeature, "name", ""):lower()
if string.match(name, "^%W*aspect%W+of%W+the%W+beast%W*bear%W*$") then
bBeastBear = true;
elseif string.match(name, "^%W*aspect%W+of%W+the%W+bear%W*$") then
bBear = true;
end
end

return false
return (bBear and not bBearFromFGU) or
(bBeastBear and not bBearFromFGU) or
(bBeastBear and not bBear and bBearFromFGU)
end

function isBarbarianOfLevelSixOrHigher(nodeChar)
for _, nodeClass in pairs(DB.getChildren(nodeChar, "classes")) do
if DB.getValue(nodeClass, "name", ""):lower() == "barbarian" and DB.getValue(nodeClass, "level", 0) >= 6 then
if DB.getValue(nodeClass, "name", ""):lower() == "barbarian" and
DB.getValue(nodeClass, "level", 0) >= 6 then
return true
end
end
Expand All @@ -55,9 +66,14 @@ function onFeatureNameAddOrUpdate(nodeFeatureName)
end

function updateInventoryPaneEncumbranceBaseIfLoaded(w)
if not (w and w.inventory and w.inventory.subwindow and w.inventory.subwindow.contents and w.inventory.subwindow.contents.subwindow
and w.inventory.subwindow.contents.subwindow.encumbrancebase
and w.inventory.subwindow.contents.subwindow.encumbrancebase.onTraitsUpdated) then return end
if not (w and w.inventory
and w.inventory.subwindow
and w.inventory.subwindow.contents
and w.inventory.subwindow.contents.subwindow
and w.inventory.subwindow.contents.subwindow.encumbrancebase
and w.inventory.subwindow.contents.subwindow.encumbrancebase.onTraitsUpdated) then
return
end

-- See: <number_linked name="encumbrancebase" source="encumbrance.encumbered">
w.inventory.subwindow.contents.subwindow.encumbrancebase.onTraitsUpdated()
Expand Down

0 comments on commit 8d92a7e

Please sign in to comment.