2025-02-02 18:25:51 +00:00
|
|
|
-- Copyright (C) 2025 snoutie
|
|
|
|
-- Authors: snoutie (copyright@achtarmig.org)
|
|
|
|
-- This program is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU Affero General Public License as published
|
|
|
|
-- by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
-- (at your option) any later version.
|
|
|
|
|
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
-- You should have received a copy of the GNU Affero General Public License
|
|
|
|
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2025-02-02 18:07:50 +00:00
|
|
|
local M = {}
|
|
|
|
|
2025-03-06 17:27:00 +00:00
|
|
|
M.dependencies = { 'career_modules_inventory', 'freeroam_facilities', "career_vehicleSaveSystem",
|
2025-03-06 18:14:55 +00:00
|
|
|
"career_modules_permissions", 'career_modules_valueCalculator' }
|
2025-02-02 18:07:50 +00:00
|
|
|
|
2025-03-04 19:31:07 +00:00
|
|
|
local career_modules_inventory_removeVehicleObject
|
|
|
|
local vehicleObjectsToRemove = {}
|
2025-02-03 11:07:34 +00:00
|
|
|
|
|
|
|
local function spawnVehicle(inventoryId, callback)
|
|
|
|
if career_modules_inventory.getVehicleIdFromInventoryId(inventoryId) then
|
|
|
|
callback()
|
|
|
|
else
|
|
|
|
career_modules_inventory.spawnVehicle(inventoryId, nil, callback)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-03-06 17:09:31 +00:00
|
|
|
local function Retrieve(inventoryId)
|
2025-03-06 17:34:31 +00:00
|
|
|
career_vehicleSaveSystem.QueueVehicleToSave(inventoryId)
|
|
|
|
if not career_vehicleSaveSystem.SaveVehicle(inventoryId) then
|
|
|
|
career_vehicleSaveSystem.QueuedVehicleSaved(inventoryId)
|
|
|
|
end
|
2025-03-06 18:14:55 +00:00
|
|
|
|
|
|
|
local vehicleValue = career_modules_valueCalculator.getInventoryVehicleValue(inventoryId, true)
|
|
|
|
local currentVehicleValue = career_modules_valueCalculator.getInventoryVehicleValue(inventoryId)
|
|
|
|
|
2025-03-06 17:34:31 +00:00
|
|
|
career_vehicleSaveSystem.CheckSavedAsync(function()
|
|
|
|
extensions.core_jobsystem.create(
|
|
|
|
function(job)
|
|
|
|
spawnVehicle(inventoryId, function()
|
|
|
|
local veh = be:getObjectByID(career_modules_inventory.getVehicleIdFromInventoryId(inventoryId))
|
|
|
|
local location = { pos = veh:getPosition(), rot = quat(0, 0, 1, 0) * quat(veh:getRefNodeRotation()) }
|
|
|
|
local garage = career_modules_inventory.getClosestGarage(location.pos)
|
|
|
|
job.sleep(1)
|
2025-03-06 18:14:55 +00:00
|
|
|
if currentVehicleValue < vehicleValue then
|
|
|
|
career_vehicleSaveSystem.LoadVehicle(inventoryId)
|
|
|
|
else
|
|
|
|
log('I', 'retrieval', 'retrieving vehicle ' .. inventoryId .. " in an undamaged state")
|
|
|
|
end
|
2025-03-06 17:34:31 +00:00
|
|
|
freeroam_facilities.teleportToGarage(garage.id, veh, false)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end)
|
2025-02-02 18:07:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function onComputerAddFunctions(menuData, computerFunctions)
|
|
|
|
if menuData.computerFacility.functions["vehicleInventory"] then
|
2025-03-06 17:09:31 +00:00
|
|
|
local favouriteVehicleId = career_modules_inventory.getFavoriteVehicle()
|
|
|
|
|
2025-02-02 18:07:50 +00:00
|
|
|
local computerFunctionData = {
|
|
|
|
id = "retrieve_damaged",
|
|
|
|
label = "Retrieve Favourite Damaged",
|
2025-03-06 17:09:31 +00:00
|
|
|
callback = function() Retrieve(favouriteVehicleId) end,
|
2025-02-02 18:07:50 +00:00
|
|
|
order = 1
|
|
|
|
}
|
2025-03-06 17:09:31 +00:00
|
|
|
|
2025-03-06 17:10:38 +00:00
|
|
|
local repairPermission = career_modules_permissions.getStatusForTag("vehicleRepair",
|
|
|
|
{ inventoryId = favouriteVehicleId })
|
|
|
|
|
|
|
|
if not repairPermission["allow"] then
|
|
|
|
computerFunctionData.disabled = true
|
|
|
|
computerFunctionData.reason = { type = "text", label = "Vehicle is being repaired." }
|
|
|
|
end
|
|
|
|
|
2025-02-02 18:07:50 +00:00
|
|
|
if menuData.tutorialPartShoppingActive or menuData.tutorialTuningActive then
|
|
|
|
computerFunctionData.disabled = true
|
|
|
|
computerFunctionData.reason = career_modules_computer.reasons.tutorialActive
|
|
|
|
end
|
|
|
|
computerFunctions.general[computerFunctionData.id] = computerFunctionData
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-03-04 19:31:07 +00:00
|
|
|
local function RemoveVehicleObject(inventoryId)
|
|
|
|
table.insert(vehicleObjectsToRemove, inventoryId)
|
|
|
|
career_vehicleSaveSystem.QueueVehicleToSave(inventoryId)
|
|
|
|
career_vehicleSaveSystem.SaveVehicle(inventoryId)
|
|
|
|
career_vehicleSaveSystem.CheckSavedAsync(function()
|
|
|
|
career_modules_inventory_removeVehicleObject(inventoryId)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onCareerActive()
|
|
|
|
career_modules_inventory_removeVehicleObject = career_modules_inventory.removeVehicleObject
|
|
|
|
career_modules_inventory.removeVehicleObject = RemoveVehicleObject
|
2025-02-02 18:07:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.onComputerAddFunctions = onComputerAddFunctions
|
2025-03-04 19:31:07 +00:00
|
|
|
M.onCareerActive = onCareerActive
|
2025-02-02 18:07:50 +00:00
|
|
|
|
|
|
|
return M
|