Skip to content

Commit

Permalink
Add xml docs. add pedtaskfactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDutchDev committed Nov 25, 2023
1 parent 6e8acbe commit 5201631
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 10 deletions.
2 changes: 1 addition & 1 deletion AltV.Atlas.Peds.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/altv-atlas/Peds.Shared.git</RepositoryUrl>
Expand Down
31 changes: 31 additions & 0 deletions Factories/PedTaskFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using AltV.Atlas.Peds.Shared.Interfaces;
using Microsoft.Extensions.DependencyInjection;

namespace AltV.Atlas.Peds.Shared.Factories;

/// <summary>
/// A factory that can be injected via DI and used to create a new ped task
/// </summary>
public class PedTaskFactory
{
private readonly IServiceProvider _serviceProvider;
/// <summary>
/// The ped task factory
/// </summary>
/// <param name="serviceProvider">A service provider</param>
public PedTaskFactory( IServiceProvider serviceProvider )
{
_serviceProvider = serviceProvider;
}

/// <summary>
/// Creates a new ped task of the given type, with the given parameters
/// </summary>
/// <param name="parameters">The parameters that are required for the given ped task</param>
/// <typeparam name="T">The ped task to create</typeparam>
/// <returns></returns>
public T CreatePedTask<T>( params object[ ] parameters ) where T : IPedTask
{
return ActivatorUtilities.CreateInstance<T>( _serviceProvider, parameters );
}
}
3 changes: 3 additions & 0 deletions Interfaces/IAtlasPed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ namespace AltV.Atlas.Peds.Shared.Interfaces;
/// </summary>
public interface IAtlasPed : ISharedPed
{
/// <summary>
/// The task the ped is currently doing (eg wander, follow player, etc)
/// </summary>
IPedTask? CurrentTask { get; }
}
8 changes: 8 additions & 0 deletions Interfaces/IPedTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public interface IPedTask
/// </summary>
Guid Id { get; set; }

/// <summary>
/// Triggered on client-side when the task starts (eg on stream-in)
/// </summary>
/// <param name="ped">The ped it started on</param>
void OnStart( ISharedPed ped );

/// <summary>
/// Triggered on client-side when the task needs to stop (eg on stream-out)
/// </summary>
void OnStop( );
}
22 changes: 22 additions & 0 deletions PedTasks/PedTaskFollowPlayerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,47 @@

namespace AltV.Atlas.Peds.Shared.PedTasks;

/// <summary>
/// A task to make the ped follow the given player
/// </summary>
public abstract class PedTaskFollowPlayerBase : IPedTask
{
private const string Identifier = "58E1B465-A689-47F7-98B3-D0F236E81052";

/// <summary>
/// The ID of this task (Unique ID used on both client and server-side to identify the task)
/// </summary>
[Identifier( Identifier )]
public Guid Id { get; set; } = Guid.Parse( Identifier );

/// <summary>
/// The ID of the target player to follow
/// </summary>
public uint TargetId { get; set; }

/// <summary>
/// Creates a new instance of this task
/// </summary>
/// <param name="targetId">The ID of the target player to follow</param>
public PedTaskFollowPlayerBase( uint targetId )
{
TargetId = targetId;
}

/// <summary>
/// Triggered when the ped starts the task. Unused on server-side
/// </summary>
/// <param name="ped">The ped that starts the task</param>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStart( ISharedPed ped )
{
throw new NotImplementedException( );
}

/// <summary>
/// Triggered when the ped stops the task. Unused on server-side
/// </summary>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStop( )
{
throw new NotImplementedException( );
Expand Down
19 changes: 17 additions & 2 deletions PedTasks/PedTaskIdleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,33 @@

namespace AltV.Atlas.Peds.Shared.PedTasks;

public class PedTaskIdleBase : IPedTask
/// <summary>
/// A task to make the ped idle (do nothing)
/// </summary>
public abstract class PedTaskIdleBase : IPedTask
{
private const string Identifier = "169FA116-9BC7-4FF7-B628-B591BCECA6F0";

/// <summary>
/// The ID of this task (Unique ID used on both client and server-side to identify the task)
/// </summary>
[Identifier( Identifier )]
public Guid Id { get; set; } = Guid.Parse( Identifier );


/// <summary>
/// Triggered when the ped starts the task. Unused on server-side
/// </summary>
/// <param name="ped">The ped that starts the task</param>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStart( ISharedPed ped )
{
throw new NotImplementedException( );
}

/// <summary>
/// Triggered when the ped stops the task. Unused on server-side
/// </summary>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStop( )
{
throw new NotImplementedException( );
Expand Down
25 changes: 20 additions & 5 deletions PedTasks/PedTaskMoveToTargetPositionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@

namespace AltV.Atlas.Peds.Shared.PedTasks;

/// <summary>
/// A task to make the ped move(walk) to a given position
/// </summary>
public abstract class PedTaskMoveToTargetPositionBase : IPedTask
{
private const string Identifier = "18F9B53E-840E-45EC-A209-6D058F8C2D5F";

/// <summary>
/// The ID of this task (Unique ID used on both client and server-side to identify the task)
/// </summary>
[Identifier( Identifier )]
public Guid Id { get; set; } = Guid.Parse( Identifier );
/// <summary>
/// The target position to move to
/// </summary>
public Position TargetPosition { get; set; }

public PedTaskMoveToTargetPositionBase( )
{
}


/// <summary>
/// Triggered when the ped starts the task. Unused on server-side
/// </summary>
/// <param name="ped">The ped that starts the task</param>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStart( ISharedPed ped )
{
throw new NotImplementedException( );
}

/// <summary>
/// Triggered when the ped stops the task. Unused on server-side
/// </summary>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStop( )
{
throw new NotImplementedException( );
Expand Down
39 changes: 37 additions & 2 deletions PedTasks/PedTaskWanderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,64 @@

namespace AltV.Atlas.Peds.Shared.PedTasks;

public class PedTaskWanderBase : IPedTask
/// <summary>
/// A task to make the ped wander around in an area
/// </summary>
public abstract class PedTaskWanderBase : IPedTask
{
private const string Identifier = "E73C7957-4D36-44EA-AD81-5731533DA8C0";

/// <summary>
/// The ID of this task (Unique ID used on both client and server-side to identify the task)
/// </summary>
[Identifier( Identifier )]
public Guid Id { get; set; } = Guid.Parse( Identifier );
/// <summary>
/// The position to wander around
/// </summary>
public Vector3 Position { get; set; }
/// <summary>
/// Radius from position the ped can wander in
/// </summary>
public uint Radius { get; set; }
/// <summary>
/// Minimum length of a walk
/// </summary>
public uint MinLength { get; set; }
/// <summary>
/// Time the ped waits between walks
/// </summary>
public uint TimeBetweenWalks { get; set; }

public PedTaskWanderBase( Vector3 position, uint radius, uint minLength, uint timeBetweenWalks )
/// <summary>
/// Creates a new wander task
/// </summary>
/// <param name="position">The position to wander around</param>
/// <param name="radius">Radius from position the ped can wander in</param>
/// <param name="minLength">Minimum length of a walk</param>
/// <param name="timeBetweenWalks">Time the ped waits between walks</param>
protected PedTaskWanderBase( Vector3 position, uint radius, uint minLength, uint timeBetweenWalks )
{
Position = position;
Radius = radius;
MinLength = minLength;
TimeBetweenWalks = timeBetweenWalks;
}

/// <summary>
/// Triggered when the ped starts the task. Unused on server-side
/// </summary>
/// <param name="ped">The ped that starts the task</param>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStart( ISharedPed ped )
{
throw new NotImplementedException( );
}

/// <summary>
/// Triggered when the ped stops the task. Unused on server-side
/// </summary>
/// <exception cref="NotImplementedException">throws this exception when not implemented on client-side</exception>
public virtual void OnStop( )
{
throw new NotImplementedException( );
Expand Down

0 comments on commit 5201631

Please sign in to comment.