mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-11 15:40:29 +01:00
146 lines
4.9 KiB
C#
146 lines
4.9 KiB
C#
using Rage;
|
|
using System.Linq;
|
|
|
|
namespace SceneManager
|
|
{
|
|
public class CollectedVehicle
|
|
{
|
|
internal Ped Driver { get; set; }
|
|
internal Vehicle Vehicle { get; set; }
|
|
internal Path Path { get; set; }
|
|
internal Waypoint CurrentWaypoint { get; set; }
|
|
internal Waypoint NextWaypoint { get; private set; }
|
|
internal bool StoppedAtWaypoint { get; set; } = false;
|
|
internal bool Dismissed { get; set; } = false;
|
|
internal bool Directed { get; set; } = false;
|
|
internal bool SkipWaypoint { get; set; } = false;
|
|
|
|
internal CollectedVehicle(Vehicle vehicle, Path path, Waypoint currentWaypoint)
|
|
{
|
|
Vehicle = vehicle;
|
|
Driver = vehicle.Driver;
|
|
Path = path;
|
|
CurrentWaypoint = currentWaypoint;
|
|
SetPersistence();
|
|
}
|
|
|
|
internal CollectedVehicle(Vehicle vehicle, Path path)
|
|
{
|
|
Vehicle = vehicle;
|
|
Driver = vehicle.Driver;
|
|
Path = path;
|
|
SetPersistence();
|
|
}
|
|
|
|
internal void SetPersistence()
|
|
{
|
|
Vehicle.IsPersistent = true;
|
|
Driver.IsPersistent = true;
|
|
Logger.Log($"{Vehicle.Model.Name} and driver are now persistent.");
|
|
}
|
|
|
|
internal void Dismiss(DismissOption dismissOption = DismissOption.FromPath)
|
|
{
|
|
if (!Vehicle || !Driver)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (dismissOption == DismissOption.FromWorld)
|
|
{
|
|
DismissFromWorld();
|
|
return;
|
|
}
|
|
|
|
Driver.Tasks.Clear();
|
|
if(StoppedAtWaypoint)
|
|
{
|
|
Logger.Log($"Unstucking {Vehicle.Model.Name}");
|
|
StoppedAtWaypoint = false;
|
|
}
|
|
|
|
if(dismissOption == DismissOption.FromWaypoint)
|
|
{
|
|
DismissFromWaypoint();
|
|
}
|
|
|
|
if(dismissOption == DismissOption.FromPath)
|
|
{
|
|
DismissFromPath();
|
|
}
|
|
|
|
void DismissFromWorld()
|
|
{
|
|
Game.LogTrivial($"Dismissed {Vehicle.Model.Name} from the world");
|
|
while (Vehicle.HasOccupants)
|
|
{
|
|
foreach (Ped occupant in Vehicle.Occupants)
|
|
{
|
|
occupant.Dismiss();
|
|
occupant.Delete();
|
|
}
|
|
GameFiber.Yield();
|
|
}
|
|
Vehicle.Delete();
|
|
}
|
|
|
|
void DismissFromWaypoint()
|
|
{
|
|
if (CurrentWaypoint == null || Path == null)
|
|
{
|
|
Logger.Log($"CurrentWaypoint or Path are null");
|
|
}
|
|
else if (CurrentWaypoint?.Number != Path?.Waypoints.Count)
|
|
{
|
|
Logger.Log($"Dismissed from waypoint.");
|
|
SkipWaypoint = true;
|
|
}
|
|
else if (CurrentWaypoint?.Number == Path?.Waypoints.Count)
|
|
{
|
|
DismissFromPath();
|
|
}
|
|
}
|
|
|
|
void DismissFromPath()
|
|
{
|
|
Logger.Log($"Dismissing from path");
|
|
Dismissed = true;
|
|
GameFiber.StartNew(() =>
|
|
{
|
|
// check if the vehicle is near any of the path's collector waypoints
|
|
var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector).OrderBy(wp => Vehicle.DistanceTo2D(wp.Position)).FirstOrDefault();
|
|
if(nearestCollectorWaypoint != null)
|
|
{
|
|
while (nearestCollectorWaypoint != null && Vehicle && Driver && Vehicle.FrontPosition.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius)
|
|
{
|
|
//Game.LogTrivial($"{Vehicle.Model.Name} is within 2x collector radius, cannot be fully dismissed yet.");
|
|
GameFiber.Yield();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Logger.Log($"Nearest collector is null");
|
|
}
|
|
|
|
|
|
if (!Vehicle || !Driver)
|
|
{
|
|
return;
|
|
}
|
|
|
|
VehicleCollector.collectedVehicles.Remove(this);
|
|
Logger.Log($"{Vehicle.Model.Name} dismissed successfully.");
|
|
if (Driver.GetAttachedBlip())
|
|
{
|
|
Driver.GetAttachedBlip().Delete();
|
|
}
|
|
Driver.BlockPermanentEvents = false;
|
|
Driver.Dismiss();
|
|
Vehicle.IsSirenOn = false;
|
|
Vehicle.IsSirenSilent = true;
|
|
Vehicle.Dismiss();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|