Skip to content

Commit

Permalink
Generate a list of compatible Weapon Components when creating the Man…
Browse files Browse the repository at this point in the history
…ager
  • Loading branch information
justalemon committed Feb 14, 2021
1 parent eef3b9f commit 7b0cea5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions PlayerCompanion/WeaponManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public WeaponInfo(WeaponHash hash)
public void Update()
{
Components.Clear();
foreach (WeaponComponentHash component in Enum.GetValues(typeof(WeaponComponentHash)))
foreach (WeaponComponentHash component in WeaponManager.sets[WeaponHash])
{
if (Function.Call<bool>(Hash.HAS_PED_GOT_WEAPON_COMPONENT, Game.Player.Character, WeaponHash, component))
{
Expand Down Expand Up @@ -119,7 +119,7 @@ public class WeaponSet
public void Populate()
{
Weapons.Clear();
foreach (WeaponHash hash in Enum.GetValues(typeof(WeaponHash)))
foreach (WeaponHash hash in WeaponManager.sets.Keys)
{
if (hash == WeaponHash.Unarmed || hash == WeaponHash.Parachute)
{
Expand Down Expand Up @@ -164,6 +164,7 @@ public class WeaponManager
{
#region Fields

internal static Dictionary<WeaponHash, List<WeaponComponentHash>> sets = new Dictionary<WeaponHash, List<WeaponComponentHash>>();
private readonly Dictionary<Model, WeaponSet> weapons = new Dictionary<Model, WeaponSet>();

#endregion
Expand All @@ -187,6 +188,26 @@ public class WeaponManager

internal WeaponManager()
{
// Add the list of weapons and their components
foreach (WeaponHash hash in Enum.GetValues(typeof(WeaponHash)))
{
if (hash == WeaponHash.Unarmed || hash == WeaponHash.Parachute)
{
continue;
}

List<WeaponComponentHash> components = new List<WeaponComponentHash>();

foreach (WeaponComponentHash component in Enum.GetValues(typeof(WeaponComponentHash)))
{
if (Function.Call<bool>(Hash.DOES_WEAPON_TAKE_WEAPON_COMPONENT, hash, component))
{
components.Add(component);
}
}

sets.Add(hash, components);
}
}

#endregion
Expand Down

0 comments on commit 7b0cea5

Please sign in to comment.