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, 39 insertions, 0 deletions
diff --git a/code/entity/DroppedWeapon.cs b/code/entity/DroppedWeapon.cs
new file mode 100644
index 0000000..f0cad67
--- /dev/null
+++ b/code/entity/DroppedWeapon.cs
@@ -0,0 +1,39 @@
+using MurderGame;
+using Sandbox;
+using System;
+
+public partial class DroppedWeapon : AnimatedEntity
+{
+ public int Ammo { get; set; }
+ public Type WeaponType { get; set; }
+
+ public DroppedWeapon(Weapon weapon) : this()
+ {
+ Ammo = weapon.Ammo;
+ WeaponType = weapon.GetType();
+ }
+
+ public DroppedWeapon()
+ {
+ Tags.Add("droppedweapon");
+ PhysicsEnabled = true;
+ UsePhysicsCollision = true;
+ EnableSelfCollisions = true;
+ EnableSolidCollisions = true;
+ }
+
+ public override void StartTouch( Entity other )
+ {
+ 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;
+
+ Weapon instance = TypeLibrary.Create<Weapon>( WeaponType );
+ instance.Ammo = Ammo;
+ player.Inventory.SetPrimaryWeapon( instance );
+ Delete();
+ }
+}