/
5e_char_weapon.lua
131 lines (108 loc) · 3.98 KB
/
5e_char_weapon.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
--
-- Please see the LICENSE.md file included with this distribution for
-- attribution and copyright information.
--
-- 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)
-- Perform damage action
local rActor = ActorManager.resolveActor(nodeChar)
-- 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 ---
-- 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
ActionDamage.performRoll(draginfo, rActor, rAction)
return true
end
-- luacheck: globals setAmmoVis maxammo.setLink
function setAmmoVis(nodeWeapon, ...)
if super and super.setAmmoVis then
super.setAmmoVis(nodeWeapon, ...)
end
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_new
local onDataChanged_old
function onDataChanged_new(nodeWeapon)
onDataChanged_old(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' }
local bLoading = AmmunitionManager.hasLoadAction(nodeWeapon)
local nodeAmmoManager = DB.getChild(nodeWeapon, 'ammunitionmanager')
local bIsLoaded = DB.getValue(nodeAmmoManager, 'isloaded') == 1
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)
if bLoading then
DB.setValue(nodeAmmoManager, 'isloaded', 'number', 0)
end
else
local sWeaponName = DB.getValue(nodeWeapon, 'name', 'weapon')
messagedata.text = string.format(Interface.getString('char_actions_notloaded'), sWeaponName, true, rActor)
Comm.deliverChatMessage(messagedata)
end
-- end bmos only allowing attacks when ammo is sufficient
end
function onInit()
if super and super.onInit then
super.onInit()
end
if super and super.onAttackAction then
onAttackAction_old = super.onAttackAction
super.onAttackAction = onAttackAction_new
end
if super and super.onDataChanged then
onDataChanged_old = super.onDataChanged
super.onDataChanged = onDataChanged_new
end
local nodeWeapon = getDatabaseNode()
DB.addHandler(DB.getPath(nodeWeapon), 'onChildUpdate', self.onDataChanged)
self.onDataChanged(nodeWeapon)
end
function onClose()
if super and super.onClose then
super.onClose()
end
if super and super.onAttackAction then
super.onAttackAction = onAttackAction_old
end
local nodeWeapon = getDatabaseNode()
DB.removeHandler(DB.getPath(nodeWeapon), 'onChildUpdate', self.onDataChanged)
end