LUADOC - Farming Simulator 22

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
137function HighPressureWasherLance:cleanVehicle(node, dt)
138 local x, y, z = getWorldTranslation(node)
139 local dx, dy, dz = localDirectionToWorld(node, 0, 0, -1)
140 local lastFoundVehicle = self.foundVehicle
141 raycastAll(x, y, z, dx, dy, dz, "washRaycastCallback", self.washDistance, self, 32+64+128+256+4096+8194)
142
143 if self.foundVehicle ~= nil and lastFoundVehicle ~= self.foundVehicle then
144 self.foundVehicle:addDirtAmount(-self.washMultiplier * dt / self.foundVehicle:getWashDuration())
145 end
146end

delete

Description
Deleting
Definition
delete()
Code
67function HighPressureWasherLance:delete()
68 g_effectManager:deleteEffects(self.effects)
69 g_soundManager:deleteSample(self.washingSample)
70 HighPressureWasherLance:superClass().delete(self)
71end

getIsActiveForInput

Description
Get is active for input
Definition
getIsActiveForInput()
Return Values
booleanisActiveForInputis active for input
Code
186function HighPressureWasherLance:getIsActiveForInput()
187 if self.player == g_currentMission.player and not g_gui:getIsGuiVisible() then
188 return true
189 end
190 return false
191end

isBeingUsed

Description
Definition
isBeingUsed()
Code
195function HighPressureWasherLance:isBeingUsed()
196 return self.doWashing
197end

new

Description
Definition
new()
Code
29function HighPressureWasherLance.new(isServer, isClient, customMt)
30 local self = HighPressureWasherLance:superClass().new(isServer, isClient, customMt or HighPressureWasherLance_mt)
31
32 self.foundVehicle = nil
33 self.doWashing = false
34 self.washDistance = 10.0
35 self.washMultiplier = 1.0
36 self.pricePerSecond = 10
37 self.isHPWLance = true
38
39 return self
40end

onDeactivate

Description
Definition
onDeactivate()
Code
75function HighPressureWasherLance:onDeactivate()
76 self:setIsWashing(false, true, true)
77 HighPressureWasherLance:superClass().onDeactivate(self)
78end

postLoad

Description
Called after hand tool i3d file was loaded
Definition
postLoad(table xmlFile)
Arguments
tablexmlFilexmlFile
Code
45function HighPressureWasherLance:postLoad(xmlFile)
46 if not HighPressureWasherLance:superClass().postLoad(self, xmlFile) then
47 return false
48 end
49
50 self.lanceNode = xmlFile:getValue("handTool.highPressureWasherLance.lance#node", nil, self.components, self.i3dMappings)
51 self.lanceRaycastNode = xmlFile:getValue("handTool.highPressureWasherLance.lance#raycastNode", nil, self.components, self.i3dMappings)
52 self.washDistance = xmlFile:getValue("handTool.highPressureWasherLance.lance#washDistance", 10)
53 self.washMultiplier = xmlFile:getValue("handTool.highPressureWasherLance.lance#washMultiplier", 1)
54 self.pricePerSecond = xmlFile:getValue("handTool.highPressureWasherLance.lance#pricePerMinute", 10) / 1000
55
56 self.effects = g_effectManager:loadEffect(xmlFile, "handTool.highPressureWasherLance.effects", self.components, self, self.i3dMappings)
57 g_effectManager:setFillType(self.effects, FillType.WATER)
58
59 -- Sounds
60 self.washingSample = g_soundManager:loadSampleFromXML(xmlFile, "handTool.highPressureWasherLance.sounds", "washing", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
61
62 return true
63end

setIsWashing

Description
Set is washing
Definition
setIsWashing(boolean doWashing, boolean force, boolean noEventSend)
Arguments
booleandoWashingdo washing
booleanforceforce
booleannoEventSendno event send
Code
114function HighPressureWasherLance:setIsWashing(doWashing, force, noEventSend)
115 HPWLanceStateEvent.sendEvent(self.player, doWashing, noEventSend)
116 if self.doWashing ~= doWashing then
117 if doWashing then
118 g_effectManager:setFillType(self.effects, FillType.WATER)
119 g_effectManager:startEffects(self.effects)
120 g_soundManager:playSample(self.washingSample)
121 else
122 if force then
123 g_effectManager:resetEffects(self.effects)
124 else
125 g_effectManager:stopEffects(self.effects)
126 end
127 g_soundManager:stopSample(self.washingSample)
128 end
129 self.doWashing = doWashing
130 end
131end

update

Description
Definition
update()
Code
82function HighPressureWasherLance:update(dt, allowInput)
83 HighPressureWasherLance:superClass().update(self, dt)
84
85 if allowInput then
86 self:setIsWashing(self.activatePressed, false, false)
87 end
88
89 if self.isServer then
90 if self.doWashing then
91 self.foundVehicle = nil
92 self:cleanVehicle(self.player.cameraNode, dt)
93 if self.lanceRaycastNode ~= nil then
94 self:cleanVehicle(self.lanceRaycastNode, dt)
95 end
96 if self.foundVehicle ~= nil then
97 local farmId = self.foundVehicle:getOwnerFarmId()
98 local price = self.pricePerSecond * (dt / 1000)
99 local stats = g_farmManager:getFarmById(self.player.farmId).stats
100 stats:updateStats("expenses", price)
101 g_currentMission:addMoney(-price, farmId, MoneyType.VEHICLE_RUNNING_COSTS)
102 end
103 end
104 end
105 self.activatePressed = false
106 self:raiseActive()
107end

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
160function HighPressureWasherLance:washRaycastCallback(hitActorId, x, y, z, distance, nx, ny, nz, subShapeIndex, hitShapeId)
161 local vehicle = g_currentMission.nodeToObject[hitActorId]
162 if hitActorId ~= hitShapeId then
163 -- object is a compoundChild. Try to find the compound
164 local parentId = hitShapeId
165 while parentId ~= 0 do
166 if g_currentMission.nodeToObject[parentId] ~= nil then
167 -- found valid compound
168 vehicle = g_currentMission.nodeToObject[parentId]
169 break
170 end
171 parentId = getParent(parentId)
172 end
173 end
174
175 if vehicle ~= nil and vehicle.getAllowsWashingByType ~= nil and vehicle:getAllowsWashingByType(Washable.WASHTYPE_HIGH_PRESSURE_WASHER) then
176 self.foundVehicle = vehicle
177 return false
178 end
179 return true
180end