1
- local object_binder_update = object_binder.update
2
-
3
1
function init(obj) -- called 1st
4
2
5
3
local ini = obj:spawn_ini()
6
- --[[
7
- if ini and ini:section_exist("animation") then
8
- abort("object '%s': animation section is deprecated, use logic + impulse combination", obj:name())
9
- return
10
- end
11
- ]]
12
- if (ini and ini:section_exist("logic")) or obj:clsid() == clsid.inventory_box then -- drop-boxes all have a [logic] section in vanilla, so are included without an explicit test
13
- db.storage[obj:id()] = {}
4
+
5
+ -- Drop-boxes all have a [logic] section in vanilla, so are included without an explicit test:
6
+ if (ini and ini:section_exist("logic")) or obj:clsid() == clsid.inventory_box then
14
7
obj:bind_object(generic_physics_binder(obj))
15
8
end
16
9
end
17
10
18
- ---------------------------------------------------------------------------------------------
11
+ --------------------------------------------------------------------------------
19
12
20
13
class "generic_physics_binder" (object_binder)
21
14
22
15
function generic_physics_binder:__init(obj) super(obj) -- called 2nd
23
16
self.initialized = false
24
17
self.loaded = false
18
+ self.particle = nil
19
+ self.box_items = nil
20
+ if obj:clsid() == clsid.inventory_box then
21
+ self.is_inventory_box = true
22
+ self.is_drop_box = false
23
+ else
24
+ local ini = obj:spawn_ini()
25
+ self.is_inventory_box = false
26
+ self.is_drop_box = ini ~= nil and ini:section_exist("drop_box")
27
+ end
28
+ self.st = {}
25
29
end
26
30
27
31
function generic_physics_binder:reload(section) -- called 3rd
30
34
31
35
function generic_physics_binder:reinit() -- called 4th
32
36
object_binder.reinit(self)
33
- local sobj = self.object
34
- self.st = db.storage[sobj:id()]
35
- local is_inventory_box = sobj:clsid() == clsid.inventory_box
36
- self.is_inventory_box = is_inventory_box
37
- if not is_inventory_box then
38
- local ini = sobj:spawn_ini()
39
- self.is_drop_box = ini and ini:section_exist("drop_box")
40
- end
37
+ db.storage[self.object:id()] = self.st
41
38
end
42
39
43
- function generic_physics_binder:net_spawn(data ) -- called 5th
40
+ function generic_physics_binder:net_spawn(se_abstract ) -- called 5th
44
41
45
- if not object_binder.net_spawn(self, data ) then
42
+ if not object_binder.net_spawn(self, se_abstract ) then
46
43
return false
47
44
end
48
45
49
- local sobj = self.object
46
+ local obj = self.object
50
47
51
- -- if sobj:clsid() == clsid.projector then
52
- -- db.add_sl(sobj)
53
- -- end
48
+ db.add_obj(obj)
54
49
55
50
if self.is_drop_box then
56
- self.box_items = xr_box.ph_item_box(sobj )
51
+ self.box_items = xr_box.ph_item_box(obj )
57
52
end
58
53
59
- db.add_obj(sobj)
60
-
61
54
if self.is_inventory_box then
62
- local sname = sobj :name()
55
+ local sname = obj :name()
63
56
if sname ~= "gar_treasure_quest_reward_in_anomaly" and sname ~= "gar_treasure_quest_old_pda" then
64
57
local actor_level = level.name()
65
58
if (actor_level == "marsh" and has_alife_info("mar_stashes_filled"))
@@ -76,58 +69,21 @@ function generic_physics_binder:net_spawn(data) -- called 5th
76
69
return true
77
70
end
78
71
treasure_manager.use_box(sname)
79
- -- dbglog("Used box with name "..sname.." and ID "..sobj:id()..".")
80
72
end
81
73
end
82
74
83
75
return true
84
76
end
85
77
86
- function generic_physics_binder:update(delta) -- called 6th
87
-
88
- object_binder_update(self, delta)
89
-
90
- local sobj = self.object
91
- local obj_st = self.st
92
-
93
- if not self.initialized then
94
- self.initialized = true
95
- xr_logic.initialize_obj(sobj, obj_st, self.loaded, modules.stype_item)
96
- local particle = utils.cfg_get_string(obj_st.ini, obj_st.section_logic, "particle", sobj, false, "", nil)
97
- if particle ~= nil then
98
- self.particle = particles_object(particle)
99
- self.particle:play_at_pos(sobj:position())
100
- end
101
- if obj_st.active_section ~= nil or self.is_drop_box then
102
- sobj:set_callback(callback.hit, generic_physics_binder.hit_callback, self)
103
- sobj:set_callback(callback.death, generic_physics_binder.death_callback, self)
104
- sobj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
105
- else
106
- if self.is_inventory_box then
107
- sobj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
108
- end
109
- end
110
- end
111
-
112
- if obj_st.active_section ~= nil then
113
- xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "update", delta)
114
- end
115
-
116
- xr_sound.update(sobj:id())
117
- end
118
-
119
78
function generic_physics_binder:net_destroy()
120
79
121
- local sobj = self.object
122
- local sid = sobj:id()
80
+ self:clear_callbacks()
123
81
124
- xr_sound.stop_sounds_by_id(sid)
82
+ local obj = self.object
83
+ local obj_st = self.st
125
84
126
- sobj:set_callback(callback.hit, nil) -- SRP
127
- sobj:set_callback(callback.death, nil) -- SRP
128
- sobj:set_callback(callback.use_object, nil) -- SRP
85
+ xr_sound.stop_sounds_by_id(obj:id())
129
86
130
- local obj_st = self.st
131
87
if obj_st.active_scheme then
132
88
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "net_destroy")
133
89
end
@@ -136,47 +92,53 @@ function generic_physics_binder:net_destroy()
136
92
self.particle:stop()
137
93
end
138
94
139
- -- db.del_obj(sobj) -- done below
140
- -- db.del_sl(sobj)
141
-
142
- db.storage[sid] = nil
95
+ db.del_obj(obj)
143
96
144
97
object_binder.net_destroy(self)
145
98
end
146
99
147
- function generic_physics_binder:net_save_relevant()
148
- return true
149
- end
100
+ local object_binder_update = object_binder.update
150
101
151
- function generic_physics_binder:save(packet)
152
- object_binder.save(self, packet)
153
- set_save_marker(packet, "save", false, "physics_binder")
154
- xr_logic.save_obj(self.object, packet)
155
- set_save_marker(packet, "save", true, "physics_binder")
156
- end
102
+ function generic_physics_binder:update(delta) -- called 6th
157
103
158
- function generic_physics_binder:load(reader)
159
- self.loaded = true
160
- object_binder.load(self, reader)
161
- set_save_marker(reader, "load", false, "physics_binder")
162
- xr_logic.load_obj(self.object, reader)
163
- set_save_marker(reader, "load", true, "physics_binder")
164
- end
104
+ object_binder_update(self, delta)
165
105
166
- function generic_physics_binder:use_callback(used_obj, user)
167
- if self.is_inventory_box then
168
- if used_obj:name() == "gar_smart_terrain_5_6_box" then
169
- local act = db.actor
170
- if act:has_info("gar_quest_redemption_started") then
171
- act:give_info_portion("gar_quest_redemption_done")
106
+ local obj = self.object
107
+ local obj_st = self.st
108
+
109
+ if not self.initialized then
110
+ self.initialized = true
111
+ xr_logic.initialize_obj(obj, obj_st, self.loaded, modules.stype_item)
112
+ local particle = utils.cfg_get_string(obj_st.ini, obj_st.section_logic, "particle", nil, false, "", nil)
113
+ if particle ~= nil then
114
+ self.particle = particles_object(particle)
115
+ self.particle:play_at_pos(obj:position())
116
+ end
117
+ if obj_st.active_scheme or self.is_drop_box then
118
+ obj:set_callback(callback.hit, generic_physics_binder.hit_callback, self)
119
+ obj:set_callback(callback.death, generic_physics_binder.death_callback, self)
120
+ obj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
121
+ else
122
+ if self.is_inventory_box then
123
+ obj:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
172
124
end
173
125
end
174
- -- treasure_manager.use_box(used_obj, user)
175
126
end
176
- local obj_st = self.st
177
- if obj_st.active_section then
178
- xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "use_callback ", used_obj, user )
127
+
128
+ if obj_st.active_scheme then
129
+ xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "update ", delta )
179
130
end
131
+
132
+ xr_sound.update(obj:id())
133
+ end
134
+
135
+ --------------------------------------------------------------------------------
136
+
137
+ function generic_physics_binder:clear_callbacks()
138
+ local obj = self.object
139
+ obj:set_callback(callback.hit, nil)
140
+ obj:set_callback(callback.death, nil)
141
+ obj:set_callback(callback.use_object, nil)
180
142
end
181
143
182
144
function generic_physics_binder:hit_callback(victim, amount, local_direction, hitter, bone_index)
@@ -187,32 +149,65 @@ function generic_physics_binder:hit_callback(victim, amount, local_direction, hi
187
149
xr_logic.issue_event(nil, obj_st.ph_on_hit, "hit_callback", victim, amount, local_direction, hitter, bone_index)
188
150
end
189
151
190
- if obj_st.active_section then
152
+ if obj_st.active_scheme then
191
153
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "hit_callback", victim, amount, local_direction, hitter, bone_index)
192
154
end
193
155
end
194
156
195
157
function generic_physics_binder:death_callback(victim, culprit)
196
158
159
+ self:clear_callbacks()
160
+
197
161
local obj_st = self.st
198
162
199
- if obj_st.active_section then
163
+ if obj_st.active_scheme then
200
164
xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "death_callback", victim, culprit)
201
165
end
202
166
203
- victim:set_callback(callback.hit, nil) -- SRP
204
- victim:set_callback(callback.death, nil) -- SRP
205
- victim:set_callback(callback.use_object, nil) -- SRP
206
-
207
167
if self.particle ~= nil then
208
168
self.particle:stop()
209
169
end
210
170
211
- if self.disable_graph_point ~= nil then
212
- game_graph():accessible(self.disable_graph_point, true)
213
- end
214
-
215
171
if self.is_drop_box then
216
172
self.box_items:spawn_items()
217
173
end
174
+ end
175
+
176
+ function generic_physics_binder:use_callback(used_obj, user)
177
+
178
+ if self.is_inventory_box then
179
+ if used_obj:name() == "gar_smart_terrain_5_6_box" then
180
+ local actor = db.actor
181
+ if actor:has_info("gar_quest_redemption_started") then
182
+ actor:give_info_portion("gar_quest_redemption_done")
183
+ end
184
+ end
185
+ end
186
+
187
+ local obj_st = self.st
188
+
189
+ if obj_st.active_scheme then
190
+ xr_logic.issue_event(nil, obj_st[obj_st.active_scheme], "use_callback", used_obj, user)
191
+ end
192
+ end
193
+
194
+ --------------------------------------------------------------------------------
195
+
196
+ function generic_physics_binder:net_save_relevant()
197
+ return true
198
+ end
199
+
200
+ function generic_physics_binder:save(packet)
201
+ set_save_marker(packet, "save", false, "physics_binder")
202
+ object_binder.save(self, packet)
203
+ xr_logic.save_obj(self.object, packet)
204
+ set_save_marker(packet, "save", true, "physics_binder")
205
+ end
206
+
207
+ function generic_physics_binder:load(reader) -- called 4.5th (only on load)
208
+ set_save_marker(reader, "load", false, "physics_binder")
209
+ object_binder.load(self, reader)
210
+ xr_logic.load_obj(self.object, reader)
211
+ set_save_marker(reader, "load", true, "physics_binder")
212
+ self.loaded = true
218
213
end
0 commit comments