This commit is contained in:
Oscar
2025-06-10 23:24:50 +03:00
parent de85b85b13
commit 5c9be94aba
24 changed files with 1187 additions and 580 deletions

View File

@@ -6,8 +6,7 @@ public abstract class AmmoUseableBase : UseableBase
private InventoryItem FindAmmoItem()
{
// var ammoDefinition = new InventoryItemDefinition();
//По типу патрон поиск + енум типа патрон
return Dedugan.Local.Inventory.Items.FirstOrDefault( i => i.Definition.Name == "Pistol Ammo" );
}
@@ -28,7 +27,6 @@ public abstract class AmmoUseableBase : UseableBase
if ( ammo != null )
{
ammo.Count--;
Log.Info( $"[AmmoUseableBase] Ammo left: {ammo.Count}" );
if ( ammo.Count <= 0 )
{

View File

@@ -0,0 +1,29 @@
using Sandbox.Gravity;
using Sasalka;
namespace Sandbox.UI;
[Icon( "skip_next" )]
public sealed class PickupItem : InteractionButton
{
[Property] public override string Label { get; set; } = "E";
public override bool Press( IPressable.Event e )
{
base.Press( e );
if ( e.Source.Components.TryGet<Dedugan>( out var dedugan ) )
{
dedugan.Inventory.AddItem( Components.Get<InventoryItem>() );
RpcDestroy();
}
return true;
}
[Rpc.Broadcast]
void RpcDestroy()
{
GameObject.Destroy();
}
}

View File

@@ -2,14 +2,17 @@
public static class UseSystem
{
public static void TryUse( IUseContext context )
public static bool TryUse( IUseContext context )
{
foreach ( var useable in context.GetUsables() )
{
if ( useable.CanUse() )
{
useable.Use();
return true;
}
}
return false;
}
}

View File

@@ -6,11 +6,38 @@ public abstract class UseableBase : Component, IUseable
{
[Property] public float Cooldown { get; set; } = 0.5f;
private TimeSince _timeSinceUsed;
private bool _equipped;
protected override void OnStart()
[Property]
public bool Equipped
{
get => _equipped;
set
{
if ( _equipped != value )
{
_equipped = value;
if ( _equipped )
{
OnEquip?.Invoke();
}
}
}
}
private TimeSince _timeSinceUsed;
public Action OnEquip { get; set; }
protected override void OnAwake()
{
_timeSinceUsed = Cooldown;
OnEquip += OnEquipped;
}
public virtual void OnEquipped()
{
Log.Info( $"OnEquip {this}" );
}
public virtual bool CanUse()