3
3
-- attribution and copyright information.
4
4
--
5
5
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 )
32
10
end
33
11
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
41
12
42
- -- luacheck: globals onLinkChanged
43
13
local m_sClass = " " ;
44
14
local m_sRecord = " " ;
15
+ -- luacheck: globals onLinkChanged
45
16
function onLinkChanged ()
46
17
local node = getDatabaseNode ();
47
18
local sClass , sRecord = DB .getValue (node , " shortcut" , " " , " " );
@@ -56,50 +27,61 @@ function onLinkChanged()
56
27
end
57
28
end
58
29
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 , ' ...' )
64
34
65
- setAmmoVis ()
66
- end
35
+ -- Build basic damage action record
36
+ local rAction = CharWeaponManager . buildDamageAction ( nodeChar , nodeWeapon )
67
37
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 )
76
40
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 ---
80
46
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
82
54
83
- attackview .setValue (nMod );
55
+ ActionDamage .performRoll (draginfo , rActor , rAction )
56
+ return true
84
57
end
85
58
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
90
62
91
- -- Build basic attack action record
92
- local rAction = CharWeaponManager . buildAttackAction ( nodeChar , nodeWeapon );
63
+ local bLoading = AmmunitionManager . hasLoadAction ( nodeWeapon )
64
+ isloaded . setVisible ( bLoading )
93
65
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 )
98
71
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
101
76
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 )
103
85
local nAmmo , bInfiniteAmmo = AmmunitionManager .getAmmoRemaining (rActor , nodeWeapon , AmmunitionManager .getAmmoNode (nodeWeapon ))
104
86
local messagedata = { text = ' ' , sender = rActor .sName , font = ' emotefont' }
105
87
@@ -110,6 +92,7 @@ function onAttackAction(draginfo)
110
92
if not bLoading or bIsLoaded then
111
93
if bInfiniteAmmo or nAmmo > 0 then
112
94
if bLoading then DB .setValue (nodeAmmoManager , ' isloaded' , ' number' , 0 ) end
95
+ return onAttackAction_old (draginfo , ... )
113
96
end
114
97
messagedata .text = Interface .getString (' char_message_atkwithnoammo' )
115
98
Comm .deliverChatMessage (messagedata )
@@ -119,48 +102,29 @@ function onAttackAction(draginfo)
119
102
local sWeaponName = DB .getValue (nodeWeapon , ' name' , ' weapon' )
120
103
messagedata .text = string.format (Interface .getString (' char_actions_notloaded' ), sWeaponName , true , rActor )
121
104
Comm .deliverChatMessage (messagedata )
122
- return false
123
105
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
128
107
end
129
108
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
135
111
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
138
116
139
- -- luacheck: globals onDamageAction
140
- function onDamageAction (draginfo )
141
117
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 )
146
119
147
- -- Perform damage action
148
- local rActor = ActorManager . resolveActor ( nodeChar )
120
+ self . onDataChanged ( nodeWeapon )
121
+ end
149
122
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
155
125
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
163
127
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
0 commit comments