100 lines
3.1 KiB
C#
100 lines
3.1 KiB
C#
using GTANetworkAPI;
|
|
using reallife_gamemode.Model;
|
|
using reallife_gamemode.Server.Entities;
|
|
using reallife_gamemode.Server.Extensions;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace reallife_gamemode.Server.Managers
|
|
{
|
|
class TuningManager : Script
|
|
{
|
|
private static List<ColShape> tuningGarages = new List<ColShape>();
|
|
|
|
/// <summary>
|
|
/// Fügt eine Tuning-Garage zum Spiel hinzu
|
|
/// </summary>
|
|
/// <param name="pos">Die Position der Garage</param>
|
|
public static void AddTuningGarage(Vector3 pos)
|
|
{
|
|
ColShape colShape = NAPI.ColShape.CreateSphereColShape(pos, 10, 0);
|
|
|
|
colShape.OnEntityEnterColShape += (cs, c) =>
|
|
{
|
|
if(c.IsInVehicle)
|
|
{
|
|
Vehicle v = c.Vehicle;
|
|
if(v.GetServerVehicle() is FactionVehicle fV && fV.GetFaction().StateOwned)
|
|
{
|
|
return;
|
|
}
|
|
c.TriggerEvent("showTuningInfo");
|
|
}
|
|
};
|
|
|
|
colShape.OnEntityExitColShape += (cs, c) =>
|
|
{
|
|
c.TriggerEvent("hideTuningInfo", true);
|
|
};
|
|
|
|
tuningGarages.Add(colShape);
|
|
}
|
|
|
|
public static void ApplyTuningToServerVehicle(ServerVehicle sVeh)
|
|
{
|
|
Vehicle veh = VehicleManager.GetVehicleFromServerVehicle(sVeh);
|
|
if (veh == null) return;
|
|
|
|
using(var dbContext = new DatabaseContext())
|
|
{
|
|
foreach(VehicleMod vMod in dbContext.VehicleMods.ToList().FindAll(vM => vM.ServerVehicleId == sVeh.Id))
|
|
{
|
|
veh.SetMod(vMod.Slot, vMod.ModId - 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
[RemoteEvent("startPlayerTuning")]
|
|
public void StartPlayerTuning(Client player)
|
|
{
|
|
if (!player.IsInVehicle) return;
|
|
|
|
player.TriggerEvent("showTuningMenu");
|
|
}
|
|
|
|
[RemoteEvent("setVehicleMod")]
|
|
public void SetVehicleMod(Client player, int slot, int index)
|
|
{
|
|
if (index == 0) index--;
|
|
player.Vehicle.SetMod(slot, index - 1);
|
|
|
|
ServerVehicle sV = player.Vehicle.GetServerVehicle();
|
|
if (sV == null) return;
|
|
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
VehicleMod vMod = dbContext.VehicleMods.FirstOrDefault(m => m.ServerVehicleId == sV.Id && m.Slot == slot);
|
|
if(vMod == null && index != -1)
|
|
{
|
|
vMod = new VehicleMod
|
|
{
|
|
ServerVehicleId = sV.Id,
|
|
Slot = slot,
|
|
ModId = index
|
|
};
|
|
dbContext.VehicleMods.Add(vMod);
|
|
}
|
|
else if(vMod != null && index == -1)
|
|
{
|
|
dbContext.VehicleMods.Remove(vMod);
|
|
}
|
|
else
|
|
{
|
|
vMod.ModId = index;
|
|
}
|
|
dbContext.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|