From 20269f671e4a2a2cdec449bad01099260b7eba06 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 1 Aug 2023 17:17:55 +0100 Subject: Add glow to gun --- code/entity/DroppedWeapon.cs | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'code') 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.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( WeaponType ); + public void Pickup( MurderGame.Player player ) + { + var instance = TypeLibrary.Create( 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 } }; + } } -- cgit v1.2.3-70-g09d2