LUADOC - Farming Simulator 19

HighPressureWasherLance

Description
Class for high pressure washer lance
Parent
HandTool
Functions

cleanVehicle

Description
Clean vehicle
Definition
cleanVehicle(integer node, float dt)
Arguments
integernodenode id
floatdttime since last call in ms
Code
123function HighPressureWasherLance:cleanVehicle(node, dt)
124 local x, y, z = getWorldTranslation(node)
125 local dx, dy, dz = localDirectionToWorld(node, 0, 0, -1)
126 local lastFoundVehicle = self.foundVehicle
127 raycastAll(x, y, z, dx, dy, dz, "washRaycastCallback", self.washDistance, self, 32+64+128+256+4096+8194)
128
129 if self.foundVehicle ~= nil and lastFoundVehicle ~= self.foundVehicle then
130 self.foundVehicle:addDirtAmount(-self.washMultiplier * dt / self.foundVehicle:getWashDuration())
131 end
132end

delete

Description
Deleting
Definition
delete()
Code
53function HighPressureWasherLance:delete()
54 g_effectManager:deleteEffects(self.effects)
55 g_soundManager:deleteSample(self.washingSample)
56 HighPressureWasherLance:superClass().delete(self)
57end

getIsActiveForInput

Description
Get is active for input
Definition
getIsActiveForInput()
Return Values
booleanisActiveForInputis active for input
Code
172function HighPressureWasherLance:getIsActiveForInput()
173 if self.player == g_currentMission.player and not g_gui:getIsGuiVisible() then
174 return true
175 end
176 return false
177end

isBeingUsed

Description
Definition
isBeingUsed()
Code
181function HighPressureWasherLance:isBeingUsed()
182 return self.doWashing
183end

load

Description
Definition
load()
Code
29function HighPressureWasherLance:load(xmlFilename, player)
30 if not HighPressureWasherLance:superClass().load(self, xmlFilename, player) then
31 return false
32 end
33
34 -- Lance model
35 local xmlFile = loadXMLFile("TempXML", xmlFilename)
36 self.lanceNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.highPressureWasherLance.lance#node"))
37 self.lanceRaycastNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.highPressureWasherLance.lance#raycastNode"))
38 self.washDistance = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#washDistance"), 10)
39 self.washMultiplier = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#washMultiplier"), 1)
40 self.pricePerSecond = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#pricePerMinute"), 10) / 1000
41
42 self.effects = g_effectManager:loadEffect(xmlFile, "handTool.highPressureWasherLance.effects", self.rootNode, self)
43 g_effectManager:setFillType(self.effects, FillType.WATER)
44
45 -- Sounds
46 self.washingSample = g_soundManager:loadSampleFromXML(xmlFile, "handTool.highPressureWasherLance.sounds", "washing", self.baseDirectory, self.rootNode, 0, AudioGroup.VEHICLE, nil, self)
47
48 return true
49end

new

Description
Definition
new()
Code
14function HighPressureWasherLance:new(isServer, isClient, customMt)
15 local self = HighPressureWasherLance:superClass().new(self, isServer, isClient, customMt or HighPressureWasherLance_mt)
16
17 self.foundVehicle = nil
18 self.doWashing = false
19 self.washDistance = 10.0
20 self.washMultiplier = 1.0
21 self.pricePerSecond = 10
22 self.isHPWLance = true
23
24 return self
25end

onDeactivate

Description
Definition
onDeactivate()
Code
61function HighPressureWasherLance:onDeactivate()
62 self:setIsWashing(false, true, true)
63 HighPressureWasherLance:superClass().onDeactivate(self)
64end

setIsWashing

Description
Set is washing
Definition
setIsWashing(boolean doWashing, boolean force, boolean noEventSend)
Arguments
booleandoWashingdo washing
booleanforceforce
booleannoEventSendno event send
Code
100function HighPressureWasherLance:setIsWashing(doWashing, force, noEventSend)
101 HPWLanceStateEvent.sendEvent(self.player, doWashing, noEventSend)
102 if self.doWashing ~= doWashing then
103 if doWashing then
104 g_effectManager:setFillType(self.effects, FillType.WATER)
105 g_effectManager:startEffects(self.effects)
106 g_soundManager:playSample(self.washingSample)
107 else
108 if force then
109 g_effectManager:resetEffects(self.effects)
110 else
111 g_effectManager:stopEffects(self.effects)
112 end
113 g_soundManager:stopSample(self.washingSample)
114 end
115 self.doWashing = doWashing
116 end
117end

update

Description
Definition
update()
Code
68function HighPressureWasherLance:update(dt, allowInput)
69 HighPressureWasherLance:superClass().update(self, dt)
70
71 if allowInput then
72 self:setIsWashing(self.activatePressed, false, false)
73 end
74
75 if self.isServer then
76 if self.doWashing then
77 self.foundVehicle = nil
78 self:cleanVehicle(self.player.cameraNode, dt)
79 if self.lanceRaycastNode ~= nil then
80 self:cleanVehicle(self.lanceRaycastNode, dt)
81 end
82 if self.foundVehicle ~= nil then
83 local farmId = self.foundVehicle:getOwnerFarmId()
84 local price = self.pricePerSecond * (dt / 1000)
85 local stats = g_farmManager:getFarmById(self.player.farmId).stats
86 stats:updateStats("expenses", price)
87 g_currentMission:addMoney(-price, farmId, MoneyType.VEHICLE_RUNNING_COSTS)
88 end
89 end
90 end
91 self.activatePressed = false
92 self:raiseActive()
93end

washRaycastCallback

Description
Wash raycast callback
Definition
washRaycastCallback(integer hitActorId, float x, float y, float z, float distance, float nx, float ny, float nz, integer subShapeIndex, integer hitShapeId)
Arguments
integerhitActorIdid of hit object actor
floatxx raycast position
floatyy raycast position
floatzz raycast position
floatdistancedistance to raycast position
floatnxx component of hit surface normal (unused)
floatnyy component of hit surface normal (unused)
floatnzz component of hit surface normal (unused)
integersubShapeIndexsub shape index of hit object
integerhitShapeIdid of hit object shape
Code
146function HighPressureWasherLance:washRaycastCallback(hitActorId, x, y, z, distance, nx, ny, nz, subShapeIndex, hitShapeId)
147 local vehicle = g_currentMission.nodeToObject[hitActorId]
148 if hitActorId ~= hitShapeId then
149 -- object is a compoundChild. Try to find the compound
150 local parentId = hitShapeId
151 while parentId ~= 0 do
152 if g_currentMission.nodeToObject[parentId] ~= nil then
153 -- found valid compound
154 vehicle = g_currentMission.nodeToObject[parentId]
155 break
156 end
157 parentId = getParent(parentId)
158 end
159 end
160
161 if vehicle ~= nil and vehicle.getAllowsWashingByType ~= nil and vehicle:getAllowsWashingByType(Washable.WASHTYPE_HIGH_PRESSURE_WASHER) then
162 self.foundVehicle = vehicle
163 return false
164 end
165 return true
166end