aboutsummaryrefslogtreecommitdiffstats
path: root/code/entity
diff options
context:
space:
mode:
Diffstat (limited to 'code/entity')
-rw-r--r--code/entity/DroppedWeapon.cs39
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 } };
+ }
}