Skip to content

Commit 01201e9

Browse files
author
Wil Thieme
committed
fixes for 5e adding/removing weapons
1 parent bc98162 commit 01201e9

File tree

2 files changed

+114
-59
lines changed

2 files changed

+114
-59
lines changed

campaign/scripts/5e_char_weapon.lua

Lines changed: 113 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,8 @@
33
-- attribution and copyright information.
44
--
55

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)
10-
end
11-
12-
-- luacheck: globals onDamageAction
13-
function onDamageAction(draginfo)
14-
local nodeWeapon = getDatabaseNode()
15-
local nodeChar = DB.getChild(nodeWeapon, '...')
16-
17-
-- Build basic damage action record
18-
local rAction = CharWeaponManager.buildDamageAction(nodeChar, nodeWeapon)
19-
20-
-- Perform damage action
21-
local rActor = ActorManager.resolveActor(nodeChar)
22-
23-
-- Celestian adding itemPath to rActor so that when effects
24-
-- are checked we can compare against action only effects
25-
local _, sRecord = DB.getValue(nodeWeapon, 'shortcut', '', '')
26-
rActor.itemPath = sRecord
27-
-- end Adanced Effects piece ---
28-
29-
-- bmos adding ammoPath for AmmunitionManager + Advanced Effects integration
30-
-- add this in the onDamageAction function of other effects to maintain compatibility
31-
if AmmunitionManager then
32-
local nodeAmmo = AmmunitionManager.getAmmoNode(nodeWeapon, rActor)
33-
if nodeAmmo then rActor.ammoPath = DB.getPath(nodeAmmo) end
34-
end
35-
-- end bmos adding ammoPath
36-
37-
ActionDamage.performRoll(draginfo, rActor, rAction)
38-
return true
39-
end
40-
416
-- luacheck: globals setAmmoVis maxammo.setLink
42-
function setAmmoVis(nodeWeapon, ...)
7+
local function setAmmoVis(nodeWeapon, ...)
438
if super and super.setAmmoVis then super.setAmmoVis(nodeWeapon, ...) end
449

4510
local bLoading = AmmunitionManager.hasLoadAction(nodeWeapon)
@@ -57,13 +22,85 @@ function setAmmoVis(nodeWeapon, ...)
5722
end
5823

5924
-- luacheck: globals onDataChanged
60-
function onDataChanged(nodeWeapon) self.setAmmoVis(nodeWeapon) end
25+
function onInit()
26+
local nodeWeapon = getDatabaseNode();
27+
local nodeChar = DB.getChild(nodeWeapon, "...");
28+
DB.addHandler(nodeWeapon, "onChildUpdate", onDataChanged);
29+
DB.addHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", onDataChanged);
30+
DB.addHandler(DB.getPath(nodeChar, "weapon.twoweaponfighting"), "onUpdate", onDataChanged);
6131

62-
local onAttackAction_old
63-
local function onAttackAction_new(draginfo, ...)
64-
local nodeWeapon = getDatabaseNode()
65-
local nodeChar = DB.getChild(nodeWeapon, '...')
66-
local rActor = ActorManager.resolveActor(nodeChar)
32+
onDataChanged(nodeWeapon);
33+
end
34+
35+
function onClose()
36+
local nodeWeapon = getDatabaseNode();
37+
local nodeChar = DB.getChild(nodeWeapon, "...");
38+
DB.removeHandler(nodeWeapon, "onChildUpdate", onDataChanged);
39+
DB.removeHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", onDataChanged);
40+
DB.removeHandler(DB.getPath(nodeChar, "weapon.twoweaponfighting"), "onUpdate", onDataChanged);
41+
end
42+
43+
-- luacheck: globals onLinkChanged
44+
local m_sClass = "";
45+
local m_sRecord = "";
46+
function onLinkChanged()
47+
local node = getDatabaseNode();
48+
local sClass, sRecord = DB.getValue(node, "shortcut", "", "");
49+
if sClass ~= m_sClass or sRecord ~= m_sRecord then
50+
m_sClass = sClass;
51+
m_sRecord = sRecord;
52+
53+
local sInvList = DB.getPath(DB.getChild(node, "..."), "inventorylist") .. ".";
54+
if sRecord:sub(1, #sInvList) == sInvList then
55+
carried.setLink(DB.findNode(DB.getPath(sRecord, "carried")));
56+
end
57+
end
58+
end
59+
60+
-- luacheck: globals onAttackChanged onDamageChanged
61+
function onDataChanged(nodeWeapon)
62+
onLinkChanged();
63+
onAttackChanged();
64+
onDamageChanged();
65+
66+
setAmmoVis(nodeWeapon)
67+
end
68+
69+
-- luacheck: globals highlightAttack
70+
function highlightAttack(bOnControl)
71+
if bOnControl then
72+
attackshade.setFrame("rowshade");
73+
else
74+
attackshade.setFrame(nil);
75+
end
76+
end
77+
78+
function onAttackChanged()
79+
local nodeWeapon = getDatabaseNode();
80+
local nodeChar = DB.getChild(nodeWeapon, "...")
81+
82+
local nMod = CharWeaponManager.getAttackBonus(nodeChar, nodeWeapon);
83+
84+
attackview.setValue(nMod);
85+
end
86+
87+
-- luacheck: globals onAttackAction
88+
function onAttackAction(draginfo)
89+
local nodeWeapon = getDatabaseNode();
90+
local nodeChar = DB.getChild(nodeWeapon, "...")
91+
92+
-- Build basic attack action record
93+
local rAction = CharWeaponManager.buildAttackAction(nodeChar, nodeWeapon);
94+
95+
-- Decrement ammo
96+
if rAction.range == "R" then
97+
CharWeaponManager.decrementAmmo(nodeChar, nodeWeapon);
98+
end
99+
100+
-- Perform action
101+
local rActor = ActorManager.resolveActor(nodeChar);
102+
103+
-- AMMUNITION MANAGER CHANGES
67104
local nAmmo, bInfiniteAmmo = AmmunitionManager.getAmmoRemaining(rActor, nodeWeapon, AmmunitionManager.getAmmoNode(nodeWeapon))
68105
local messagedata = { text = '', sender = rActor.sName, font = 'emotefont' }
69106

@@ -74,7 +111,6 @@ local function onAttackAction_new(draginfo, ...)
74111
if not bLoading or bIsLoaded then
75112
if bInfiniteAmmo or nAmmo > 0 then
76113
if bLoading then DB.setValue(nodeAmmoManager, 'isloaded', 'number', 0) end
77-
return onAttackAction_old(draginfo, ...)
78114
end
79115
messagedata.text = Interface.getString('char_message_atkwithnoammo')
80116
Comm.deliverChatMessage(messagedata)
@@ -84,29 +120,48 @@ local function onAttackAction_new(draginfo, ...)
84120
local sWeaponName = DB.getValue(nodeWeapon, 'name', 'weapon')
85121
messagedata.text = string.format(Interface.getString('char_actions_notloaded'), sWeaponName, true, rActor)
86122
Comm.deliverChatMessage(messagedata)
123+
return false
87124
end
88-
-- end bmos only allowing attacks when ammo is sufficient
125+
-- END AMMUNITION MANAGER CHANGES
126+
127+
ActionAttack.performRoll(draginfo, rActor, rAction);
128+
return true;
89129
end
90130

91-
function onInit()
92-
if super and super.onInit then super.onInit() end
131+
function onDamageChanged()
132+
local nodeWeapon = getDatabaseNode();
133+
local nodeChar = DB.getChild(nodeWeapon, "...")
93134

94-
if super and super.onAttackAction then
95-
onAttackAction_old = super.onAttackAction
96-
super.onAttackAction = onAttackAction_new
97-
end
135+
local sDamage = CharWeaponManager.buildDamageString(nodeChar, nodeWeapon);
98136

137+
damageview.setValue(sDamage);
138+
end
139+
140+
-- luacheck: globals onDamageAction
141+
function onDamageAction(draginfo)
99142
local nodeWeapon = getDatabaseNode()
100-
DB.addHandler(DB.getPath(nodeWeapon), 'onChildUpdate', onDataChanged)
143+
local nodeChar = DB.getChild(nodeWeapon, '...')
101144

102-
self.onDataChanged(nodeWeapon)
103-
end
145+
-- Build basic damage action record
146+
local rAction = CharWeaponManager.buildDamageAction(nodeChar, nodeWeapon)
104147

105-
function onClose()
106-
if super and super.onClose then super.onClose() end
148+
-- Perform damage action
149+
local rActor = ActorManager.resolveActor(nodeChar)
150+
151+
-- Celestian adding itemPath to rActor so that when effects
152+
-- are checked we can compare against action only effects
153+
local _, sRecord = DB.getValue(nodeWeapon, 'shortcut', '', '')
154+
rActor.itemPath = sRecord
155+
-- end Adanced Effects piece ---
107156

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

110-
local nodeWeapon = getDatabaseNode()
111-
DB.removeHandler(DB.getPath(nodeWeapon), 'onChildUpdate', onDataChanged)
165+
ActionDamage.performRoll(draginfo, rActor, rAction)
166+
return true
112167
end

extension.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<loadorder>34</loadorder>
2727
</properties>
2828

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

3131
<base>
3232
<!-- Campaign Records -->

0 commit comments

Comments
 (0)