Skip to content

Commit d06a755

Browse files
author
Wil Thieme
committed
fix ammo field visibility
1 parent 48b37a8 commit d06a755

File tree

2 files changed

+67
-103
lines changed

2 files changed

+67
-103
lines changed

campaign/scripts/5e_char_weapon.lua

Lines changed: 66 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,16 @@
33
-- attribution and copyright information.
44
--
55

6-
-- luacheck: globals setAmmoVis maxammo.setLink
7-
local function setAmmoVis()
8-
local nodeWeapon = getDatabaseNode()
9-
local bLoading = AmmunitionManager.hasLoadAction(nodeWeapon)
10-
isloaded.setVisible(bLoading)
11-
12-
local nodeAmmoLink = AmmunitionManager.getAmmoNode(nodeWeapon)
13-
local bRanged = AmmunitionManager.isWeaponRanged(nodeWeapon)
14-
ammocounter.setVisible(bRanged and not nodeAmmoLink)
15-
ammopicker.setComboBoxVisible(bRanged and nodeAmmoLink)
16-
ammopicker.setComboBoxReadOnly(true)
17-
18-
local nodeCount
19-
if nodeAmmoLink then nodeCount = DB.getChild(nodeAmmoLink, 'count') end
20-
maxammo.setLink(nodeCount, nodeCount ~= nil)
21-
end
22-
23-
-- luacheck: globals onDataChanged
24-
function onInit()
25-
local nodeWeapon = getDatabaseNode();
26-
local nodeChar = DB.getChild(nodeWeapon, "...");
27-
DB.addHandler(nodeWeapon, "onChildUpdate", onDataChanged);
28-
DB.addHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", onDataChanged);
29-
DB.addHandler(DB.getPath(nodeChar, "weapon.twoweaponfighting"), "onUpdate", onDataChanged);
30-
31-
onDataChanged(nodeWeapon);
6+
-- luacheck: globals isLoading
7+
function isLoading(nodeWeapon)
8+
Debug.console('AmmunitionManager char_weapon isLoading - DEPRECATED - 2023-03-20 - Use AmmunitionManager.hasLoadAction')
9+
return AmmunitionManager.hasLoadAction(nodeWeapon)
3210
end
3311

34-
function onClose()
35-
local nodeWeapon = getDatabaseNode();
36-
local nodeChar = DB.getChild(nodeWeapon, "...");
37-
DB.removeHandler(nodeWeapon, "onChildUpdate", onDataChanged);
38-
DB.removeHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", onDataChanged);
39-
DB.removeHandler(DB.getPath(nodeChar, "weapon.twoweaponfighting"), "onUpdate", onDataChanged);
40-
end
4112

42-
-- luacheck: globals onLinkChanged
4313
local m_sClass = "";
4414
local m_sRecord = "";
15+
-- luacheck: globals onLinkChanged
4516
function onLinkChanged()
4617
local node = getDatabaseNode();
4718
local sClass, sRecord = DB.getValue(node, "shortcut", "", "");
@@ -56,50 +27,61 @@ function onLinkChanged()
5627
end
5728
end
5829

59-
-- luacheck: globals onAttackChanged onDamageChanged
60-
function onDataChanged()
61-
onLinkChanged();
62-
onAttackChanged();
63-
onDamageChanged();
30+
-- luacheck: globals onDamageAction
31+
function onDamageAction(draginfo)
32+
local nodeWeapon = getDatabaseNode()
33+
local nodeChar = DB.getChild(nodeWeapon, '...')
6434

65-
setAmmoVis()
66-
end
35+
-- Build basic damage action record
36+
local rAction = CharWeaponManager.buildDamageAction(nodeChar, nodeWeapon)
6737

68-
-- luacheck: globals highlightAttack
69-
function highlightAttack(bOnControl)
70-
if bOnControl then
71-
attackshade.setFrame("rowshade");
72-
else
73-
attackshade.setFrame(nil);
74-
end
75-
end
38+
-- Perform damage action
39+
local rActor = ActorManager.resolveActor(nodeChar)
7640

77-
function onAttackChanged()
78-
local nodeWeapon = getDatabaseNode();
79-
local nodeChar = DB.getChild(nodeWeapon, "...")
41+
-- Celestian adding itemPath to rActor so that when effects
42+
-- are checked we can compare against action only effects
43+
local _, sRecord = DB.getValue(nodeWeapon, 'shortcut', '', '')
44+
rActor.itemPath = sRecord
45+
-- end Adanced Effects piece ---
8046

81-
local nMod = CharWeaponManager.getAttackBonus(nodeChar, nodeWeapon);
47+
-- bmos adding ammoPath for AmmunitionManager + Advanced Effects integration
48+
-- add this in the onDamageAction function of other effects to maintain compatibility
49+
if AmmunitionManager then
50+
local nodeAmmo = AmmunitionManager.getAmmoNode(nodeWeapon, rActor)
51+
if nodeAmmo then rActor.ammoPath = DB.getPath(nodeAmmo) end
52+
end
53+
-- end bmos adding ammoPath
8254

83-
attackview.setValue(nMod);
55+
ActionDamage.performRoll(draginfo, rActor, rAction)
56+
return true
8457
end
8558

86-
-- luacheck: globals onAttackAction
87-
function onAttackAction(draginfo)
88-
local nodeWeapon = getDatabaseNode();
89-
local nodeChar = DB.getChild(nodeWeapon, "...")
59+
-- luacheck: globals setAmmoVis maxammo.setLink
60+
function setAmmoVis(nodeWeapon, ...)
61+
if super and super.setAmmoVis then super.setAmmoVis(nodeWeapon, ...) end
9062

91-
-- Build basic attack action record
92-
local rAction = CharWeaponManager.buildAttackAction(nodeChar, nodeWeapon);
63+
local bLoading = AmmunitionManager.hasLoadAction(nodeWeapon)
64+
isloaded.setVisible(bLoading)
9365

94-
-- Decrement ammo
95-
if rAction.range == "R" then
96-
CharWeaponManager.decrementAmmo(nodeChar, nodeWeapon);
97-
end
66+
local nodeAmmoLink = AmmunitionManager.getAmmoNode(nodeWeapon)
67+
local bRanged = AmmunitionManager.isWeaponRanged(nodeWeapon)
68+
ammocounter.setVisible(bRanged and not nodeAmmoLink)
69+
ammopicker.setComboBoxVisible(bRanged and nodeAmmoLink)
70+
ammopicker.setComboBoxReadOnly(true)
9871

99-
-- Perform action
100-
local rActor = ActorManager.resolveActor(nodeChar);
72+
local nodeCount
73+
if nodeAmmoLink then nodeCount = DB.getChild(nodeAmmoLink, 'count') end
74+
maxammo.setLink(nodeCount, nodeCount ~= nil)
75+
end
10176

102-
-- AMMUNITION MANAGER CHANGES
77+
-- luacheck: globals onDataChanged
78+
function onDataChanged(nodeWeapon) self.setAmmoVis(nodeWeapon) end
79+
80+
local onAttackAction_old
81+
local function onAttackAction_new(draginfo, ...)
82+
local nodeWeapon = getDatabaseNode()
83+
local nodeChar = DB.getChild(nodeWeapon, '...')
84+
local rActor = ActorManager.resolveActor(nodeChar)
10385
local nAmmo, bInfiniteAmmo = AmmunitionManager.getAmmoRemaining(rActor, nodeWeapon, AmmunitionManager.getAmmoNode(nodeWeapon))
10486
local messagedata = { text = '', sender = rActor.sName, font = 'emotefont' }
10587

@@ -110,6 +92,7 @@ function onAttackAction(draginfo)
11092
if not bLoading or bIsLoaded then
11193
if bInfiniteAmmo or nAmmo > 0 then
11294
if bLoading then DB.setValue(nodeAmmoManager, 'isloaded', 'number', 0) end
95+
return onAttackAction_old(draginfo, ...)
11396
end
11497
messagedata.text = Interface.getString('char_message_atkwithnoammo')
11598
Comm.deliverChatMessage(messagedata)
@@ -119,48 +102,29 @@ function onAttackAction(draginfo)
119102
local sWeaponName = DB.getValue(nodeWeapon, 'name', 'weapon')
120103
messagedata.text = string.format(Interface.getString('char_actions_notloaded'), sWeaponName, true, rActor)
121104
Comm.deliverChatMessage(messagedata)
122-
return false
123105
end
124-
-- END AMMUNITION MANAGER CHANGES
125-
126-
ActionAttack.performRoll(draginfo, rActor, rAction);
127-
return true;
106+
-- end bmos only allowing attacks when ammo is sufficient
128107
end
129108

130-
function onDamageChanged()
131-
local nodeWeapon = getDatabaseNode();
132-
local nodeChar = DB.getChild(nodeWeapon, "...")
133-
134-
local sDamage = CharWeaponManager.buildDamageString(nodeChar, nodeWeapon);
109+
function onInit()
110+
if super and super.onInit then super.onInit() end
135111

136-
damageview.setValue(sDamage);
137-
end
112+
if super and super.onAttackAction then
113+
onAttackAction_old = super.onAttackAction
114+
super.onAttackAction = onAttackAction_new
115+
end
138116

139-
-- luacheck: globals onDamageAction
140-
function onDamageAction(draginfo)
141117
local nodeWeapon = getDatabaseNode()
142-
local nodeChar = DB.getChild(nodeWeapon, '...')
143-
144-
-- Build basic damage action record
145-
local rAction = CharWeaponManager.buildDamageAction(nodeChar, nodeWeapon)
118+
DB.addHandler(DB.getPath(nodeWeapon), 'onChildUpdate', onDataChanged)
146119

147-
-- Perform damage action
148-
local rActor = ActorManager.resolveActor(nodeChar)
120+
self.onDataChanged(nodeWeapon)
121+
end
149122

150-
-- Celestian adding itemPath to rActor so that when effects
151-
-- are checked we can compare against action only effects
152-
local _, sRecord = DB.getValue(nodeWeapon, 'shortcut', '', '')
153-
rActor.itemPath = sRecord
154-
-- end Adanced Effects piece ---
123+
function onClose()
124+
if super and super.onClose then super.onClose() end
155125

156-
-- bmos adding ammoPath for AmmunitionManager + Advanced Effects integration
157-
-- add this in the onDamageAction function of other effects to maintain compatibility
158-
if AmmunitionManager then
159-
local nodeAmmo = AmmunitionManager.getAmmoNode(nodeWeapon, rActor)
160-
if nodeAmmo then rActor.ammoPath = DB.getPath(nodeAmmo) end
161-
end
162-
-- end bmos adding ammoPath
126+
if super and super.onAttackAction then super.onAttackAction = onAttackAction_old end
163127

164-
ActionDamage.performRoll(draginfo, rActor, rAction)
165-
return true
166-
end
128+
local nodeWeapon = getDatabaseNode()
129+
DB.removeHandler(DB.getPath(nodeWeapon), 'onChildUpdate', onDataChanged)
130+
end

extension.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<loadorder>34</loadorder>
3030
</properties>
3131

32-
<announcement text="https://github.com/bmos/FG-PFRPG-Ammunition-Manager\nAmmunition Manager v4.5:\nThis extension aids in tracking ammunition and whether ranged weapons are loaded." font="emotefont" icon="archery_ammomanager" />
32+
<announcement text="https://github.com/bmos/FG-PFRPG-Ammunition-Manager\nAmmunition Manager v4.5-hotfix.1:\nThis extension aids in tracking ammunition and whether ranged weapons are loaded." font="emotefont" icon="archery_ammomanager" />
3333

3434
<base>
3535
<!-- Campaign Records -->

0 commit comments

Comments
 (0)