-- Specjalizacja dla Bizon ZO56 --
-- Autor: Rockstar94 --
-- 25.01.2015 --


print("Adrian W. to stara kurwa"); 
heder_ZO56 = {};

function heder_ZO56.prerequisitesPresent(specializations)
    return true
end;

function heder_ZO56:load(xmlFile)
	local przy_heder = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.przy_heder#index"));
	if przy_heder ~= nil then
		self.przy_heder = przy_heder;
	end;
end;

function heder_ZO56:delete()
end;

function heder_ZO56:mouseEvent(posX, posY, isDown, isUp, button)
end;

function heder_ZO56:keyEvent(unicode, sym, modifier, isDown)
end;

function heder_ZO56:update(dt)
	local nearestDistance = 2;
    local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
    local px, py, pz = getWorldTranslation(self.przy_heder);
    local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);
		if distance < nearestDistance then
			self.przy_hederze = true;
		else
			self.przy_hederze = false;
		end;
		
    if self.przy_hederze then
		if InputBinding.hasEvent(InputBinding.mlocarnia) then
			if self.animationParts[7].clipEndTime then
				self:setAnimationTime(7, self.animationParts[7].offSet);
			elseif self.animationParts[7].clipStartTime  then
				self:setAnimationTime(7, self.animationParts[7].animDuration);			
			end;
		end;
    end;
	
	if self.przy_hederze then
		if self.animationParts[7].clipStartTime then
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("heder_1")), InputBinding.mlocarnia);
		else
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("heder_2")), InputBinding.mlocarnia);
		end;
	end;

	if self.reelStarted then    
		self:setAnimationTime(1, 1);
		self:setAnimationTime(2, 1);
		self:setAnimationTime(6, 1);
	else
		self:setAnimationTime(1, 0);
		self:setAnimationTime(2, 0);
		self:setAnimationTime(6, 0);
	end;
	
	if Input.isKeyPressed(Input.KEY_KP_7) then
		self:setAnimationTime(3, self.animationParts[3].currentPosition+(self.animationParts[3].offSet+dt), false);
	elseif Input.isKeyPressed(Input.KEY_KP_4) then
		self:setAnimationTime(3, self.animationParts[3].currentPosition-(self.animationParts[3].offSet+dt), false);
	end;
	
	if Input.isKeyPressed(Input.KEY_KP_8) then
		self:setAnimationTime(4, self.animationParts[4].currentPosition+(self.animationParts[4].offSet+dt), false);
		self:setAnimationTime(5, self.animationParts[5].currentPosition+(self.animationParts[5].offSet+dt), false);
	elseif Input.isKeyPressed(Input.KEY_KP_5) then
		self:setAnimationTime(4, self.animationParts[4].currentPosition-(self.animationParts[4].offSet+dt), false);
		self:setAnimationTime(5, self.animationParts[5].currentPosition-(self.animationParts[5].offSet+dt), false);
	end;
	
	if Input.isKeyPressed(Input.KEY_KP_9) then
		if self.animationParts[2].clipSpeed < 5 then
			self.animationParts[2].clipSpeed = self.animationParts[2].clipSpeed+0.01;
		end;
	end;
	
	if Input.isKeyPressed(Input.KEY_KP_6) then
		if self.animationParts[2].clipSpeed > 0.5 then
			self.animationParts[2].clipSpeed = self.animationParts[2].clipSpeed-0.01;
		end;
	end;
end;

function heder_ZO56:onLeave()
end;

function heder_ZO56:onEnter()
end;

function heder_ZO56:onDeactivate()
end;

function heder_ZO56:draw()
end;