diff --git a/campaign/scripts/5e_char_weapon.lua b/campaign/scripts/5e_char_weapon.lua
index daf0f97..8a25332 100644
--- a/campaign/scripts/5e_char_weapon.lua
+++ b/campaign/scripts/5e_char_weapon.lua
@@ -3,45 +3,16 @@
-- attribution and copyright information.
--
--- luacheck: globals setAmmoVis maxammo.setLink
-local function setAmmoVis()
- local nodeWeapon = getDatabaseNode()
- local bLoading = AmmunitionManager.hasLoadAction(nodeWeapon)
- isloaded.setVisible(bLoading)
-
- local nodeAmmoLink = AmmunitionManager.getAmmoNode(nodeWeapon)
- local bRanged = AmmunitionManager.isWeaponRanged(nodeWeapon)
- ammocounter.setVisible(bRanged and not nodeAmmoLink)
- ammopicker.setComboBoxVisible(bRanged and nodeAmmoLink)
- ammopicker.setComboBoxReadOnly(true)
-
- local nodeCount
- if nodeAmmoLink then nodeCount = DB.getChild(nodeAmmoLink, 'count') end
- maxammo.setLink(nodeCount, nodeCount ~= nil)
-end
-
--- luacheck: globals onDataChanged
-function onInit()
- local nodeWeapon = getDatabaseNode();
- local nodeChar = DB.getChild(nodeWeapon, "...");
- DB.addHandler(nodeWeapon, "onChildUpdate", onDataChanged);
- DB.addHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", onDataChanged);
- DB.addHandler(DB.getPath(nodeChar, "weapon.twoweaponfighting"), "onUpdate", onDataChanged);
-
- onDataChanged(nodeWeapon);
+-- luacheck: globals isLoading
+function isLoading(nodeWeapon)
+ Debug.console('AmmunitionManager char_weapon isLoading - DEPRECATED - 2023-03-20 - Use AmmunitionManager.hasLoadAction')
+ return AmmunitionManager.hasLoadAction(nodeWeapon)
end
-function onClose()
- local nodeWeapon = getDatabaseNode();
- local nodeChar = DB.getChild(nodeWeapon, "...");
- DB.removeHandler(nodeWeapon, "onChildUpdate", onDataChanged);
- DB.removeHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", onDataChanged);
- DB.removeHandler(DB.getPath(nodeChar, "weapon.twoweaponfighting"), "onUpdate", onDataChanged);
-end
--- luacheck: globals onLinkChanged
local m_sClass = "";
local m_sRecord = "";
+-- luacheck: globals onLinkChanged
function onLinkChanged()
local node = getDatabaseNode();
local sClass, sRecord = DB.getValue(node, "shortcut", "", "");
@@ -56,50 +27,61 @@ function onLinkChanged()
end
end
--- luacheck: globals onAttackChanged onDamageChanged
-function onDataChanged()
- onLinkChanged();
- onAttackChanged();
- onDamageChanged();
+-- luacheck: globals onDamageAction
+function onDamageAction(draginfo)
+ local nodeWeapon = getDatabaseNode()
+ local nodeChar = DB.getChild(nodeWeapon, '...')
- setAmmoVis()
-end
+ -- Build basic damage action record
+ local rAction = CharWeaponManager.buildDamageAction(nodeChar, nodeWeapon)
--- luacheck: globals highlightAttack
-function highlightAttack(bOnControl)
- if bOnControl then
- attackshade.setFrame("rowshade");
- else
- attackshade.setFrame(nil);
- end
-end
+ -- Perform damage action
+ local rActor = ActorManager.resolveActor(nodeChar)
-function onAttackChanged()
- local nodeWeapon = getDatabaseNode();
- local nodeChar = DB.getChild(nodeWeapon, "...")
+ -- Celestian adding itemPath to rActor so that when effects
+ -- are checked we can compare against action only effects
+ local _, sRecord = DB.getValue(nodeWeapon, 'shortcut', '', '')
+ rActor.itemPath = sRecord
+ -- end Adanced Effects piece ---
- local nMod = CharWeaponManager.getAttackBonus(nodeChar, nodeWeapon);
+ -- bmos adding ammoPath for AmmunitionManager + Advanced Effects integration
+ -- add this in the onDamageAction function of other effects to maintain compatibility
+ if AmmunitionManager then
+ local nodeAmmo = AmmunitionManager.getAmmoNode(nodeWeapon, rActor)
+ if nodeAmmo then rActor.ammoPath = DB.getPath(nodeAmmo) end
+ end
+ -- end bmos adding ammoPath
- attackview.setValue(nMod);
+ ActionDamage.performRoll(draginfo, rActor, rAction)
+ return true
end
--- luacheck: globals onAttackAction
-function onAttackAction(draginfo)
- local nodeWeapon = getDatabaseNode();
- local nodeChar = DB.getChild(nodeWeapon, "...")
+-- luacheck: globals setAmmoVis maxammo.setLink
+function setAmmoVis(nodeWeapon, ...)
+ if super and super.setAmmoVis then super.setAmmoVis(nodeWeapon, ...) end
- -- Build basic attack action record
- local rAction = CharWeaponManager.buildAttackAction(nodeChar, nodeWeapon);
+ local bLoading = AmmunitionManager.hasLoadAction(nodeWeapon)
+ isloaded.setVisible(bLoading)
- -- Decrement ammo
- if rAction.range == "R" then
- CharWeaponManager.decrementAmmo(nodeChar, nodeWeapon);
- end
+ local nodeAmmoLink = AmmunitionManager.getAmmoNode(nodeWeapon)
+ local bRanged = AmmunitionManager.isWeaponRanged(nodeWeapon)
+ ammocounter.setVisible(bRanged and not nodeAmmoLink)
+ ammopicker.setComboBoxVisible(bRanged and nodeAmmoLink)
+ ammopicker.setComboBoxReadOnly(true)
- -- Perform action
- local rActor = ActorManager.resolveActor(nodeChar);
+ local nodeCount
+ if nodeAmmoLink then nodeCount = DB.getChild(nodeAmmoLink, 'count') end
+ maxammo.setLink(nodeCount, nodeCount ~= nil)
+end
- -- AMMUNITION MANAGER CHANGES
+-- luacheck: globals onDataChanged
+function onDataChanged(nodeWeapon) self.setAmmoVis(nodeWeapon) end
+
+local onAttackAction_old
+local function onAttackAction_new(draginfo, ...)
+ local nodeWeapon = getDatabaseNode()
+ local nodeChar = DB.getChild(nodeWeapon, '...')
+ local rActor = ActorManager.resolveActor(nodeChar)
local nAmmo, bInfiniteAmmo = AmmunitionManager.getAmmoRemaining(rActor, nodeWeapon, AmmunitionManager.getAmmoNode(nodeWeapon))
local messagedata = { text = '', sender = rActor.sName, font = 'emotefont' }
@@ -110,6 +92,7 @@ function onAttackAction(draginfo)
if not bLoading or bIsLoaded then
if bInfiniteAmmo or nAmmo > 0 then
if bLoading then DB.setValue(nodeAmmoManager, 'isloaded', 'number', 0) end
+ return onAttackAction_old(draginfo, ...)
end
messagedata.text = Interface.getString('char_message_atkwithnoammo')
Comm.deliverChatMessage(messagedata)
@@ -119,48 +102,29 @@ function onAttackAction(draginfo)
local sWeaponName = DB.getValue(nodeWeapon, 'name', 'weapon')
messagedata.text = string.format(Interface.getString('char_actions_notloaded'), sWeaponName, true, rActor)
Comm.deliverChatMessage(messagedata)
- return false
end
- -- END AMMUNITION MANAGER CHANGES
-
- ActionAttack.performRoll(draginfo, rActor, rAction);
- return true;
+ -- end bmos only allowing attacks when ammo is sufficient
end
-function onDamageChanged()
- local nodeWeapon = getDatabaseNode();
- local nodeChar = DB.getChild(nodeWeapon, "...")
-
- local sDamage = CharWeaponManager.buildDamageString(nodeChar, nodeWeapon);
+function onInit()
+ if super and super.onInit then super.onInit() end
- damageview.setValue(sDamage);
-end
+ if super and super.onAttackAction then
+ onAttackAction_old = super.onAttackAction
+ super.onAttackAction = onAttackAction_new
+ end
--- luacheck: globals onDamageAction
-function onDamageAction(draginfo)
local nodeWeapon = getDatabaseNode()
- local nodeChar = DB.getChild(nodeWeapon, '...')
-
- -- Build basic damage action record
- local rAction = CharWeaponManager.buildDamageAction(nodeChar, nodeWeapon)
+ DB.addHandler(DB.getPath(nodeWeapon), 'onChildUpdate', onDataChanged)
- -- Perform damage action
- local rActor = ActorManager.resolveActor(nodeChar)
+ self.onDataChanged(nodeWeapon)
+end
- -- Celestian adding itemPath to rActor so that when effects
- -- are checked we can compare against action only effects
- local _, sRecord = DB.getValue(nodeWeapon, 'shortcut', '', '')
- rActor.itemPath = sRecord
- -- end Adanced Effects piece ---
+function onClose()
+ if super and super.onClose then super.onClose() end
- -- bmos adding ammoPath for AmmunitionManager + Advanced Effects integration
- -- add this in the onDamageAction function of other effects to maintain compatibility
- if AmmunitionManager then
- local nodeAmmo = AmmunitionManager.getAmmoNode(nodeWeapon, rActor)
- if nodeAmmo then rActor.ammoPath = DB.getPath(nodeAmmo) end
- end
- -- end bmos adding ammoPath
+ if super and super.onAttackAction then super.onAttackAction = onAttackAction_old end
- ActionDamage.performRoll(draginfo, rActor, rAction)
- return true
-end
+ local nodeWeapon = getDatabaseNode()
+ DB.removeHandler(DB.getPath(nodeWeapon), 'onChildUpdate', onDataChanged)
+end
\ No newline at end of file
diff --git a/extension.xml b/extension.xml
index e95d168..7f7d958 100644
--- a/extension.xml
+++ b/extension.xml
@@ -29,7 +29,7 @@
34
-
+