--
-- Specialization intSoundK5
--
-- @Author  	Aluha74rus
-- @version 	v1.0
-- @date  		04/09/19

intSoundK5 = {};

intSoundK5.modDir = g_currentModDirectory;

function intSoundK5.prerequisitesPresent(specializations)
    return true; 
end;

function intSoundK5.registerEventListeners(vehicleType)	
	SpecializationUtil.registerEventListener(vehicleType, "onLoad", intSoundK5)
	SpecializationUtil.registerEventListener(vehicleType, "onDelete", intSoundK5)
	SpecializationUtil.registerEventListener(vehicleType, "onUpdate", intSoundK5)
end
function intSoundK5:onLoad(savegame)
	if self.isClient then
	    self.sampleOpenKapot = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "openKapot", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleCloseKapot = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "closeKapot", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleOpenLeftDoor = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "openLeftDoor", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleCloseLeftDoor = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "closeLeftDoor", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetStart = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetStart", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetEnd = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetEnd", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkStart = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkStart", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkEnd = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkEnd", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkBackStart = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkBackStart", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	    self.sampleKLSwetWorkBackEnd = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.sounds", "KLSwetWorkBackEnd", self.baseDirectory, self.components, 1, AudioGroup.VEHICLE, self.i3dMappings, self)
	end
end;

function intSoundK5:onDelete()
    if self.isClient then
		g_soundManager.deleteSample(self.sampleOpenKapot);
		g_soundManager.deleteSample(self.sampleCloseKapot);
		g_soundManager.deleteSample(self.sampleOpenLeftDoor);
		g_soundManager.deleteSample(self.sampleCloseLeftDoor);
		g_soundManager.deleteSample(self.sampleKLSwetStart);
		g_soundManager.deleteSample(self.sampleKLSwetEnd);
		g_soundManager.deleteSample(self.sampleKLSwetWorkStart);
		g_soundManager.deleteSample(self.sampleKLSwetWorkEnd);
		g_soundManager.deleteSample(self.sampleKLSwetWorkBackStart);
		g_soundManager.deleteSample(self.sampleKLSwetWorkBackEnd);
    end
end

function intSoundK5:onUpdate(dt)
	
    
    if self.isClient then
	    if self:getIsAnimationPlaying("Dver") then
		    if self.spec_animatedVehicle.animations["Dver"].currentSpeed > 0 and self.spec_animatedVehicle.animations["Dver"].currentTime < 50 then
			    if not g_soundManager:playSample(self.sampleOpenLeftDoor,1.5*dt) then
				    g_soundManager:playSample(self.sampleOpenLeftDoor,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["Dver"].currentSpeed < 0 and self.spec_animatedVehicle.animations["Dver"].currentTime > 2600 then
			    if not g_soundManager:playSample(self.sampleCloseLeftDoor,1.5*dt) then
				    g_soundManager:playSample(self.sampleCloseLeftDoor,1.5*dt);
			    end;
		    end;
		end;
	    if self:getIsAnimationPlaying("Kapot") then
		    if self.spec_animatedVehicle.animations["Kapot"].currentSpeed > 0 and self.spec_animatedVehicle.animations["Kapot"].currentTime < 50 then
			    if not g_soundManager:playSample(self.sampleOpenKapot,1.5*dt) then
				    g_soundManager:playSample(self.sampleOpenKapot,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["Kapot"].currentSpeed < 0 and self.spec_animatedVehicle.animations["Kapot"].currentTime > 3650 then
			    if not g_soundManager:playSample(self.sampleCloseKapot,1.5*dt) then
				    g_soundManager:playSample(self.sampleCloseKapot,1.5*dt);
			    end;
		    end;
		end;
	    if self:getIsAnimationPlaying("klawishaBliznii") then
		    if self.spec_animatedVehicle.animations["klawishaBliznii"].currentSpeed > 0 and self.spec_animatedVehicle.animations["klawishaBliznii"].currentTime < 70 then
			    if not g_soundManager:playSample(self.sampleKLSwetStart,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetStart,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["klawishaBliznii"].currentSpeed < 0 and self.spec_animatedVehicle.animations["klawishaBliznii"].currentTime > 130 then
			    if not g_soundManager:playSample(self.sampleKLSwetEnd,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetEnd,1.5*dt);
			    end;
		    end;
		end;
	    if self:getIsAnimationPlaying("klawishaWork") then
		    if self.spec_animatedVehicle.animations["klawishaWork"].currentSpeed > 0 and self.spec_animatedVehicle.animations["klawishaWork"].currentTime < 70 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkStart,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkStart,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["klawishaWork"].currentSpeed < 0 and self.spec_animatedVehicle.animations["klawishaWork"].currentTime > 130 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkEnd,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkEnd,1.5*dt);
			    end;
		    end;
		end;
	    if self:getIsAnimationPlaying("klawishaWorkBack") then
		    if self.spec_animatedVehicle.animations["klawishaWorkBack"].currentSpeed > 0 and self.spec_animatedVehicle.animations["klawishaWorkBack"].currentTime < 70 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkBackStart,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkBackStart,1.5*dt);
			    end;
		    elseif self.spec_animatedVehicle.animations["klawishaWorkBack"].currentSpeed < 0 and self.spec_animatedVehicle.animations["klawishaWorkBack"].currentTime > 130 then
			    if not g_soundManager:playSample(self.sampleKLSwetWorkBackEnd,1.5*dt) then
				    g_soundManager:playSample(self.sampleKLSwetWorkBackEnd,1.5*dt);
			    end;
		    end;
		end;
	end;
end;