From 0bba89a7858ce091f485e04284f853e1f7f304af Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 6 Aug 2023 17:21:45 +0100 Subject: Reformat --- code/pawn/component/InventoryComponent.cs | 53 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'code/pawn/component/InventoryComponent.cs') 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, 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, 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, ISingletonCom private void PrevSlot() { - if (ActiveSlot > MIN_SLOT) + if ( ActiveSlot > MIN_SLOT ) { --ActiveSlot; } @@ -55,9 +52,10 @@ public partial class InventoryComponent : EntityComponent, 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, 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, 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(); } - } -- cgit v1.2.3-70-g09d2