From 0bba89a7858ce091f485e04284f853e1f7f304af Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 6 Aug 2023 17:21:45 +0100 Subject: Reformat --- code/entity/DroppedWeapon.cs | 68 ++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'code/entity/DroppedWeapon.cs') diff --git a/code/entity/DroppedWeapon.cs b/code/entity/DroppedWeapon.cs index c540759..46cf67d 100644 --- a/code/entity/DroppedWeapon.cs +++ b/code/entity/DroppedWeapon.cs @@ -1,14 +1,12 @@ -using MurderGame; +using System; +using MurderGame; using Sandbox; -using System; using Sandbox.Component; +using Player = MurderGame.Player; -public partial class DroppedWeapon : AnimatedEntity, IUse +public class DroppedWeapon : AnimatedEntity, IUse { - private int Ammo { get; } - private Type WeaponType { get; } - - public DroppedWeapon(Weapon weapon) : this() + public DroppedWeapon( Weapon weapon ) : this() { Ammo = weapon.Ammo; WeaponType = weapon.GetType(); @@ -16,49 +14,63 @@ public partial class DroppedWeapon : AnimatedEntity, IUse public DroppedWeapon() { - Tags.Add("droppedweapon"); - + Tags.Add( "droppedweapon" ); + var glow = Components.GetOrCreate(); glow.Enabled = true; glow.Width = 0.25f; - glow.Color = new Color( 4f, 50.0f, 70.0f, 1.0f ); - glow.ObscuredColor = new Color( 0, 0, 0, 0); - + glow.Color = new Color( 4f, 50.0f, 70.0f ); + glow.ObscuredColor = new Color( 0, 0, 0, 0 ); + PhysicsEnabled = true; UsePhysicsCollision = true; EnableSelfCollisions = true; EnableSolidCollisions = true; } + private int Ammo { get; } + private Type WeaponType { get; } + + public bool OnUse( Entity user ) + { + if ( user is not Player player ) + { + return false; + } + + Pickup( player ); + return false; + } + + public bool IsUsable( Entity user ) + { + return user is Player { Inventory: { PrimaryWeapon: null, AllowPickup: true } }; + } + public override void StartTouch( Entity other ) { - if ( !Game.IsServer ) return; - if ( !other.Tags.Has( "livingplayer" ) ) return; + if ( !Game.IsServer ) + { + return; + } - var player = (MurderGame.Player)other; + if ( !other.Tags.Has( "livingplayer" ) ) + { + return; + } + + var player = (Player)other; if ( IsUsable( player ) ) { Pickup( player ); } } - public void Pickup( MurderGame.Player player ) + public void Pickup( Player player ) { var instance = TypeLibrary.Create( WeaponType ); instance.Ammo = Ammo; player.Inventory.SetPrimaryWeapon( instance ); Delete(); } - - public bool OnUse( Entity user ) - { - if ( user is not MurderGame.Player player ) return false; - Pickup( player ); - return false; - } - - public bool IsUsable( Entity user ) - { - return user is MurderGame.Player { Inventory: { PrimaryWeapon: null, AllowPickup: true } }; - } } -- cgit v1.2.3-70-g09d2