--Specjalizacja dla Przetrzasacz pajak--
--Autor: Rockstar94--
--Data: 19.17.2014--

Przetrzasacz = {};

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

function Przetrzasacz:load(xmlFile)
	local walek = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#walek"));
   	if walek ~= nil then
		self.walek = walek;
	end;
	local awaria = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.awaria#index"));
	if awaria ~= nil then
		self.awaria = awaria;
	end;
	    self.czas1 = 0;
end;

 function Przetrzasacz:delete()
end;

function Przetrzasacz:keyEvent(unicode, sym, modifier, isDown)
 end;
 
function Przetrzasacz:update(dt)	
	if self.isTurnedOn then
	   self:setAnimationTime(1, 1);
    else
	   self:setAnimationTime(1, 0);
    end;
    local nearestDistance = 2;
    local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
    local px, py, pz = getWorldTranslation(self.walek);
    local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);
    if distance < nearestDistance then
        self.przywalek = true;
    else
        self.przywalek = false;
    end;
    if self.przywalek then
    if InputBinding.hasEvent(InputBinding.walek) then
    if self.animationParts[2].clipEndTime then
       self:setAnimationTime(2, self.animationParts[2].offSet);
    elseif self.animationParts[2].clipStartTime then
       self:setAnimationTime(2, self.animationParts[2].animDuration);
    end;
    end;
    end;
	if self.przywalek then
	if self.animationParts[2].clipStartTime then
		g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Zaczep_walek")), InputBinding.walek);
	else
		g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Odczep_walek")), InputBinding.walek);
	end;
	end;
	local nearestDistance = 2;
	local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
    local px, py, pz = getWorldTranslation(self.awaria);
    local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);
	if distance < nearestDistance then
		self.przypas = true; 
	else
		self.przypas = false; 
	end;
	
	if self.przypas then
	if Input.isKeyPressed(Input.KEY_m) then
	    self.napraw = true;
	    self.psucie = false;
	else
	    self.psucie = true;
        self.napraw = false;
    end;
	end;	
	if  self.isTurnedOn then
    if self.czas1 <= 10000 then
        self.czas1 = self.czas1 +(dt/1);
    end;
    end;
    if self.czas1 >= 10000 then
       self.psucie = true;
    else
       self.psucie = false;
    end;  
	if self.psucie then
    if self.animationParts[3].clipStartTime then
	   self:setAnimationTime(3, self.animationParts[3].animDuration);
	end;
	   self.isTurnedOn = false;
	end;
    if not self.psucie then
	if self.animationParts[3].clipEndTime then
		self:setAnimationTime(3, self.animationParts[3].offSet);
	end;
	end;
	if self.napraw then
       self.czas1 = 0;
    end;
	if self.psucie and self:getIsActive(false) then
		g_currentMission:addWarning(g_i18n:getText("info"), 0.07+0.022, 0.019+0.029);
	end;
	
	if self.przypas and self.psucie then
		g_currentMission:addWarning(g_i18n:getText("info1"), 0.07+0.022, 0.019+0.029);
	end;
	if self.przypas and self.psucie and Input.isKeyPressed(Input.KEY_m) then
		g_currentMission:addSharedMoney(-69);
	end;
	if self.animationParts[2].clipStartTime then
		self.isTurnedOn = false;
	end;	
	if self.animationParts[2].clipStartTime and self:getIsActive(false) and Input.isKeyPressed(Input.KEY_b) then
	g_currentMission:addWarning(g_i18n:getText("info2"), 0.07+0.022, 0.019+0.029);
	end;
end;

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

function Przetrzasacz:validateAttacherJoint(implement, jointDesc, dt)
return true;
end;

function Przetrzasacz:draw()

end;