mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-12 08:00:30 +01:00
Merge V2.1.1 release (#3)
* Mouse can now be used to fully navigate menus * Added check for driver's current vehicle when releasing from Stop waypoint in case the ped is not in a vehicle. * Lines are now only drawn between waypoint markers under the same conditions that waypoint markers are drawn * Updated marker position to be player's mouse position * Version update * Added logic to update waypoint position during driving task if the waypoint position was changed before the driver arrived. * Removed unused usings. Refactored debug statements to use Game.LogTrivial instead of Logger.Log * Removed class * Removed Logger class * Consolidated all custom enums to this class. Added default waypoint settings from .ini * Modified a hint message * Fixed collector options not being enabled/disabled when Collector box is checked * Refactored AITasking into CollectedVehicle. * Updated reference to vehicle tasking based on AITasking refactor. Fixed speed zone radius not updating correctly. * Version update * Refactored AITasking into CollectedVehicle * Added check for CollectorRadius being more than SpeedZoneRadius. Added debug messages when values are reset to default. * Added hint message if player tries to edit waypoints while 3D waypoints are disabled * Fixed a bug where a 3D waypoint marker would be drawn even if 3D waypoints were disabled * Removed unnecessary property setting when a vehicle is being removed from a path. * Added a check for if the driver loses their task and reassigns it. * Fixed a bug where the 3D line between waypoints was still being drawn even though 3D waypoints were disabled in the settings menu. * Updated version * Added console command to show info about collected vehicles. * Added ConsoleCommand class, removed AITasking class. * Removed class after refactoring into CollectedVehicle * Update README.md * Update README.md * Added ini setting for Advanced Barrier Options. Added enum for TrafficLight state. Added debug message for invalid barriers. * Updated version * Added MousePositionInWorld and RNUIMouseInputHandler classes * Fixed a crash when a collected ped is arrested. * Refactored to implement RNUIMouseInputHandler class. * Removed unused method. * Updated version * Disabled deletion/creation of shadow barrier and re-enabled updating position based on mouse position. * Added check for Driver's current vehicle in driving loop in case the Driver exited Vehicle at some point. Adjusted some guard clause logic and log messages. * Removed unused variable * Renamed some methods to improve clarity * Updated version.
This commit is contained in:
parent
d73ae601e7
commit
8bc4de3528
21 changed files with 1818 additions and 1083 deletions
|
|
@ -1,20 +1,21 @@
|
|||
using Rage;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SceneManager
|
||||
{
|
||||
internal class CollectedVehicle
|
||||
{
|
||||
internal Ped Driver { get; set; }
|
||||
internal Vehicle Vehicle { get; set; }
|
||||
internal Path Path { get; set; }
|
||||
internal Waypoint CurrentWaypoint { get; set; }
|
||||
internal Ped Driver { get; private set; }
|
||||
internal Vehicle Vehicle { get; private set; }
|
||||
internal Path Path { get; private set; }
|
||||
internal Waypoint CurrentWaypoint { get; private set; }
|
||||
internal Waypoint NextWaypoint { get; private set; }
|
||||
internal bool StoppedAtWaypoint { get; set; } = false;
|
||||
internal bool Dismissed { get; set; } = false;
|
||||
internal bool StoppedAtWaypoint { get; private set; } = false;
|
||||
internal bool Dismissed { get; private set; } = false;
|
||||
internal bool Directed { get; set; } = false;
|
||||
internal bool SkipWaypoint { get; set; } = false;
|
||||
internal bool ReadyForDirectTasks { get; set; } = true;
|
||||
internal bool SkipWaypoint { get; private set; } = false;
|
||||
internal bool ReadyForDirectTasks { get; private set; } = true;
|
||||
|
||||
internal CollectedVehicle(Vehicle vehicle, Path path, Waypoint currentWaypoint)
|
||||
{
|
||||
|
|
@ -33,12 +34,264 @@ namespace SceneManager
|
|||
SetPersistence();
|
||||
}
|
||||
|
||||
internal void SetPersistence()
|
||||
private void SetPersistence()
|
||||
{
|
||||
Vehicle.IsPersistent = true;
|
||||
Driver.IsPersistent = true;
|
||||
Driver.BlockPermanentEvents = true;
|
||||
//Logger.Log($"{Vehicle.Model.Name} and driver are now persistent.");
|
||||
}
|
||||
|
||||
internal void AssignWaypointTasks(Path path, Waypoint currentWaypoint)
|
||||
{
|
||||
// Driving styles https://gtaforums.com/topic/822314-guide-driving-styles/
|
||||
// also https://vespura.com/fivem/drivingstyle/
|
||||
|
||||
if (!VehicleAndDriverAreValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AssignPathAndCurrentWaypoint();
|
||||
|
||||
AssignDirectedTask();
|
||||
|
||||
if (currentWaypoint.IsStopWaypoint)
|
||||
{
|
||||
StopAtWaypoint();
|
||||
}
|
||||
if (path?.Waypoints?.Count > 0 && currentWaypoint != path?.Waypoints?.Last())
|
||||
{
|
||||
DriveToNextWaypoint();
|
||||
}
|
||||
|
||||
if (!VehicleAndDriverAreValid() || Directed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] all Path {path.Number} tasks complete.");
|
||||
if (!Dismissed)
|
||||
{
|
||||
Dismiss();
|
||||
}
|
||||
|
||||
void AssignPathAndCurrentWaypoint()
|
||||
{
|
||||
Path = path;
|
||||
if (currentWaypoint != null)
|
||||
{
|
||||
CurrentWaypoint = currentWaypoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentWaypoint = path.Waypoints[0];
|
||||
}
|
||||
}
|
||||
|
||||
void AssignDirectedTask()
|
||||
{
|
||||
if (currentWaypoint != null && Directed)
|
||||
{
|
||||
Dismissed = false;
|
||||
|
||||
while (!ReadyForDirectTasks)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
if (!VehicleAndDriverAreValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Driver.Tasks.Clear();
|
||||
DriveToDirectedWaypoint();
|
||||
}
|
||||
}
|
||||
|
||||
void DriveToDirectedWaypoint()
|
||||
{
|
||||
Dismissed = false;
|
||||
|
||||
while (!ReadyForDirectTasks)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
Driver.Tasks.Clear();
|
||||
AssignTasksForDirectedDriver();
|
||||
|
||||
void AssignTasksForDirectedDriver()
|
||||
{
|
||||
float acceptedDistance = GetAcceptedStoppingDistance(Path.Waypoints, Path.Waypoints.IndexOf(currentWaypoint));
|
||||
Vector3 oldPosition = currentWaypoint.Position;
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] is driving to path {currentWaypoint.Path.Number} waypoint {currentWaypoint.Number} (directed)");
|
||||
Driver.Tasks.DriveToPosition(currentWaypoint.Position, currentWaypoint.Speed, (VehicleDrivingFlags)currentWaypoint.DrivingFlagType, acceptedDistance);
|
||||
LoopWhileDrivingToDirectedWaypoint();
|
||||
|
||||
void LoopWhileDrivingToDirectedWaypoint()
|
||||
{
|
||||
while (VehicleAndDriverAreValid() && !Dismissed && !SkipWaypoint && Vehicle.FrontPosition.DistanceTo2D(oldPosition) > acceptedDistance)
|
||||
{
|
||||
if (oldPosition != currentWaypoint.Position)
|
||||
{
|
||||
oldPosition = currentWaypoint.Position;
|
||||
}
|
||||
GameFiber.Yield();
|
||||
}
|
||||
if (Vehicle)
|
||||
{
|
||||
Driver.Tasks.PerformDrivingManeuver(Vehicle, VehicleManeuver.GoForwardWithCustomSteeringAngle, 3).WaitForCompletion();
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] directed task is complete, directed is now false");
|
||||
}
|
||||
Directed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DriveToNextWaypoint()
|
||||
{
|
||||
if (!VehicleAndDriverAreValid() || CurrentWaypoint == null || Path == null)
|
||||
{
|
||||
Game.LogTrivial($"Vehicle, driver, waypoint, or path is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
Game.LogTrivial($"Preparing to run task loop for {Vehicle.Model.Name} [{Vehicle.Handle}] on path {Path.Number}");
|
||||
for (int currentWaypointTask = CurrentWaypoint.Number; currentWaypointTask < Path.Waypoints.Count; currentWaypointTask++)
|
||||
{
|
||||
var oldPosition = Path.Waypoints[currentWaypointTask].Position;
|
||||
SkipWaypoint = false;
|
||||
|
||||
if (this == null || !Vehicle || Dismissed || Directed)
|
||||
{
|
||||
Game.LogTrivial($"Vehicle dismissed, directed, or null, return");
|
||||
return;
|
||||
}
|
||||
if (Driver == null || !Driver || !Vehicle.HasDriver || !Driver.IsAlive || Vehicle.Driver == Game.LocalPlayer.Character)
|
||||
{
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] does not have a driver/driver is null or driver is dead.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Path.Waypoints.ElementAtOrDefault(currentWaypointTask) != null && !StoppedAtWaypoint)
|
||||
{
|
||||
CurrentWaypoint = Path.Waypoints[currentWaypointTask];
|
||||
float acceptedDistance = GetAcceptedStoppingDistance(Path.Waypoints, currentWaypointTask);
|
||||
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] is driving to path {Path.Number} waypoint {Path.Waypoints[currentWaypointTask].Number} (Stop: {CurrentWaypoint.IsStopWaypoint}, Driving flag: {CurrentWaypoint.DrivingFlagType})");
|
||||
Driver.Tasks.DriveToPosition(Path.Waypoints[currentWaypointTask].Position, Path.Waypoints[currentWaypointTask].Speed, (VehicleDrivingFlags)Path.Waypoints[currentWaypointTask].DrivingFlagType, acceptedDistance);
|
||||
LoopWhileDrivingToWaypoint(currentWaypointTask, acceptedDistance, oldPosition);
|
||||
|
||||
if (!VehicleAndDriverAreValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (SkipWaypoint)
|
||||
{
|
||||
SkipWaypoint = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Dismissed && !Directed && Path.Waypoints.ElementAtOrDefault(currentWaypointTask) != null && Path.Waypoints[currentWaypointTask].IsStopWaypoint)
|
||||
{
|
||||
StopAtWaypoint();
|
||||
}
|
||||
|
||||
if (!VehicleAndDriverAreValid() || Dismissed || Directed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Driver.Tasks.PerformDrivingManeuver(Vehicle, VehicleManeuver.GoForwardWithCustomSteeringAngle, 3).WaitForCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
void LoopWhileDrivingToWaypoint(int currentWaypointTask, float acceptedDistance, Vector3 oldPosition)
|
||||
{
|
||||
while (VehicleAndDriverAreValid() && !Dismissed && !SkipWaypoint && !Directed && Path.Waypoints.ElementAtOrDefault(currentWaypointTask) != null && Vehicle.FrontPosition.DistanceTo2D(Path.Waypoints[currentWaypointTask].Position) > acceptedDistance)
|
||||
{
|
||||
if (oldPosition != Path.Waypoints[currentWaypointTask].Position)
|
||||
{
|
||||
oldPosition = Path.Waypoints[currentWaypointTask].Position;
|
||||
Driver.Tasks.DriveToPosition(Path.Waypoints[currentWaypointTask].Position, Path.Waypoints[currentWaypointTask].Speed, (VehicleDrivingFlags)Path.Waypoints[currentWaypointTask].DrivingFlagType, acceptedDistance);
|
||||
}
|
||||
if(Driver.Tasks.CurrentTaskStatus == TaskStatus.NoTask)
|
||||
{
|
||||
//Game.DisplayNotification($"~o~Scene Manager ~r~[Error]\n{Vehicle.Model.Name} [{Vehicle.Handle}] driver [{Driver.Handle}] has no task. Reassiging current waypoint task.");
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] driver [{Driver.Handle}] has no task. Reassiging current waypoint task.");
|
||||
if (Driver.CurrentVehicle)
|
||||
{
|
||||
Driver.Tasks.DriveToPosition(Path.Waypoints[currentWaypointTask].Position, Path.Waypoints[currentWaypointTask].Speed, (VehicleDrivingFlags)Path.Waypoints[currentWaypointTask].DrivingFlagType, acceptedDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] driver [{Driver.Handle}] is not in a vehicle. Exiting loop.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
GameFiber.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float GetAcceptedStoppingDistance(List<Waypoint> waypoints, int nextWaypoint)
|
||||
{
|
||||
float dist;
|
||||
if (Settings.SpeedUnit == SpeedUnits.MPH)
|
||||
{
|
||||
dist = (MathHelper.ConvertMilesPerHourToKilometersPerHour(waypoints[nextWaypoint].Speed) * MathHelper.ConvertMilesPerHourToKilometersPerHour(waypoints[nextWaypoint].Speed)) / (250 * 0.8f);
|
||||
}
|
||||
else
|
||||
{
|
||||
dist = (waypoints[nextWaypoint].Speed * waypoints[nextWaypoint].Speed) / (250 * 0.8f);
|
||||
}
|
||||
var acceptedDistance = MathHelper.Clamp(dist, 2, 10);
|
||||
return acceptedDistance;
|
||||
}
|
||||
|
||||
void StopAtWaypoint()
|
||||
{
|
||||
if (!VehicleAndDriverAreValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var stoppingDistance = GetAcceptedStoppingDistance(currentWaypoint.Path.Waypoints, currentWaypoint.Path.Waypoints.IndexOf(currentWaypoint));
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} stopping at path {currentWaypoint.Path.Number} waypoint.");
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Vehicle, stoppingDistance, -1, true);
|
||||
StoppedAtWaypoint = true;
|
||||
|
||||
while (currentWaypoint != null && VehicleAndDriverAreValid() && StoppedAtWaypoint && !Directed)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
if (Driver && Driver.CurrentVehicle)
|
||||
{
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} releasing from stop waypoint.");
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Vehicle, 0f, 1, true);
|
||||
Driver.Tasks.CruiseWithVehicle(5f);
|
||||
}
|
||||
}
|
||||
|
||||
bool VehicleAndDriverAreValid()
|
||||
{
|
||||
if (this == null)
|
||||
{
|
||||
Game.LogTrivial($"CollectedVehicle is null");
|
||||
return false;
|
||||
}
|
||||
if (!Vehicle && !Dismissed)
|
||||
{
|
||||
Game.LogTrivial($"Vehicle is null");
|
||||
Dismiss();
|
||||
return false;
|
||||
}
|
||||
if (!Driver || !Driver.IsAlive)
|
||||
{
|
||||
Dismiss();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal void Dismiss(DismissOption dismissOption = DismissOption.FromPath, Path newPath = null)
|
||||
|
|
@ -64,18 +317,20 @@ namespace SceneManager
|
|||
if (Vehicle)
|
||||
{
|
||||
Vehicle.Dismiss();
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Vehicle, 0f, 1, true);
|
||||
}
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Vehicle, 0f, 1, true);
|
||||
Path.CollectedVehicles.Remove(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if(StoppedAtWaypoint)
|
||||
if(Vehicle && StoppedAtWaypoint)
|
||||
{
|
||||
//Logger.Log($"Unstucking {Vehicle.Model.Name}");
|
||||
StoppedAtWaypoint = false;
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Vehicle, 0f, 1, true);
|
||||
Driver.Tasks.CruiseWithVehicle(5f);
|
||||
Rage.Native.NativeFunction.Natives.x260BE8F09E326A20(Driver.CurrentVehicle, 0f, 1, true);
|
||||
if (Driver?.CurrentVehicle)
|
||||
{
|
||||
Driver.Tasks.CruiseWithVehicle(5f);
|
||||
}
|
||||
}
|
||||
Driver.Tasks.Clear();
|
||||
|
||||
|
|
@ -96,7 +351,7 @@ namespace SceneManager
|
|||
|
||||
void DismissFromWorld()
|
||||
{
|
||||
Game.LogTrivial($"Dismissed {Vehicle.Model.Name} from the world");
|
||||
Game.LogTrivial($"Dismissed {Vehicle.Model.Name} [{Vehicle.Handle}] from the world");
|
||||
while (Vehicle.HasOccupants)
|
||||
{
|
||||
foreach (Ped occupant in Vehicle.Occupants)
|
||||
|
|
@ -113,11 +368,13 @@ namespace SceneManager
|
|||
{
|
||||
if (CurrentWaypoint == null || Path == null)
|
||||
{
|
||||
Logger.Log($"CurrentWaypoint or Path are null");
|
||||
Game.LogTrivial($"CurrentWaypoint or Path is null");
|
||||
return;
|
||||
}
|
||||
else if (CurrentWaypoint?.Number != Path?.Waypoints.Count)
|
||||
|
||||
if (CurrentWaypoint?.Number != Path?.Waypoints.Count)
|
||||
{
|
||||
Logger.Log($"Dismissed from waypoint.");
|
||||
Game.LogTrivial($"{Vehicle?.Model.Name} [{Vehicle?.Handle}] dismissed from waypoint.");
|
||||
SkipWaypoint = true;
|
||||
}
|
||||
else if (CurrentWaypoint?.Number == Path?.Waypoints.Count)
|
||||
|
|
@ -128,36 +385,35 @@ namespace SceneManager
|
|||
|
||||
void DismissFromPath()
|
||||
{
|
||||
Logger.Log($"Dismissing from path");
|
||||
Game.LogTrivial($"Dismissing {Vehicle?.Model.Name} [{Vehicle?.Handle}] from path");
|
||||
Dismissed = true;
|
||||
|
||||
// Check if the vehicle is near any of the path's collector waypoints
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
var nearestCollectorWaypoint = Path.Waypoints.Where(wp => wp.IsCollector).OrderBy(wp => Vehicle.DistanceTo2D(wp.Position)).FirstOrDefault();
|
||||
if (nearestCollectorWaypoint != null)
|
||||
if(nearestCollectorWaypoint == null)
|
||||
{
|
||||
// Enabling this will keep the menu, but the dismissed vehicle is immediately re - collected
|
||||
while (nearestCollectorWaypoint != null && Vehicle && Vehicle.HasDriver && Driver && Driver.IsAlive && Vehicle.FrontPosition.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius)
|
||||
{
|
||||
//Game.LogTrivial($"{Vehicle.Model.Name} is within 2x collector radius, cannot be fully dismissed yet.");
|
||||
GameFiber.Yield();
|
||||
}
|
||||
Game.LogTrivial($"Nearest collector is null");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log($"Nearest collector is null");
|
||||
while (nearestCollectorWaypoint != null && Vehicle && Vehicle.HasDriver && Driver && Driver.IsAlive && Vehicle.FrontPosition.DistanceTo2D(nearestCollectorWaypoint.Position) <= nearestCollectorWaypoint.CollectorRadius)
|
||||
{
|
||||
GameFiber.Yield();
|
||||
}
|
||||
}
|
||||
|
||||
if (!Vehicle || !Driver)
|
||||
{
|
||||
Game.LogTrivial($"Vehicle or driver is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Directed)
|
||||
{
|
||||
Path.CollectedVehicles.Remove(this);
|
||||
Logger.Log($"{Vehicle.Model.Name} dismissed successfully.");
|
||||
Game.LogTrivial($"{Vehicle.Model.Name} [{Vehicle.Handle}] dismissed successfully.");
|
||||
if (Driver)
|
||||
{
|
||||
if (Driver.GetAttachedBlip())
|
||||
|
|
@ -169,12 +425,12 @@ namespace SceneManager
|
|||
}
|
||||
if (Vehicle)
|
||||
{
|
||||
Vehicle.Dismiss();
|
||||
Vehicle.IsSirenOn = false;
|
||||
Vehicle.IsSirenSilent = true;
|
||||
Vehicle.Dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}, "DismissFromPath Fiber");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,9 +81,9 @@ namespace SceneManager
|
|||
{
|
||||
GameFiber.StartNew(() =>
|
||||
{
|
||||
while (SettingsMenu.threeDWaypoints.Checked)
|
||||
while(true)
|
||||
{
|
||||
if (MenuManager.menuPool.IsAnyMenuOpen())
|
||||
if (SettingsMenu.threeDWaypoints.Checked && (State == State.Finished && MenuManager.menuPool.IsAnyMenuOpen()) || (State == State.Creating && PathCreationMenu.pathCreationMenu.Visible))
|
||||
{
|
||||
for (int i = 0; i < Waypoints.Count; i++)
|
||||
{
|
||||
|
|
@ -133,7 +133,6 @@ namespace SceneManager
|
|||
internal void LoopWaypointCollection()
|
||||
{
|
||||
uint lastProcessTime = Game.GameTime; // Store the last time the full loop finished; this is a value in ms
|
||||
int timeBetweenChecks = 1000; // How many ms to wait between outer loops
|
||||
int yieldAfterChecks = 50; // How many calculations to do before yielding
|
||||
while (PathMainMenu.paths.Contains(this))
|
||||
{
|
||||
|
|
@ -148,10 +147,11 @@ namespace SceneManager
|
|||
{
|
||||
foreach (Vehicle v in World.GetAllVehicles())
|
||||
{
|
||||
if (IsNearWaypoint(v, waypoint) && IsValidForCollection(v))
|
||||
if (VehicleIsNearWaypoint(v, waypoint) && VehicleIsValidForCollection(v))
|
||||
{
|
||||
CollectedVehicle newCollectedVehicle = AddVehicleToCollection(v);
|
||||
GameFiber AssignTasksFiber = new GameFiber(() => AITasking.AssignWaypointTasks(newCollectedVehicle, this, waypoint));
|
||||
GameFiber AssignTasksFiber = new GameFiber(() => newCollectedVehicle.AssignWaypointTasks(this, waypoint));
|
||||
//GameFiber AssignTasksFiber = new GameFiber(() => AITasking.AssignWaypointTasks(newCollectedVehicle, this, waypoint));
|
||||
AssignTasksFiber.Start();
|
||||
}
|
||||
|
||||
|
|
@ -177,18 +177,18 @@ namespace SceneManager
|
|||
{
|
||||
var collectedVehicle = new CollectedVehicle(vehicle, this);
|
||||
CollectedVehicles.Add(collectedVehicle);
|
||||
Logger.Log($"Added {vehicle.Model.Name} to collection from path {Number} waypoint {1}.");
|
||||
Game.LogTrivial($"Added {vehicle.Model.Name} to collection from path {Number} waypoint {1}.");
|
||||
return collectedVehicle;
|
||||
}
|
||||
|
||||
bool IsNearWaypoint(Vehicle v, Waypoint wp)
|
||||
bool VehicleIsNearWaypoint(Vehicle v, Waypoint wp)
|
||||
{
|
||||
return v.FrontPosition.DistanceTo2D(wp.Position) <= wp.CollectorRadius && Math.Abs(wp.Position.Z - v.Position.Z) < 3;
|
||||
}
|
||||
|
||||
bool IsValidForCollection(Vehicle v)
|
||||
bool VehicleIsValidForCollection(Vehicle v)
|
||||
{
|
||||
if (v && v != Game.LocalPlayer.Character.CurrentVehicle && v != Game.LocalPlayer.Character.LastVehicle && (v.IsCar || v.IsBike || v.IsBicycle || v.IsQuadBike) && !v.IsSirenOn && v.IsEngineOn && v.IsOnAllWheels && v.Speed > 1 && !CollectedVehicles.Any(cv => cv?.Vehicle == v))
|
||||
if (v && v != Game.LocalPlayer.Character.LastVehicle && (v.IsCar || v.IsBike || v.IsBicycle || v.IsQuadBike) && !v.IsSirenOn && v.IsEngineOn && v.IsOnAllWheels && v.Speed > 1 && !CollectedVehicles.Any(cv => cv?.Vehicle == v))
|
||||
{
|
||||
var vehicleCollectedOnAnotherPath = PathMainMenu.paths.Any(p => p.Number != Number && p.CollectedVehicles.Any(cv => cv.Vehicle == v));
|
||||
if (vehicleCollectedOnAnotherPath)
|
||||
|
|
|
|||
|
|
@ -6,12 +6,6 @@ using System.Linq;
|
|||
|
||||
namespace SceneManager
|
||||
{
|
||||
public enum DrivingFlagType
|
||||
{
|
||||
Normal = 263075,
|
||||
Direct = 17040259
|
||||
}
|
||||
|
||||
public class Waypoint
|
||||
{
|
||||
internal Path Path { get; set; }
|
||||
|
|
@ -60,7 +54,7 @@ namespace SceneManager
|
|||
DrawWaypointMarker();
|
||||
}
|
||||
|
||||
internal void UpdateWaypoint(Waypoint currentWaypoint, DrivingFlagType drivingFlag, bool stopWaypoint, float speed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius, bool updateWaypointPositionChecked)
|
||||
internal void UpdateWaypoint(Waypoint currentWaypoint, Vector3 newWaypointPosition, DrivingFlagType drivingFlag, bool stopWaypoint, float speed, bool collectorWaypointChecked, float collectorRadius, float speedZoneRadius, bool updateWaypointPositionChecked)
|
||||
{
|
||||
if(IsStopWaypoint != stopWaypoint)
|
||||
{
|
||||
|
|
@ -71,7 +65,7 @@ namespace SceneManager
|
|||
UpdateCollectorOptions();
|
||||
if (updateWaypointPositionChecked)
|
||||
{
|
||||
UpdateWaypointPosition(Game.LocalPlayer.Character.Position);
|
||||
UpdateWaypointPosition();
|
||||
}
|
||||
|
||||
void UpdateIfStopWaypoint()
|
||||
|
|
@ -103,7 +97,7 @@ namespace SceneManager
|
|||
{
|
||||
IsCollector = true;
|
||||
RemoveSpeedZone();
|
||||
SpeedZone = World.AddSpeedZone(currentWaypoint.Position, SpeedZoneRadius, speed);
|
||||
SpeedZone = World.AddSpeedZone(currentWaypoint.Position, speedZoneRadius, speed);
|
||||
Blip.Color = Color.Blue;
|
||||
if (CollectorRadiusBlip)
|
||||
{
|
||||
|
|
@ -140,7 +134,7 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateWaypointPosition(Vector3 newWaypointPosition)
|
||||
void UpdateWaypointPosition()
|
||||
{
|
||||
Position = newWaypointPosition;
|
||||
RemoveSpeedZone();
|
||||
|
|
@ -199,27 +193,27 @@ namespace SceneManager
|
|||
{
|
||||
if (EditWaypointMenu.updateWaypointPosition.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, 1f, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, 1f, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, GetMousePositionInWorld(), 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, 1f, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, GetMousePositionInWorld(), 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, 1f, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, 2f, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, 2f, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, (float)EditWaypointMenu.changeCollectorRadius.Value * 2, 2f, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, (float)EditWaypointMenu.changeSpeedZoneRadius.Value * 2, 2f, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
else if (EditWaypointMenu.stopWaypointType.Checked)
|
||||
{
|
||||
if (EditWaypointMenu.updateWaypointPosition.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, GetMousePositionInWorld(), 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 2f, 255, 65, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, 1f, 1f, 2f, 255, 65, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EditWaypointMenu.updateWaypointPosition.Checked)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y, Game.LocalPlayer.Character.Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, GetMousePositionInWorld(), 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, 2f, 65, 255, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, 1f, 1f, 2f, 65, 255, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
}
|
||||
else if ((Path.State == State.Finished && MenuManager.menuPool.IsAnyMenuOpen()) || (Path.State == State.Creating && PathCreationMenu.pathCreationMenu.Visible))
|
||||
|
|
@ -231,16 +225,16 @@ namespace SceneManager
|
|||
}
|
||||
if (IsCollector)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, CollectorRadius * 2, CollectorRadius * 2, markerHeight, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, SpeedZoneRadius * 2, SpeedZoneRadius * 2, markerHeight, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, CollectorRadius * 2, CollectorRadius * 2, markerHeight, 80, 130, 255, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, SpeedZoneRadius * 2, SpeedZoneRadius * 2, markerHeight, 255, 185, 80, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
else if (IsStopWaypoint)
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, markerHeight, 255, 65, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, 1f, 1f, markerHeight, 255, 65, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position.X, Position.Y, Position.Z - 1, 0, 0, 0, 0, 0, 0, 1f, 1f, markerHeight, 65, 255, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, Position, 0, 0, 0, 0, 0, 0, 1f, 1f, markerHeight, 65, 255, 65, 100, false, false, 2, false, 0, 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -292,7 +286,7 @@ namespace SceneManager
|
|||
internal void CollectVehicles(List<Path> paths)
|
||||
{
|
||||
var sleepInterval = 1000;
|
||||
Logger.Log($"Starting collection loop on waypoint {Number}");
|
||||
Game.LogTrivial($"Starting collection loop on waypoint {Number}");
|
||||
while (paths.Contains(Path) && Path.Waypoints.Contains(this))
|
||||
{
|
||||
if (Path.IsEnabled && IsCollector)
|
||||
|
|
@ -309,7 +303,7 @@ namespace SceneManager
|
|||
if (collectedVehiclePlayerIsIn != null)
|
||||
{
|
||||
collectedVehiclePlayerIsIn.Dismiss(DismissOption.FromPlayer);
|
||||
Logger.Log($"Dismissed a collected vehicle the player was in.");
|
||||
Game.LogTrivial($"Dismissed a collected vehicle the player was in.");
|
||||
}
|
||||
GameFiber.Sleep(sleepInterval);
|
||||
}
|
||||
|
|
@ -327,8 +321,8 @@ namespace SceneManager
|
|||
if (collectedVehicle == null)
|
||||
{
|
||||
CollectedVehicle newCollectedVehicle = AddVehicleToCollection(vehicle);
|
||||
//Logger.Log($"Vehicle's front position distance to waypoint: {vehicle.FrontPosition.DistanceTo2D(waypoint.Position)}, collector radius: {waypoint.CollectorRadius}");
|
||||
GameFiber AssignTasksFiber = new GameFiber(() => AITasking.AssignWaypointTasks(newCollectedVehicle, Path, this));
|
||||
GameFiber AssignTasksFiber = new GameFiber(() => newCollectedVehicle.AssignWaypointTasks(Path, this));
|
||||
//GameFiber AssignTasksFiber = new GameFiber(() => AITasking.AssignWaypointTasks(newCollectedVehicle, Path, this));
|
||||
AssignTasksFiber.Start();
|
||||
}
|
||||
}
|
||||
|
|
@ -343,7 +337,7 @@ namespace SceneManager
|
|||
{
|
||||
var collectedVehicle = new CollectedVehicle(vehicle, Path, this);
|
||||
Path.CollectedVehicles.Add(collectedVehicle);
|
||||
Logger.Log($"Added {vehicle.Model.Name} to collection from path {Path.Number} waypoint {this.Number}.");
|
||||
Game.LogTrivial($"Added {vehicle.Model.Name} to collection from path {Path.Number} waypoint {this.Number}.");
|
||||
return collectedVehicle;
|
||||
}
|
||||
|
||||
|
|
@ -385,5 +379,36 @@ namespace SceneManager
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3 GetMousePositionInWorld()
|
||||
{
|
||||
HitResult TracePlayerView(float maxTraceDistance = 100f, TraceFlags flags = TraceFlags.IntersectWorld) => TracePlayerView2(out Vector3 v1, out Vector3 v2, maxTraceDistance, flags);
|
||||
|
||||
HitResult TracePlayerView2(out Vector3 start, out Vector3 end, float maxTraceDistance, TraceFlags flags)
|
||||
{
|
||||
Vector3 direction = GetPlayerLookingDirection(out start);
|
||||
end = start + (maxTraceDistance * direction);
|
||||
return World.TraceLine(start, end, flags);
|
||||
}
|
||||
|
||||
Vector3 GetPlayerLookingDirection(out Vector3 camPosition)
|
||||
{
|
||||
if (Camera.RenderingCamera)
|
||||
{
|
||||
camPosition = Camera.RenderingCamera.Position;
|
||||
return Camera.RenderingCamera.Direction;
|
||||
}
|
||||
else
|
||||
{
|
||||
float pitch = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_PITCH<float>();
|
||||
float heading = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_HEADING<float>();
|
||||
|
||||
camPosition = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_COORD<Vector3>();
|
||||
return (Game.LocalPlayer.Character.Rotation + new Rotator(pitch, 0, heading)).ToVector().ToNormalized();
|
||||
}
|
||||
}
|
||||
|
||||
return TracePlayerView(100f, TraceFlags.IntersectWorld).HitPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue