3
3
-- attribution and copyright information.
4
4
--
5
5
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
-
41
6
-- luacheck: globals setAmmoVis maxammo.setLink
42
- function setAmmoVis (nodeWeapon , ...)
7
+ local function setAmmoVis (nodeWeapon , ...)
43
8
if super and super .setAmmoVis then super .setAmmoVis (nodeWeapon , ... ) end
44
9
45
10
local bLoading = AmmunitionManager .hasLoadAction (nodeWeapon )
@@ -57,13 +22,85 @@ function setAmmoVis(nodeWeapon, ...)
57
22
end
58
23
59
24
-- 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 );
61
31
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
67
104
local nAmmo , bInfiniteAmmo = AmmunitionManager .getAmmoRemaining (rActor , nodeWeapon , AmmunitionManager .getAmmoNode (nodeWeapon ))
68
105
local messagedata = { text = ' ' , sender = rActor .sName , font = ' emotefont' }
69
106
@@ -74,7 +111,6 @@ local function onAttackAction_new(draginfo, ...)
74
111
if not bLoading or bIsLoaded then
75
112
if bInfiniteAmmo or nAmmo > 0 then
76
113
if bLoading then DB .setValue (nodeAmmoManager , ' isloaded' , ' number' , 0 ) end
77
- return onAttackAction_old (draginfo , ... )
78
114
end
79
115
messagedata .text = Interface .getString (' char_message_atkwithnoammo' )
80
116
Comm .deliverChatMessage (messagedata )
@@ -84,29 +120,48 @@ local function onAttackAction_new(draginfo, ...)
84
120
local sWeaponName = DB .getValue (nodeWeapon , ' name' , ' weapon' )
85
121
messagedata .text = string.format (Interface .getString (' char_actions_notloaded' ), sWeaponName , true , rActor )
86
122
Comm .deliverChatMessage (messagedata )
123
+ return false
87
124
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 ;
89
129
end
90
130
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 , " ..." )
93
134
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 );
98
136
137
+ damageview .setValue (sDamage );
138
+ end
139
+
140
+ -- luacheck: globals onDamageAction
141
+ function onDamageAction (draginfo )
99
142
local nodeWeapon = getDatabaseNode ()
100
- DB .addHandler ( DB . getPath ( nodeWeapon ) , ' onChildUpdate ' , onDataChanged )
143
+ local nodeChar = DB .getChild ( nodeWeapon , ' ... ' )
101
144
102
- self . onDataChanged ( nodeWeapon )
103
- end
145
+ -- Build basic damage action record
146
+ local rAction = CharWeaponManager . buildDamageAction ( nodeChar , nodeWeapon )
104
147
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 ---
107
156
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
109
164
110
- local nodeWeapon = getDatabaseNode ( )
111
- DB . removeHandler ( DB . getPath ( nodeWeapon ), ' onChildUpdate ' , onDataChanged )
165
+ ActionDamage . performRoll ( draginfo , rActor , rAction )
166
+ return true
112
167
end
0 commit comments