-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteraction_global.lua
More file actions
115 lines (93 loc) · 3.85 KB
/
interaction_global.lua
File metadata and controls
115 lines (93 loc) · 3.85 KB
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
require('scripts/globals/utils')
require('scripts/globals/interaction/interaction_lookup')
-- Used by core to call into the loaded interaction handlers
InteractionGlobal = InteractionGlobal or {}
InteractionGlobal.lookup = InteractionGlobal.lookup or InteractionLookup:new()
InteractionGlobal.zones = InteractionGlobal.zones or {}
function InteractionGlobal.initZones(zoneIds)
-- Add the given zones to the zones table
for i=1, #zoneIds do
local zone = GetZone(zoneIds[i])
if zone then
InteractionGlobal.zones[zoneIds[i]] = zone:getName()
end
end
InteractionGlobal.loadDefaultActions(false)
InteractionGlobal.loadContainers(false)
end
-- Add container handlers found for the added zones
function InteractionGlobal.loadContainers(shouldReloadRequires)
local zoneIds = {}
for zoneId, _ in pairs(InteractionGlobal.zones) do
zoneIds[#zoneIds+1] = zoneId
end
local interactionContainersPath = 'scripts/globals/interaction_containers'
if shouldReloadRequires then
package.loaded[interactionContainersPath] = nil
end
local containerFiles = require(interactionContainersPath)
local containers = {}
for i=1, #containerFiles do
containers[i] = utils.prequire(containerFiles[i])
end
InteractionGlobal.lookup:addContainers(containers, zoneIds)
end
-- Load default actions in added zones
function InteractionGlobal.loadDefaultActions(shouldReloadRequires)
for zoneId, _ in pairs(InteractionGlobal.zones) do
InteractionGlobal.loadDefaultActionsForZone(zoneId, shouldReloadRequires)
end
end
-- Load default actions for a specific zone
function InteractionGlobal.loadDefaultActionsForZone(zoneId, shouldReloadRequires)
local zoneName = InteractionGlobal.zones[zoneId]
if not zoneName then
printf("Unable to load default actions for zone %d, since it hasn't been initialized.", zoneId)
return
end
-- Path to zone-specific default actions
local defaultActionPath = string.format('scripts/zones/%s/DefaultActions', zoneName)
if shouldReloadRequires then
package.loaded[defaultActionPath] = nil
end
-- Only add default handlers if DefaultActions file is found in zone directory
local ok, defaultHandlers = pcall(require, defaultActionPath)
if ok then
InteractionGlobal.lookup:addDefaultHandlers(zoneId, defaultHandlers)
end
end
-- Reloads the framework which is useful during development
function InteractionGlobal.reload(shouldReloadData)
if shouldReloadData then
InteractionGlobal.lookup = InteractionLookup:new()
InteractionGlobal.loadDefaultActions(true)
InteractionGlobal.loadContainers(true)
else
InteractionGlobal.lookup = InteractionLookup:new(InteractionGlobal.lookup)
end
end
function InteractionGlobal.onTrigger(player, npc)
return InteractionGlobal.lookup:onTrigger(player, npc)
end
function InteractionGlobal.onTrade(player, npc, trade)
return InteractionGlobal.lookup:onTrade(player, npc, trade)
end
function InteractionGlobal.onMobDeath(mob, player, isKiller, firstCall)
return InteractionGlobal.lookup:onMobDeath(mob, player, isKiller, firstCall)
end
function InteractionGlobal.onZoneIn(player, prevZone)
return InteractionGlobal.lookup:onZoneIn(player, prevZone)
end
function InteractionGlobal.onRegionEnter(player, region)
return InteractionGlobal.lookup:onRegionEnter(player, region)
end
function InteractionGlobal.onRegionLeave(player, region)
return InteractionGlobal.lookup:onRegionLeave(player, region)
end
function InteractionGlobal.onEventFinish(player, csid, option, npc)
return InteractionGlobal.lookup:onEventFinish(player, csid, option, npc)
end
function InteractionGlobal.onEventUpdate(player, csid, option, npc)
return InteractionGlobal.lookup:onEventUpdate(player, csid, option, npc)
end
return InteractionGlobal