upd
This commit is contained in:
@@ -91,7 +91,7 @@ public class Inventar : Component
|
||||
while ( toAdd > 0 && (UnlimitedSlots || Items.Count < MaxInventorySlots) )
|
||||
{
|
||||
int stackCount = Math.Min( toAdd, item.Definition.MaxCount );
|
||||
var newStack = new InventoryItem { Definition = item.Definition, Count = stackCount };
|
||||
var newStack = new InventoryItem { Definition = item.Definition, Count = stackCount, MagazineAmmo = item.MagazineAmmo };
|
||||
Items.Add( newStack );
|
||||
toAdd -= stackCount;
|
||||
OnChanged?.Invoke();
|
||||
@@ -161,19 +161,14 @@ public class Inventar : Component
|
||||
if ( item == null || !Items.Contains( item ) )
|
||||
return;
|
||||
|
||||
// // Создаем копию предмета для выбрасывания
|
||||
// var droppedItem = new InventoryItem
|
||||
// {
|
||||
// Definition = item.Definition,
|
||||
// Count = item.Count // Выбрасываем всю стопку
|
||||
// };
|
||||
|
||||
GameObject gO = item.Definition.Prefab.Clone( position );
|
||||
|
||||
if ( gO.Components.TryGet<InventoryItem>( out var inventoryItem ) )
|
||||
{
|
||||
inventoryItem.Count = item.Count;
|
||||
inventoryItem.Definition = item.Definition;
|
||||
// Копируем патроны из оригинального предмета
|
||||
inventoryItem.MagazineAmmo = item.MagazineAmmo;
|
||||
}
|
||||
|
||||
gO.NetworkSpawn();
|
||||
|
||||
@@ -8,6 +8,9 @@ public class InventoryItem : Component
|
||||
[Property] public BaseItemDefinition Definition { get; set; }
|
||||
[Sync, Property] public int Count { get; set; } = 1;
|
||||
[Sync] public bool Equipped { get; set; } = false;
|
||||
|
||||
// Сохранение патронов в магазине для оружия
|
||||
[Sync] public int MagazineAmmo { get; set; } = 0;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
@@ -64,7 +67,7 @@ public class InventoryItem : Component
|
||||
|
||||
public InventoryItem Clone()
|
||||
{
|
||||
var clone = new InventoryItem { Definition = Definition, Count = Count, Equipped = false };
|
||||
var clone = new InventoryItem { Definition = Definition, Count = Count, Equipped = false, MagazineAmmo = MagazineAmmo };
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user