255 | function MultipleItemPurchase:getFillUnitCapacity(superFunc, fillUnitIndex) |
256 | if self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
257 | local fillLevel = 0 |
258 | local spec = self.spec_multipleItemPurchase |
259 | for _, bale in ipairs(spec.loadedBales) do |
260 | fillLevel = fillLevel + bale:getFillLevel() |
261 | end |
262 | |
263 | for _, vehicle in ipairs(spec.loadedVehicles) do |
264 | if vehicle.getFillUnitCapacity ~= nil then |
265 | fillLevel = fillLevel + vehicle:getFillUnitCapacity(1) |
266 | end |
267 | end |
268 | |
269 | return fillLevel |
270 | end |
271 | |
272 | return 0 |
273 | end |
15 | function MultipleItemPurchase.initSpecialization() |
16 | g_configurationManager:addConfigurationType("multipleItemPurchaseAmount", g_i18n:getText("configuration_buyableBaleAmount"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION) |
17 | |
18 | local schema = Vehicle.xmlSchema |
19 | schema:setXMLSpecializationType("MultipleItemPurchase") |
20 | |
21 | schema:register(XMLValueType.STRING, "vehicle.multipleItemPurchase#filename", "Item filename") |
22 | schema:register(XMLValueType.BOOL, "vehicle.multipleItemPurchase#isVehicle", "Is Loading a vehicle (false=Bale)", false) |
23 | schema:register(XMLValueType.STRING, "vehicle.multipleItemPurchase#fillType", "Bale fill type", "STRAW") |
24 | schema:register(XMLValueType.BOOL, "vehicle.multipleItemPurchase#baleIsWrapped", "Bale is wrapped", false) |
25 | |
26 | schema:register(XMLValueType.VECTOR_TRANS, "vehicle.multipleItemPurchase.offsets.offset(?)#offset", "Offset") |
27 | schema:register(XMLValueType.FLOAT, "vehicle.multipleItemPurchase.offsets.offset(?)#amount", "Amount of items to activate offset") |
28 | |
29 | schema:register(XMLValueType.VECTOR_TRANS, "vehicle.multipleItemPurchase.itemPositions.itemPosition(?)#position", "Bale position") |
30 | schema:register(XMLValueType.VECTOR_ROT, "vehicle.multipleItemPurchase.itemPositions.itemPosition(?)#rotation", "Bale rotation") |
31 | |
32 | schema:setXMLSpecializationType(XMLManager.XML_SPECIALIZATION_NONE) |
33 | end |
143 | function MultipleItemPurchase:loadItemAtPosition(position) |
144 | local spec = self.spec_multipleItemPurchase |
145 | |
146 | if self.isServer or self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
147 | local x, y, z = localToWorld(self.components[1].node, unpack(position.position)) |
148 | local rx, ry, rz = localRotationToWorld(self.components[1].node, unpack(position.rotation)) |
149 | |
150 | if not spec.isVehicle then |
151 | local baleObject = Bale.new(self.isServer, self.isClient) |
152 | if baleObject:loadFromConfigXML(spec.itemFilename, x, y, z, rx, ry, rz) then |
153 | baleObject:setFillType(spec.baleFillTypeIndex, true) |
154 | baleObject:setOwnerFarmId(self:getActiveFarm(), true) |
155 | if self.propertyState ~= Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
156 | baleObject:register() |
157 | end |
158 | |
159 | if spec.baleIsWrapped then |
160 | baleObject:setWrappingState(1) |
161 | |
162 | if self.configurations["baseColor"] ~= nil then |
163 | local color = ConfigurationUtil.getColorByConfigId(self, "baseColor", self.configurations["baseColor"]) |
164 | baleObject:setColor(unpack(color)) |
165 | end |
166 | end |
167 | |
168 | setPairCollision(self.components[1].node, baleObject.nodeId, false) |
169 | |
170 | table.insert(spec.loadedBales, baleObject) |
171 | end |
172 | else |
173 | local location = { |
174 | x = x, |
175 | y = y, |
176 | z = z, |
177 | xRot = rx, |
178 | yRot = ry, |
179 | zRot = rz |
180 | } |
181 | |
182 | self.subLoadingTasksFinished = false |
183 | self.numPendingSubLoadingTasks = self.numPendingSubLoadingTasks + 1 |
184 | |
185 | local registerVehicle = self.propertyState ~= Vehicle.PROPERTY_STATE_SHOP_CONFIG |
186 | local forceServer = self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG |
187 | VehicleLoadingUtil.loadVehicle(spec.itemFilename, location, true, 0, self.propertyState, self:getActiveFarm(), nil, nil, self.onFinishLoadingVehicle, self, nil, registerVehicle, forceServer) |
188 | end |
189 | end |
190 | end |
194 | function MultipleItemPurchase:onFinishLoadingVehicle(vehicle, vehicleLoadState) |
195 | local spec = self.spec_multipleItemPurchase |
196 | if vehicleLoadState == VehicleLoadingUtil.VEHICLE_LOAD_OK then |
197 | table.insert(spec.loadedVehicles, vehicle) |
198 | end |
199 | |
200 | self.numPendingSubLoadingTasks = self.numPendingSubLoadingTasks - 1 |
201 | self.subLoadingTasksFinished = self.numPendingSubLoadingTasks == 0 |
202 | if not self.isDeleted and not self.isDeleting then |
203 | if self.syncVehicleLoadingFinished then |
204 | self:tryFinishLoading() |
205 | end |
206 | end |
207 | end |
70 | function MultipleItemPurchase:onLoad(savegame) |
71 | local spec = self.spec_multipleItemPurchase |
72 | |
73 | spec.loadedBales = {} |
74 | spec.loadedVehicles = {} |
75 | |
76 | spec.itemFilename = Utils.getFilename(self.xmlFile:getValue("vehicle.multipleItemPurchase#filename"), self.baseDirectory) |
77 | spec.isVehicle = self.xmlFile:getValue("vehicle.multipleItemPurchase#isVehicle", false) |
78 | |
79 | local fillTypeName = self.xmlFile:getValue("vehicle.multipleItemPurchase#fillType", "STRAW") |
80 | spec.baleFillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName) |
81 | spec.baleIsWrapped = self.xmlFile:getValue("vehicle.multipleItemPurchase#baleIsWrapped", false) |
82 | |
83 | local positionOffset = {0, 0, 0} |
84 | local i = 0 |
85 | while true do |
86 | local baseKey = string.format("vehicle.multipleItemPurchase.offsets.offset(%d)", i) |
87 | if not self.xmlFile:hasProperty(baseKey) then |
88 | break |
89 | end |
90 | |
91 | local offset = self.xmlFile:getValue(baseKey.."#offset", nil, true) |
92 | local amount = self.xmlFile:getValue(baseKey.."#amount") |
93 | |
94 | if amount <= self.configurations["multipleItemPurchaseAmount"] then |
95 | positionOffset = offset |
96 | end |
97 | |
98 | i = i + 1 |
99 | end |
100 | |
101 | spec.positions = {} |
102 | i = 0 |
103 | while true do |
104 | local baseKey = string.format("vehicle.multipleItemPurchase.itemPositions.itemPosition(%d)", i) |
105 | if not self.xmlFile:hasProperty(baseKey) then |
106 | break |
107 | end |
108 | |
109 | local position = self.xmlFile:getValue(baseKey.."#position", nil, true) |
110 | local rotation = self.xmlFile:getValue(baseKey.."#rotation", nil, true) |
111 | if position ~= nil and rotation ~= nil then |
112 | if positionOffset ~= nil then |
113 | for j=1, 3 do |
114 | position[j] = position[j] + positionOffset[j] |
115 | end |
116 | end |
117 | |
118 | table.insert(spec.positions, {position=position, rotation=rotation}) |
119 | end |
120 | |
121 | i = i + 1 |
122 | end |
123 | |
124 | if not self.isServer then |
125 | SpecializationUtil.removeEventListener(self, "onUpdate", MultipleItemPurchase) |
126 | end |
127 | end |