Add changes
This commit is contained in:
59
ReallifeGamemode.Server.Core/Managers/VehicleManager.cs
Normal file
59
ReallifeGamemode.Server.Core/Managers/VehicleManager.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user