-
Notifications
You must be signed in to change notification settings - Fork 0
/
EysilesHousingAnimatorInteract.lua
245 lines (192 loc) · 6.84 KB
/
EysilesHousingAnimatorInteract.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
local EHA = EysilesHousingAnimator
EHAInteract = { callbacks = {} }
-- Let's not use real OOP as serializeing them will lead to recursive save
function EHAInteract:new(o)
local o = o or {}
local t = { furnitures = {}, run = {'', '', '', '', '', '', '', '', ''}}
for k, v in pairs(o) do
t[k] = v
end
return t
end
function EHAInteract.addFurnitures(t, furnitures)
for _, f in ipairs(furnitures) do
t.furnitures[f.id] = f
end
end
function EHAInteract.setParameter(t, param, value, position)
if param ~= nil and value ~= nil and t[param] ~= nil then
if type(t[param]) == "number" then
t[param] = tonumber(value)
elseif type(t[param]) == "boolean" then
t[param] = value ~= "0"
elseif type(t[param]) == "table" and position ~= nil then
EHAInteract.setParameter(t[param], tonumber(position), value)
elseif type(t[param]) ~= "table" then
t[param] = value
end
d("Setting value of " .. param .. " to " .. tostring(t[param]))
return t[param]
else
d("Cannot set value of " .. tostring(param) .. " to " .. tostring(value))
end
end
function EHAInteract.triggerCreate(name, number)
local fs = {}
local i = number
for _, f in ipairs( EHA.furnitures ) do
fs[i] = f
i = i - 1
if i < 1 then break end
end
local trigger = EHAInteract:new()
EHAInteract.addFurnitures(trigger, fs)
EHA.interacts[name] = trigger
d("Saved trigger to " .. name .. " with " .. #fs .. " keyframes")
end
------------------------------------------------------------------------------
function EHAInteract.ClientInteractResult( event, result, targetName )
if result ~= CLIENT_INTERACT_RESULT_SUCCESS or nil == targetName or "" == targetName then return end
targetName = ZO_StripGrammarMarkupFromCharacterName( targetName )
-- d('Activated ' .. targetName)
end
function EHAInteract.ClientInteract( event, result, targetName )
d(GetGameCameraInteractableActionInfo())
end
function EHAInteract.setState(furnitureId, state, try)
local prevState = GetPlacedHousingFurnitureCurrentObjectStateIndex( StringToId64(furnitureId) )
if prevState == nil or prevState ~= state then
local resultCode = HousingEditorRequestChangeState( StringToId64(furnitureId), state )
if resultCode == HOUSING_REQUEST_RESULT_SET_STATE_FAILED then
try = (try or 0) + 1
if try < 50 then
EHA.d('Could not set state of object ' .. furnitureId .. ', try ' .. tostring(try))
EHAInteract.callbacks[furnitureId] = function()
EHAInteract.setState(furnitureId, state, try)
end
end
else
EHA.d("Changing state of " .. furnitureId .. " to " .. tostring(state))
end
end
end
function EHAInteract.activate(a, state)
for furnitureId, f in pairs(a.furnitures) do
EHAInteract.callbacks[furnitureId] = function()
EHAInteract.setState(furnitureId, state)
end
end
end
---- tests
function EHAInteract.activateAll(state)
local id = GetNextPlacedHousingFurnitureId()
while id do
HousingEditorRequestChangeState(id, state)
id = GetNextPlacedHousingFurnitureId( id )
end
end
function EHAInteract.toggle(a)
for furnitureId, f in pairs(a.furnitures) do
local stateIndex = GetPlacedHousingFurnitureCurrentObjectStateIndex( StringToId64(furnitureId) )
if nil == stateIndex then return nil end
local stateName = GetPlacedFurniturePreviewVariationDisplayName( StringToId64(furnitureId), stateIndex + 1 )
end
end
function EHAInteract.OnUpdate()
if GetHousingEditorMode() ~= HOUSING_EDITOR_MODE_DISABLED then
return
end
for name, t in pairs( EHA.interacts ) do
-- If multiple, all states should be saved state to trigger the action
local count = 0
for furnitureId, f in pairs(t.furnitures) do
count = count + 1
end
if count > 1 then
EHAInteract.handleMultiple(t)
else
EHAInteract.handleSingle(t)
end
end
for id, t in pairs( EHAInteract.callbacks ) do
local fnc = t
EHAInteract.callbacks[id] = nil
fnc();
end
end
function EHAInteract.handleSingle(t)
for furnitureId, f in pairs(t.furnitures) do
if f.previousState == nil then
f.previousState = GetPlacedHousingFurnitureCurrentObjectStateIndex( StringToId64(f.id) )
EHA.d("Saving primary state")
else
local state = GetPlacedHousingFurnitureCurrentObjectStateIndex( StringToId64(f.id) )
if f.previousState ~= state then
if t.run[state + 1] then
EHA.d("Trigerring command from: " .. t.run[state + 1])
EHA.SlashCommand(t.run[state + 1])
end
f.previousState = state
end
end
end
end
function EHAInteract.handleMultiple(t)
local correct = true
for furnitureId, f in pairs(t.furnitures) do
local state = GetPlacedHousingFurnitureCurrentObjectStateIndex( StringToId64(f.id) )
correct = correct and (f.state == state)
end
if t.previousState == nil then
t.previousState = correct
EHA.d("Saving primary state")
end
if correct ~= t.previousState then
local command = 1
if correct then
command = 2
end
if t.run[command] then
EHA.d("Trigerring command from multiple: " .. tostring(t.run[command]))
EHA.SlashCommand(t.run[command])
end
t.previousState = correct
end
end
function EHAInteract.SlashCommand( options )
local interacts = {}
local name = options[3]
if name == "all" then
interacts = EHA.interacts
elseif EHA.interacts[name] then
interacts[name] = EHA.interacts[name]
end
-- Trigger commands
if options[2] == "create" then EHAInteract.triggerCreate(name, tonumber(options[4]) or 1) end
if options[2] == "set" then for n, i in pairs( interacts ) do EHAInteract.setParameter(i, options[4], options[5], options[6]) end end
end
function EHAInteract.HandleCombatEvent(event, actionResult, isError, abilityName, abilityGraphic, abilityActionSlotType, sourceName, sourceType, targetName, targetType, hitValue, powerType, damageType, shouldLog, sourceUnitId, targetUnitId, abilityId)
if actionResult == ACTION_RESULT_KILLING_BLOW then
d('ACTION_RESULT_KILLING_BLOW')
elseif actionResult == ACTION_RESULT_DIED then
d('ACTION_RESULT_DIED', targetUnitId, targetName)
elseif actionResult == ACTION_RESULT_PACIFIED then
d('ACTION_RESULT_PACIFIED')
elseif actionResult == ACTION_RESULT_RESURRECT then
d('ACTION_RESULT_RESURRECT')
elseif actionResult == ACTION_RESULT_TARGET_DEAD then
d('ACTION_RESULT_TARGET_DEAD')
elseif actionResult == ACTION_RESULT_BEGIN then
d('ACTION_RESULT_BEGIN')
elseif actionResult == ACTION_RESULT_IN_COMBAT then
d('ACTION_RESULT_IN_COMBAT')
elseif actionResult == ACTION_RESULT_REINCARNATING then
d('ACTION_RESULT_REINCARNATING')
else
-- d('Unknow: ' .. actionResult)
end
-- d(EHAFurniture:new('4616191546495175001'))
end
function EHAInteract.OnCombatStateChange(inCombat)
d('OnCombatStateChange', inCombat)
end