aboutsummaryrefslogtreecommitdiffstats
path: root/code/pawn/component/InventoryComponent.cs
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-08-06 17:21:45 +0100
committerLeonardo Bishop <me@leonardobishop.com>2023-08-06 17:21:45 +0100
commit0bba89a7858ce091f485e04284f853e1f7f304af (patch)
tree89ba42616e0f245cc84c96cc5b353eea117057d0 /code/pawn/component/InventoryComponent.cs
parent87d74b50bf443bf199be05bd03afdca6ece082ff (diff)
ReformatHEADmaster
Diffstat (limited to 'code/pawn/component/InventoryComponent.cs')
-rw-r--r--code/pawn/component/InventoryComponent.cs53
1 files changed, 26 insertions, 27 deletions
diff --git a/code/pawn/component/InventoryComponent.cs b/code/pawn/component/InventoryComponent.cs
index 6383aa8..cec897c 100644
--- a/code/pawn/component/InventoryComponent.cs
+++ b/code/pawn/component/InventoryComponent.cs
@@ -1,31 +1,27 @@
using Sandbox;
-using System;
namespace MurderGame;
public partial class InventoryComponent : EntityComponent<Player>, ISingletonComponent
{
- const int MIN_SLOT = 1;
- const int MAX_SLOT = 2;
+ private const int MIN_SLOT = 1;
+ private const int MAX_SLOT = 2;
- const int UNARMED_SLOT = 1;
- const int PRIMARY_SLOT = 2;
+ private const int UNARMED_SLOT = 1;
+ private const int PRIMARY_SLOT = 2;
- [Net]
- public Weapon PrimaryWeapon { get; private set; }
+ [Net] public Weapon PrimaryWeapon { get; private set; }
- [Net]
- public int ActiveSlot { get; set; }
+ [Net] public int ActiveSlot { get; set; }
- [Net]
- public bool AllowPickup { get; set; } = true;
+ [Net] public bool AllowPickup { get; set; } = true;
public Weapon GetCurrentWeapon()
{
return ActiveSlot switch
{
PRIMARY_SLOT => PrimaryWeapon,
- _ => null,
+ _ => null
};
}
@@ -34,11 +30,12 @@ public partial class InventoryComponent : EntityComponent<Player>, ISingletonCom
PrimaryWeapon?.OnHolster();
PrimaryWeapon?.Delete();
PrimaryWeapon = weapon;
- if (weapon != null)
+ if ( weapon != null )
{
weapon.ChangeOwner( Entity );
}
- if (ActiveSlot == PRIMARY_SLOT)
+
+ if ( ActiveSlot == PRIMARY_SLOT )
{
weapon?.OnEquip( Entity );
}
@@ -46,7 +43,7 @@ public partial class InventoryComponent : EntityComponent<Player>, ISingletonCom
private void PrevSlot()
{
- if (ActiveSlot > MIN_SLOT)
+ if ( ActiveSlot > MIN_SLOT )
{
--ActiveSlot;
}
@@ -55,9 +52,10 @@ public partial class InventoryComponent : EntityComponent<Player>, ISingletonCom
ActiveSlot = MAX_SLOT;
}
}
+
private void NextSlot()
{
- if (ActiveSlot < MAX_SLOT)
+ if ( ActiveSlot < MAX_SLOT )
{
++ActiveSlot;
}
@@ -67,39 +65,40 @@ public partial class InventoryComponent : EntityComponent<Player>, ISingletonCom
}
}
- public void Simulate(IClient cl)
+ public void Simulate( IClient cl )
{
var currentWeapon = GetCurrentWeapon();
var currentSlot = ActiveSlot;
- if (Input.Released("SlotPrev"))
+ if ( Input.Released( "SlotPrev" ) )
{
PrevSlot();
}
- else if (Input.Released("SlotNext"))
+ else if ( Input.Released( "SlotNext" ) )
{
NextSlot();
}
- else if (Input.Down("Slot1"))
+ else if ( Input.Down( "Slot1" ) )
{
ActiveSlot = 1;
}
- else if (Input.Down("Slot2"))
+ else if ( Input.Down( "Slot2" ) )
{
ActiveSlot = 2;
}
- if (ActiveSlot != currentSlot)
+ if ( ActiveSlot != currentSlot )
{
currentWeapon?.OnHolster();
GetCurrentWeapon()?.OnEquip( Entity );
}
+
GetCurrentWeapon()?.Simulate( cl );
}
public void Holster()
{
- Weapon weapon = GetCurrentWeapon();
+ var weapon = GetCurrentWeapon();
weapon?.OnHolster();
}
@@ -109,18 +108,18 @@ public partial class InventoryComponent : EntityComponent<Player>, ISingletonCom
SetPrimaryWeapon( null );
}
- public void SpillContents(Vector3 location, Vector3 velocity)
+ public void SpillContents( Vector3 location, Vector3 velocity )
{
Holster();
- if (PrimaryWeapon is not null and Pistol )
+ if ( PrimaryWeapon is not null and Pistol )
{
PrimaryWeapon.ChangeOwner( null );
- DroppedWeapon droppedWeapon = new( (Pistol)PrimaryWeapon );
+ DroppedWeapon droppedWeapon = new((Pistol)PrimaryWeapon);
droppedWeapon.CopyFrom( PrimaryWeapon );
droppedWeapon.Position = location;
droppedWeapon.Velocity = velocity;
}
+
Clear();
}
-
}