Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- WoodSellTrigger class |
2 | -- |
3 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
4 | |
5 | WoodSellTrigger = {} |
6 | |
7 | local WoodSellTrigger_mt = Class(WoodSellTrigger); |
8 | |
9 | function WoodSellTrigger:onCreate(id) |
10 | g_currentMission:addNonUpdateable(WoodSellTrigger:new(id)); |
11 | end |
12 | |
13 | function WoodSellTrigger:new(nodeId) |
14 | local self = {}; |
15 | setmetatable(self, WoodSellTrigger_mt); |
16 | |
17 | self.triggerId = nodeId; |
18 | addTrigger(nodeId, "triggerCallback", self); |
19 | |
20 | self.updateEventListeners = {}; |
21 | self.nextTimeSamplePlay = 0; |
22 | self.isEnabled = true; |
23 | |
24 | self.priceMultiplier = Utils.getNoNil(getUserAttribute(nodeId, "priceMultiplier"), 1); |
25 | |
26 | return self; |
27 | end |
28 | |
29 | function WoodSellTrigger:delete() |
30 | if self.triggerId ~= nil then |
31 | removeTrigger(self.triggerId); |
32 | end |
33 | end |
34 | |
35 | function WoodSellTrigger:addUpdateEventListener(listener) |
36 | if listener ~= nil then |
37 | self.updateEventListeners[listener] = listener; |
38 | end; |
39 | end; |
40 | |
41 | function WoodSellTrigger:removeUpdateEventListener(listener) |
42 | if listener ~= nil then |
43 | self.updateEventListeners[listener] = nil; |
44 | end; |
45 | end; |
46 | |
47 | function WoodSellTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
48 | if self.isEnabled and onEnter then |
49 | if otherActorId ~= 0 then |
50 | local splitType = SplitUtil.splitTypes[getSplitType(otherActorId)]; |
51 | if splitType ~= nil and splitType.pricePerLiter > 0 then |
52 | |
53 | if g_currentMission.time > self.nextTimeSamplePlay then |
54 | self.nextTimeSamplePlay = g_currentMission.time + 500; |
55 | playSample(g_currentMission.cashRegistrySound, 1, 1, 0); |
56 | end; |
57 | |
58 | if g_currentMission:getIsServer() then |
59 | |
60 | local volume = getVolume(otherActorId); |
61 | local qualityScale = 1; |
62 | local lengthScale = 1; |
63 | local defoliageScale = 1; |
64 | local sizeX, sizeY, sizeZ, numConvexes, numAttachments = getSplitShapeStats(otherActorId); |
65 | if sizeX ~= nil and volume > 0 then |
66 | local bvVolume = sizeX*sizeY*sizeZ; |
67 | local volumeRatio = bvVolume / volume; |
68 | local volumeQuality = 1-math.sqrt(Utils.clamp((volumeRatio-3)/7, 0,1)) * 0.95; -- 100% if ratio <= 3, 5% if ratio >= 10 |
69 | local convexityQuality = 1-Utils.clamp((numConvexes-2)/(6-2), 0,1) * 0.95-- 100%: 0-2, 5%: >= 6 |
70 | |
71 | local maxSize = math.max(sizeX, math.max(sizeY, sizeZ)); |
72 | -- 3m: 100%, 6-11m: 120%, 19m: 60% |
73 | if maxSize < 11 then |
74 | lengthScale = 1 + math.min(math.max((maxSize-3)/3, 0), 1)*0.2; |
75 | else |
76 | lengthScale = 1.2 - math.min(math.max((maxSize-11)/8, 0), 1)*0.6; |
77 | end |
78 | |
79 | local minQuality = math.min(convexityQuality,volumeQuality); |
80 | local maxQuality = math.max(convexityQuality,volumeQuality); |
81 | qualityScale = minQuality + (maxQuality-minQuality) * 0.3; -- use 70% of min quality |
82 | |
83 | defoliageScale = 1-Utils.clamp(numAttachments-4/11, 0,1) * 0.5; -- #attachments 0-4: 100%, >=15: 50% |
84 | --print("lengthScale: "..lengthScale.." quality scale: "..qualityScale.. " volumeQuality: "..volumeQuality.. " convexityQuality: "..convexityQuality.. " defoliageScale: "..defoliageScale.." volume: "..volume.." bvvolume: " ..bvVolume.." size: "..sizeX.." " ..sizeY.." " ..sizeZ.. " numAttachments: "..numAttachments); |
85 | end |
86 | -- Only take 33% into account of the quality criteria on low |
87 | qualityScale = Utils.lerp(1, qualityScale, g_currentMission.missionStats.difficulty/3); |
88 | defoliageScale = Utils.lerp(1, defoliageScale, g_currentMission.missionStats.difficulty/3); |
89 | local baseValue = volume*1000*splitType.pricePerLiter*qualityScale*defoliageScale * lengthScale; |
90 | |
91 | --print("base value: "..baseValue.. " final quality: "..qualityScale); |
92 | |
93 | local difficultyMultiplier = 2 ^ (3 - g_currentMission.missionStats.difficulty); |
94 | g_currentMission:addSharedMoney(baseValue * difficultyMultiplier * self.priceMultiplier, "harvestIncome"); |
95 | g_currentMission:addMoneyChange(baseValue * difficultyMultiplier * self.priceMultiplier, FSBaseMission.MONEY_TYPE_SINGLE, true); |
96 | delete(otherActorId); |
97 | |
98 | for _, listener in pairs(self.updateEventListeners) do |
99 | listener:onWoodSellingUpdateEvent(self, baseValue * difficultyMultiplier * self.priceMultiplier); |
100 | end; |
101 | end |
102 | end |
103 | end |
104 | end |
105 | |
106 | end
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de