1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-11 23:50:29 +01:00

Added Directed property and set all initial bool properties to false. Refactored Dismiss function.

This commit is contained in:
Rich Dunne 2020-09-20 12:56:06 -06:00
parent 4b4f596024
commit 64587347d7

View file

@ -10,9 +10,10 @@ namespace SceneManager
internal Path Path { get; set; } internal Path Path { get; set; }
internal Waypoint CurrentWaypoint { get; set; } internal Waypoint CurrentWaypoint { get; set; }
internal Waypoint NextWaypoint { get; private set; } internal Waypoint NextWaypoint { get; private set; }
internal bool StoppedAtWaypoint { get; set; } internal bool StoppedAtWaypoint { get; set; } = false;
internal bool Dismissed { get; set; } internal bool Dismissed { get; set; } = false;
internal bool SkipWaypoint { get; set; } internal bool Directed { get; set; } = false;
internal bool SkipWaypoint { get; set; } = false;
internal CollectedVehicle(Vehicle vehicle, Path path, Waypoint currentWaypoint) internal CollectedVehicle(Vehicle vehicle, Path path, Waypoint currentWaypoint)
{ {
@ -29,34 +30,56 @@ namespace SceneManager
Path = path; Path = path;
} }
internal void Dismiss() internal void Dismiss(DismissOption dismissOption = DismissOption.FromPath)
{
GameFiber.StartNew(() =>
{ {
if (!Vehicle || !Driver) if (!Vehicle || !Driver)
{ {
return; return;
} }
Dismissed = true;
StoppedAtWaypoint = false;
Driver.Tasks.Clear(); if (dismissOption == DismissOption.FromWorld)
Driver.Tasks.PerformDrivingManeuver(Vehicle, VehicleManeuver.GoForwardWithCustomSteeringAngle, 3);
if (Driver.GetAttachedBlip())
{ {
Driver.GetAttachedBlip().Delete(); Game.LogTrivial($"Dismissed {Vehicle.Model.Name} from the world");
Vehicle.Driver.Delete();
Vehicle.Delete();
return;
} }
// check if the vehicle is near any of the path's collector waypoints Dismissed = true;
var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector && Vehicle.DistanceTo2D(wp.Position) <= wp.CollectorRadius * 2).FirstOrDefault(); Dismissed = false;
if (nearestCollectorWaypoint != null) Driver.Tasks.Clear();
if(StoppedAtWaypoint)
{ {
while (nearestCollectorWaypoint != null && Vehicle && Driver && Vehicle.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius * 2) Logger.Log($"Unstucking stopped vehicle");
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Vehicle, 0f, 1, true);
GameFiber.StartNew(() =>
{
while(Vehicle.Speed < 1f)
{ {
//Game.LogTrivial($"{_vehicle.Model.Name} is too close to the collector to be fully dismissed.");
GameFiber.Yield(); GameFiber.Yield();
} }
});
StoppedAtWaypoint = false;
}
if(dismissOption == DismissOption.FromWaypoint && CurrentWaypoint.Number != Path.Waypoints.Count)
{
Logger.Log($"Dismissed from waypoint.");
SkipWaypoint = true;
SkipWaypoint = false;
}
if(dismissOption == DismissOption.FromWaypoint && CurrentWaypoint.Number == Path.Waypoints.Count || dismissOption == DismissOption.FromPath)
{
Logger.Log($"Dismissed from path.");
GameFiber.StartNew(() =>
{
// check if the vehicle is near any of the path's collector waypoints
var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector && Vehicle.DistanceTo2D(wp.Position) <= wp.CollectorRadius * 2).FirstOrDefault();
while (nearestCollectorWaypoint != null && Vehicle && Driver && Vehicle.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius * 2)
{
//Game.LogTrivial($"{Vehicle.Model.Name} is too close to the collector to be fully dismissed.");
GameFiber.Yield();
} }
if (!Vehicle || !Driver) if (!Vehicle || !Driver)
@ -66,6 +89,10 @@ namespace SceneManager
VehicleCollector.collectedVehicles.Remove(this); VehicleCollector.collectedVehicles.Remove(this);
Logger.Log($"{Vehicle.Model.Name} dismissed successfully."); Logger.Log($"{Vehicle.Model.Name} dismissed successfully.");
if (Driver.GetAttachedBlip())
{
Driver.GetAttachedBlip().Delete();
}
Driver.BlockPermanentEvents = false; Driver.BlockPermanentEvents = false;
Driver.Dismiss(); Driver.Dismiss();
Vehicle.IsSirenOn = false; Vehicle.IsSirenOn = false;
@ -74,4 +101,5 @@ namespace SceneManager
}); });
} }
} }
}
} }