blob: c54075992f0ea3423f4bcacf02040badace4f0aa (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
using MurderGame;
using Sandbox;
using System;
using Sandbox.Component;
public partial class DroppedWeapon : AnimatedEntity, IUse
{
private int Ammo { get; }
private Type WeaponType { get; }
public DroppedWeapon(Weapon weapon) : this()
{
Ammo = weapon.Ammo;
WeaponType = weapon.GetType();
}
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;
EnableSolidCollisions = true;
}
public override void StartTouch( Entity other )
{
if ( !Game.IsServer ) return;
if ( !other.Tags.Has( "livingplayer" ) ) return;
var player = (MurderGame.Player)other;
if ( IsUsable( player ) )
{
Pickup( player );
}
}
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 } };
}
}
|