Skip to content

Commit

Permalink
-updated some classes, added methods to AtlasTuningVehicle, added des…
Browse files Browse the repository at this point in the history
…criptions for docs
  • Loading branch information
Kaiwoknats committed Nov 25, 2023
1 parent c386065 commit 7abe0ac
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 85 deletions.
17 changes: 5 additions & 12 deletions src/AltV/Entities/AtlasVehicleBase.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
using AltV.Atlas.Vehicles.AltV.Interfaces;
using AltV.Net;
using AltV.Net.Async.Elements.Entities;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;

namespace AltV.Atlas.Vehicles.AltV.Entities;

public class AtlasVehicleBase : AsyncVehicle, IAtlasVehicle
public class AtlasVehicleBase( ICore core, IntPtr nativePointer, uint id ) : AsyncVehicle( core, nativePointer, id ), IAtlasVehicle

Check warning on line 8 in src/AltV/Entities/AtlasVehicleBase.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Missing XML comment for publicly visible type or member 'AtlasVehicleBase'

Check warning on line 8 in src/AltV/Entities/AtlasVehicleBase.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Missing XML comment for publicly visible type or member 'AtlasVehicleBase.AtlasVehicleBase(ICore, nint, uint)'
{
public uint Fuel => CalculateFuel( );
public uint VehicleId { get; set; }

Check warning on line 10 in src/AltV/Entities/AtlasVehicleBase.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Missing XML comment for publicly visible type or member 'AtlasVehicleBase.VehicleId'

public AtlasVehicleBase( ICore core, IntPtr nativePointer, uint id ) : base( core, nativePointer, id )
{
}

/// <summary>
/// Forces the player out of the vehicle
/// </summary>
/// <param name="player">The player to force out</param>
public void WarpOutOfVehicle( IPlayer player )
{
var isInVehicle = Passengers.Any( s => s.Player == player );
Expand All @@ -33,9 +31,4 @@ public bool LockVehicle( IPlayer player )
{
return false;
}

private uint CalculateFuel( )
{
return 1;
}
}
1 change: 0 additions & 1 deletion src/AltV/Interfaces/IAtlasVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace AltV.Atlas.Vehicles.AltV.Interfaces;

public interface IAtlasVehicle : IVehicle

Check warning on line 6 in src/AltV/Interfaces/IAtlasVehicle.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Missing XML comment for publicly visible type or member 'IAtlasVehicle'
{
uint Fuel { get; }
uint VehicleId { get; set; }

Check warning on line 8 in src/AltV/Interfaces/IAtlasVehicle.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Missing XML comment for publicly visible type or member 'IAtlasVehicle.VehicleId'
void WarpOutOfVehicle( IPlayer player );

Check warning on line 9 in src/AltV/Interfaces/IAtlasVehicle.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Missing XML comment for publicly visible type or member 'IAtlasVehicle.WarpOutOfVehicle(IPlayer)'
bool LockVehicle( object item );

Check warning on line 10 in src/AltV/Interfaces/IAtlasVehicle.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Missing XML comment for publicly visible type or member 'IAtlasVehicle.LockVehicle(object)'
Expand Down
207 changes: 148 additions & 59 deletions src/Entities/AtlasTuningVehicle.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,160 @@
using AltV.Atlas.Vehicles.AltV.Entities;
using AltV.Atlas.Vehicles.Enums;
using AltV.Atlas.Vehicles.Models;
using AltV.Atlas.Vehicles.Utils;
using AltV.Net;
using AltV.Net.Data;
using AltV.Net.Enums;

namespace AltV.Atlas.Vehicles.Entities;

public class AtlasTuningVehicle : AtlasVehicleBase
{
/// <summary>
/// Creates an AtlasTuningVehicle
/// </summary>
/// <param name="core">AltV core</param>
/// <param name="nativePointer">AltV nativePointer</param>
/// <param name="id">Id of the ped</param>
public AtlasTuningVehicle( ICore core, IntPtr nativePointer, uint id ) : base( core, nativePointer, id )
{
ModKit = 1;
NumberplateText = "ATLAS";
SetPrimaryRgb( "#1a222e" );
SetSecondaryRgb( "#15dbfc" );
SetPearlColor( EGtaColor.MatteBlack );
}
/// <summary>
/// All installed vehicle mods
/// </summary>
public List<VehicleMod> InstalledMods { get; } = new( );
/// <summary>
/// The primary color material
/// </summary>
public EColorMaterial PrimaryColorMaterial { get; private set; } = EColorMaterial.DefaultAlloy;
/// <summary>
/// The secondary color material
/// </summary>
public EColorMaterial SecondaryColorMaterial { get; private set; } = EColorMaterial.DefaultAlloy;

// public List<VehicleMod> InstalledMods { get; } = new( );
// public EColorMaterial PrimaryColorMaterial { get; private set; } = EColorMaterial.DefaultAlloy;
// public EColorMaterial SecondaryColorMaterial { get; private set; } = EColorMaterial.DefaultAlloy;

// public void SetPrimaryMaterial( EColorMaterial material )
// {
// var oldColor = PrimaryColorRgb;
// PrimaryColor = ( byte ) material;
// PrimaryColorRgb = oldColor;
// }
//
// public void SetSecondaryMaterial( EColorMaterial material )
// {
// var oldColor = PrimaryColorRgb;
// PrimaryColor = ( byte ) material;
// PrimaryColorRgb = oldColor;
// }
//
// public void SetPrimaryRgb( string rgb )
// {
// if( !rgb.TryParseRgb( out var color ) )
// return;
//
// PrimaryColorRgb = new Rgba( color.R, color.G, color.B, color.A );
// }
//
// public void SetSecondaryRgb( string rgb )
// {
// if( !rgb.TryParseRgb( out var color ) )
// return;
//
// SecondaryColorRgb = new Rgba( color.R, color.G, color.B, color.A );
// }
//
// public bool InstallMod( VehicleMod vehicleMod, bool force = false )
// {
// var maxIndex = GetModsCount( ( byte ) vehicleMod.ModType );
//
// if( vehicleMod.Index > maxIndex && !force )
// {
// return false;
// }
//
// var result = SetMod( ( byte ) vehicleMod.ModType, ( byte ) vehicleMod.Index );
// InstalledMods.Add( vehicleMod );
// return result;
// }
//
// public IEnumerable<( VehicleMod mod, bool result )> InstallMods( IEnumerable<VehicleMod> vehicleMods )
// {
// return ( from vehicleMod in vehicleMods let result = InstallMod( vehicleMod ) select ( vehicleMod, result ) ).ToList( );
// }
//
// public bool RemoveMod( VehicleModType vehicleModType )
// {
// var result = SetMod( ( byte ) vehicleModType, 0 );
// InstalledMods.RemoveAll( x => x.ModType == vehicleModType );
// return result;
// }
/// <summary>
/// Sets the PrimaryMaterial of the vehicle
/// A list of all available Materials can be found in the EColorMaterial Enum
/// </summary>
/// <param name="material">The material to apply</param>
public void SetPrimaryMaterial( EColorMaterial material )
{
var oldColor = PrimaryColorRgb;
PrimaryColor = ( byte ) material;
PrimaryColorRgb = oldColor;
}

/// <summary>
/// Sets the SecondaryMaterial of the vehicle
/// A list of all available Materials can be found in the EColorMaterial Enum
/// </summary>
/// <param name="material">The material to apply</param>
public void SetSecondaryMaterial( EColorMaterial material )
{
var oldColor = PrimaryColorRgb;
PrimaryColor = ( byte ) material;
PrimaryColorRgb = oldColor;
}

/// <summary>
/// Sets the vehicle PrimaryColorRgb from a string
/// </summary>
/// <param name="rgb"></param>
public void SetPrimaryRgb( string rgb )
{
if( !rgb.TryParseRgb( out var color ) )
return;

PrimaryColorRgb = new Rgba( color.R, color.G, color.B, color.A );
}

/// <summary>
/// Sets the vehicle SecondaryColorRgb from a string
/// </summary>
/// <param name="rgb"></param>
public void SetSecondaryRgb( string rgb )
{
if( !rgb.TryParseRgb( out var color ) )
return;

SecondaryColorRgb = new Rgba( color.R, color.G, color.B, color.A );
}

/// <summary>
/// Sets the vehicle PearlColor from a EGtaColor
/// </summary>
/// <param name="color"></param>
public void SetPearlColor( EGtaColor color ) => PearlColor = ( byte ) color;

/// <summary>
/// Installs a given VehicleMod
/// </summary>
/// <param name="vehicleMod">The mod to install</param>
/// <param name="force">Force the mod index even if it should not exist</param>
/// <returns>Returns if the SetMod was successful</returns>
public bool InstallMod( VehicleMod vehicleMod, bool force = false )
{
var maxIndex = GetModsCount( ( byte ) vehicleMod.ModType );

if( vehicleMod.Index > maxIndex && !force )
{
return false;
}

var result = SetMod( ( byte ) vehicleMod.ModType, ( byte ) vehicleMod.Index );

if( result )
InstalledMods.Add( vehicleMod );

return result;
}

/// <summary>
/// Installs a list of mods
/// </summary>
/// <param name="vehicleMods">The list of mods to install</param>
/// <returns>Returns a list of tuples with the given mod and the SetMod result</returns>
public IEnumerable<( VehicleMod mod, bool result )> InstallMods( IEnumerable<VehicleMod> vehicleMods )
{
return ( from vehicleMod in vehicleMods let result = InstallMod( vehicleMod ) select ( vehicleMod, result ) ).ToList( );
}

/// <summary>
/// Removes the given VehicleModType
/// </summary>
/// <param name="vehicleModType">The type to remove</param>
/// <returns>Returns the SetMod result or false if the mod wasn't installed</returns>
public bool RemoveMod( VehicleModType vehicleModType )
{
if( InstalledMods.All( mod => mod.ModType != vehicleModType ) )
return false;

var result = SetMod( ( byte ) vehicleModType, 0 );
InstalledMods.RemoveAll( x => x.ModType == vehicleModType );
return result;
}

/// <summary>
/// Removes all installed vehicleMods
/// </summary>
/// <returns>Returns a list of tuples with the given mod and the SetMod result</returns>
public IEnumerable<( VehicleMod mod, bool result )> RemoveMods( )
{
return ( from vehicleMod in InstalledMods.ToList( ) let result = RemoveMod( vehicleMod.ModType ) select ( vehicleMod, result ) ).ToList( );
}

/// <summary>
/// Removes all given vehicleMods
/// </summary>
/// <param name="vehicleMods"></param>
/// <returns>Returns a list of tuples with the given mod and the SetMod result</returns>
public IEnumerable<( VehicleMod mod, bool result )> RemoveMods( IEnumerable<VehicleMod> vehicleMods )
{
return ( from vehicleMod in vehicleMods.ToList( ) let result = RemoveMod( vehicleMod.ModType ) select ( vehicleMod, result ) ).ToList( );
}
}
1 change: 0 additions & 1 deletion src/Factories/AtlasVehicleFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public AtlasVehicleFactory( ILogger<AtlasVehicleFactory> logger, IServiceProvide
/// <summary>
/// Create a new vehicle of type T
/// </summary>
/// <param name="vehicleId"></param>
/// <param name="model">The model of the vehicle</param>
/// <param name="position">The position to spawn the vehicle at</param>
/// <param name="rotation">The rotation to spawn the vehicle at</param>
Expand Down
15 changes: 3 additions & 12 deletions src/Models/VehicleMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@ namespace AltV.Atlas.Vehicles.Models;

public class VehicleMod
{
/// <summary>
/// Constructor to create a VehicleMod
/// </summary>
/// <param name="vehicleModType">The type of the mod</param>
/// <param name="index">The index of the mod</param>
public VehicleMod( VehicleModType vehicleModType, uint index )
{
ModType = vehicleModType;
Index = index;
}
/// <summary>
/// Type of the vehicle mod
/// </summary>
public VehicleModType ModType { get; set; }
public VehicleModType ModType { get; init; }

/// <summary>
/// Index of the vehicle mod
/// </summary>
public uint Index { get; set; }
public uint Index { get; init; }

}

0 comments on commit 7abe0ac

Please sign in to comment.