Files
reallife-gamemode/ReallifeGamemode.Server.Core/Managers/VehicleManager.cs
2020-03-12 19:19:42 +01:00

60 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using ReallifeGamemode.Server.Core.API;
using ReallifeGamemode.Server.Types;
using ReallifeGamemode.Server.Common;
namespace ReallifeGamemode.Server.Core.Managers
{
internal class VehicleManager : Script
{
private const string DataKey = "VehicleData";
public VehicleManager()
{
}
public void SetEngineState(IVehicle veh, bool state)
{
var data = GetData(veh);
data.EngineState = state;
SetData(veh, data);
}
public bool GetEngineState(IVehicle veh)
{
return GetData(veh).EngineState;
}
public void SetLocked(IVehicle veh, bool state)
{
var data = GetData(veh);
data.Locked = state;
SetData(veh, data);
}
public bool IsLocked(IVehicle veh)
{
return GetData(veh).Locked;
}
public VehicleData GetData(IVehicle veh)
{
return veh.GetSharedData(DataKey, new VehicleData());
}
public void SetData(IVehicle veh, VehicleData data)
{
if (data is null)
{
throw new ArgumentNullException(nameof(data));
}
veh.SetSharedData(DataKey, data);
Api.TriggerClientEventForAll("Vehicle:UpdateData", veh.Handle, data.SerializeJson());
}
}
}