aboutsummaryrefslogtreecommitdiffstats
path: root/code/entity/DroppedWeapon.cs
blob: 0cea7da99447c470c2c2739ef4acbf4777c1ce32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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();
	}
}