Skip to content

Commit

Permalink
Added Ammo Config
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmightyLks committed Feb 7, 2021
1 parent 40b0ee4 commit e03786d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CustomLoadout/Config/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Synapse.Config;
using CustomLoadout.Config.Types;
using Synapse.Config;
using System.Collections.Generic;
using System.ComponentModel;

namespace CustomLoadout
{
public class PluginConfig : AbstractConfigSection
public sealed class PluginConfig : AbstractConfigSection
{
[Description("Loadout configuration")]
public List<Loadout> RoleInventory { get; set; } = new List<Loadout>()
Expand Down
26 changes: 26 additions & 0 deletions CustomLoadout/Config/Types/AmmoConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomLoadout.Config.Types
{
public sealed class AmmoConfig
{
[Description("Should the class' amount of ammo be replaced?")]
public bool ReplaceAmmo { get; set; }
public uint Ammo5 { get; set; }
public uint Ammo7 { get; set; }
public uint Ammo9 { get; set; }

public AmmoConfig()
{
ReplaceAmmo = false;
Ammo5 = 0;
Ammo7 = 0;
Ammo9 = 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Synapse.Config;

namespace CustomLoadout.Config
namespace CustomLoadout.Config.Types
{
public class ItemChance
public sealed class ItemChance
{
public SerializedItem Item { get; set; }
public float Chance { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.ComponentModel;

namespace CustomLoadout
namespace CustomLoadout.Config.Types
{
public class Loadout
public sealed class Loadout
{
public int RoleID { get; set; }

Expand All @@ -13,11 +13,16 @@ public class Loadout

[Description("Items & their Chance to spawn")]
public List<ItemChance> Items { get; set; }

[Description("Configure the class' ammunition")]
public AmmoConfig AmmoConfig { get; set; }

public Loadout()
{
RoleID = -1;
ReplaceDefault = false;
Items = new List<ItemChance>() { new ItemChance() };
AmmoConfig = new AmmoConfig();
}
}
}
1 change: 1 addition & 0 deletions CustomLoadout/CustomLoadout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace CustomLoadout
Author = "AlmightyLks",
Description = "Configure roles' inventories",
Name = "CustomLoadout",
LoadPriority = int.MinValue,
SynapseMajor = 2,
SynapseMinor = 1,
SynapsePatch = 0,
Expand Down
5 changes: 3 additions & 2 deletions CustomLoadout/CustomLoadout.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Config\ItemChance.cs" />
<Compile Include="Config\Types\AmmoConfig.cs" />
<Compile Include="Config\Types\ItemChance.cs" />
<Compile Include="CustomLoadout.cs" />
<Compile Include="Config\Loadout.cs" />
<Compile Include="Config\Types\Loadout.cs" />
<Compile Include="Config\PluginConfig.cs" />
<Compile Include="Handler\PluginEventHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
8 changes: 8 additions & 0 deletions CustomLoadout/Handler/PluginEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ private void Player_PlayerSetClassEvent(PlayerSetClassEventArgs ev)
if (loadout is null)
return;

uint ammo5 = loadout.AmmoConfig.ReplaceAmmo ? loadout.AmmoConfig.Ammo5 : ev.Player.Ammo5;
uint ammo7 = loadout.AmmoConfig.ReplaceAmmo ? loadout.AmmoConfig.Ammo7 : ev.Player.Ammo7;
uint ammo9 = loadout.AmmoConfig.ReplaceAmmo ? loadout.AmmoConfig.Ammo9 : ev.Player.Ammo9;

if (loadout.ReplaceDefault)
ev.Player.Inventory.Clear();

foreach (var item in loadout.Items)
{
if (UnityEngine.Random.Range(0f, 100f) <= item.Chance)
ev.Player.Inventory.AddItem(item.Item.Parse());

ev.Player.Ammo5 = ammo5;
ev.Player.Ammo7 = ammo7;
ev.Player.Ammo9 = ammo9;
}
}
});
Expand Down

0 comments on commit e03786d

Please sign in to comment.