diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2023-08-06 17:21:45 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2023-08-06 17:21:45 +0100 |
| commit | 0bba89a7858ce091f485e04284f853e1f7f304af (patch) | |
| tree | 89ba42616e0f245cc84c96cc5b353eea117057d0 /code/entity/DroppedWeapon.cs | |
| parent | 87d74b50bf443bf199be05bd03afdca6ece082ff (diff) | |
Diffstat (limited to 'code/entity/DroppedWeapon.cs')
| -rw-r--r-- | code/entity/DroppedWeapon.cs | 68 |
1 files changed, 40 insertions, 28 deletions
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>();
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<Weapon>( 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 } };
- }
}
|
