File size: 2,073 Bytes
b6a38d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
function AutoAttachObject:OnDestroy()
	if self:GetAutoAttachMode("OFF") ~= "" then
		self:SetAutoAttachMode("OFF")
	end
end

function AutoAttachObject:SetState(state, flags, crossfade, speed)
	self:DestroyAutoAttaches()
	self:ClearAttachMembers()
	
	-- Call original SetState
	if speed == nil and flags == nil and crossfade == nil then
		g_CObjectFuncs.SetState(self, state)
	elseif speed == nil and crossfade == nil then
		g_CObjectFuncs.SetState(self, state, flags)
	elseif crossfade == nil then
		g_CObjectFuncs.SetState(self, state, flags, crossfade)
	else
		g_CObjectFuncs.SetState(self, state, flags, crossfade, speed)
	end
	
	local mode = (state ~= "broken") and self:GetAutoAttachMode() or false
	self:SetAutoAttachMode(mode)
end

function AutoAttachObject:SetAutoAttachMode(value)
	if self.auto_attach_mode ~= value and value == "OFF" and self:IsKindOf("DecorStateFXObject") then
		PlayFX("DecorState", "end", self, self:GetStateText())
	end
	
	local parent = self:GetParent()
	local floatingDummy = GetTopmostParent(self)
	
	if not IsKindOf(floatingDummy, "FloatingDummy") then
		floatingDummy = false
	end
	if floatingDummy then
		self:ForEachAttach("FloatingDummyCollision", RestoreFloatingDummyAttach)
		MapForEach(self:GetPos(), guim * 10, "FloatingDummyCollision", function(o)
			if o.clone_of == self then
				RestoreFloatingDummyAttach(o)
			end
		end)
	end
	
	self.auto_attach_mode = value
	self:DestroyAutoAttaches()
	self:ClearAttachMembers()
	self:AutoAttachObjects()
	
	if floatingDummy then
		AttachObjectToFloatingDummy(self, floatingDummy, parent ~= floatingDummy and parent or nil)
	end
end

function AutoAttachObject:OnEditorSetProperty(prop_id, old_value, ged)
	if prop_id == "AllAttachedLightsToDetailLevel" or prop_id == "StateText" then
		self:SetAutoAttachMode(self:GetAutoAttachMode())
		if prop_id == "AllAttachedLightsToDetailLevel" then
			self:ForEachAttach(function(attach)
				if IsKindOf(attach, "Light") then
					Stealth_HandleLight(attach)
				end
			end)
		end
	end
	Object.OnEditorSetProperty(self, prop_id, old_value, ged)
end