upd
This commit is contained in:
@@ -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 )
|
||||
{
|
||||
|
||||
29
Code/Inventory/Usable/PickupItem.cs
Normal file
29
Code/Inventory/Usable/PickupItem.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user