diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2023-08-01 17:17:55 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2023-08-01 17:17:55 +0100 |
| commit | 20269f671e4a2a2cdec449bad01099260b7eba06 (patch) | |
| tree | 33c1794885d96d3bda81e19050e69329ce0d7fdf | |
| parent | b17d3c797717a0bce602f45c49681a64c7f5b6b3 (diff) | |
Add glow to gun
| -rw-r--r-- | code/entity/DroppedWeapon.cs | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/code/entity/DroppedWeapon.cs b/code/entity/DroppedWeapon.cs index a58bdb1..c540759 100644 --- a/code/entity/DroppedWeapon.cs +++ b/code/entity/DroppedWeapon.cs @@ -1,11 +1,12 @@ using MurderGame;
using Sandbox;
using System;
+using Sandbox.Component;
-public partial class DroppedWeapon : AnimatedEntity
+public partial class DroppedWeapon : AnimatedEntity, IUse
{
- public int Ammo { get; set; }
- public Type WeaponType { get; set; }
+ private int Ammo { get; }
+ private Type WeaponType { get; }
public DroppedWeapon(Weapon weapon) : this()
{
@@ -16,6 +17,13 @@ public partial class DroppedWeapon : AnimatedEntity public 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);
+
PhysicsEnabled = true;
UsePhysicsCollision = true;
EnableSelfCollisions = true;
@@ -27,13 +35,30 @@ public partial class DroppedWeapon : AnimatedEntity if ( !Game.IsServer ) return;
if ( !other.Tags.Has( "livingplayer" ) ) return;
- MurderGame.Player player = (MurderGame.Player)other;
-
- if ( player.Inventory== null || player.Inventory.PrimaryWeapon != null || !player.Inventory.AllowPickup) return;
+ var player = (MurderGame.Player)other;
+ if ( IsUsable( player ) )
+ {
+ Pickup( player );
+ }
+ }
- Weapon instance = TypeLibrary.Create<Weapon>( WeaponType );
+ public void Pickup( MurderGame.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 } };
+ }
}
|
