71 | function WoodSellTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
72 | if self.isEnabled and onEnter then |
73 | if otherActorId ~= 0 then |
74 | local splitType = SplitUtil.splitTypes[getSplitType(otherActorId)]; |
75 | if splitType ~= nil and splitType.pricePerLiter > 0 then |
76 | |
77 | if g_currentMission.time > self.nextTimeSamplePlay then |
78 | self.nextTimeSamplePlay = g_currentMission.time + 500; |
79 | playSample(g_currentMission.cashRegistrySound, 1, 1, 0); |
80 | end; |
81 | |
82 | if g_currentMission:getIsServer() then |
83 | |
84 | local volume = getVolume(otherActorId); |
85 | local qualityScale = 1; |
86 | local lengthScale = 1; |
87 | local defoliageScale = 1; |
88 | local sizeX, sizeY, sizeZ, numConvexes, numAttachments = getSplitShapeStats(otherActorId); |
89 | if sizeX ~= nil and volume > 0 then |
90 | local bvVolume = sizeX*sizeY*sizeZ; |
91 | local volumeRatio = bvVolume / volume; |
92 | local volumeQuality = 1-math.sqrt(Utils.clamp((volumeRatio-3)/7, 0,1)) * 0.95; -- ratio <= 3: 100%, ratio >= 10: 5% |
93 | local convexityQuality = 1-Utils.clamp((numConvexes-2)/(6-2), 0,1) * 0.95-- 0-2: 100%:, >= 6: 5% |
94 | |
95 | local maxSize = math.max(sizeX, math.max(sizeY, sizeZ)); |
96 | -- 1m: 60%, 6-11m: 120%, 19m: 60% |
97 | if maxSize < 11 then |
98 | lengthScale = 0.6 + math.min(math.max((maxSize-1)/5, 0), 1)*0.6; |
99 | else |
100 | lengthScale = 1.2 - math.min(math.max((maxSize-11)/8, 0), 1)*0.6; |
101 | end |
102 | |
103 | local minQuality = math.min(convexityQuality,volumeQuality); |
104 | local maxQuality = math.max(convexityQuality,volumeQuality); |
105 | qualityScale = minQuality + (maxQuality-minQuality) * 0.3; -- use 70% of min quality |
106 | |
107 | defoliageScale = 1-math.min(numAttachments/15, 1) * 0.8; -- #attachments 0: 100%, >=15: 20% |
108 | end |
109 | -- Only take 33% into account of the quality criteria on low |
110 | qualityScale = Utils.lerp(1, qualityScale, g_currentMission.missionInfo.difficulty/3); |
111 | defoliageScale = Utils.lerp(1, defoliageScale, g_currentMission.missionInfo.difficulty/3); |
112 | local baseValue = volume*1000*splitType.pricePerLiter*qualityScale*defoliageScale * lengthScale; |
113 | |
114 | -- update tons of wood sold for achievements |
115 | g_currentMission.missionStats:updateStats("woodTonsSold", volume); |
116 | |
117 | local difficultyMultiplier = g_currentMission.missionInfo.sellPriceMultiplier; |
118 | g_currentMission:addSharedMoney(baseValue * difficultyMultiplier * self.priceMultiplier, "soldWood"); |
119 | g_currentMission:addMoneyChange(baseValue * difficultyMultiplier * self.priceMultiplier, FSBaseMission.MONEY_TYPE_SINGLE, true, g_i18n:getText("finance_soldWood")); |
120 | delete(otherActorId); |
121 | |
122 | for _, listener in pairs(self.updateEventListeners) do |
123 | listener:onWoodSellingUpdateEvent(self, baseValue * difficultyMultiplier * self.priceMultiplier); |
124 | end; |
125 | end |
126 | end |
127 | end |
128 | end |
129 | |
130 | end |