This commit is contained in:
Oscar
2025-06-10 20:45:40 +03:00
parent dd266b1a8a
commit de85b85b13
14 changed files with 196 additions and 273 deletions

View File

@@ -0,0 +1,12 @@
namespace Sasalka;
[GameResource( "Base Item Definition", "inv", "", Category = "Sasalka", Icon = "inventory_2" )]
public class BaseItemDefinition : GameResource
{
public string Name { get; set; }
public string Description { get; set; }
[ResourceType( "prefab" )] public GameObject Prefab { get; set; }
public Texture ImageTexture { get; set; }
public string ImageUrl { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace Sasalka;
[GameResource( "Clothing Item Definition", "clitem", "", Category = "Sasalka", Icon = "inventory_2" )]
public class ClothingItemDefinition : BaseItemDefinition, IEquipable
{
[Property] public string ClothUrl { get; set; }
public Inventar.InventorySlot Slot { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Sasalka;
public interface IEquipable
{
Inventar.InventorySlot Slot { get; }
}

View File

@@ -2,23 +2,11 @@
namespace Sasalka;
[GameResource( "Inventory Item Definition", "inv", "", Category = "Sasalka", Icon = "inventory_2" )]
public class InventoryItemDefinition : GameResource
[GameResource( "Weapon Item Definition", "weapon", "", Category = "Sasalka", Icon = "inventory_2" )]
public class WeaponItemDefinition : BaseItemDefinition, IEquipable
{
public Inventar.InventorySlot Slot { get; set; }
public CitizenAnimationHelper.HoldTypes HoldType { get; set; } = CitizenAnimationHelper.HoldTypes.None;
public Texture ImageTexture { get; set; }
public string ImageUrl { get; set; }
public string ClothUrl { get; set; }
public string Name { get; set; }
public string Description { get; set; }
[ResourceType( "prefab" )] public GameObject Prefab { get; set; }
[InlineEditor, Space] public WeaponDefinition WeaponDefinition { get; set; }
}

View File

@@ -17,20 +17,12 @@ public class Inventar
public List<InventoryItem> Items { get; private set; } = new();
public static bool IsInventoryOpen = false;
// public Dictionary<InventorySlot, EquippedItem> EquippedItems { get; private set; } = new();
public Dictionary<InventorySlot, InventoryItem> EquippedItems { get; private set; } = new();
public event Action OnChanged;
public event Action<InventoryItem> OnEquipped;
public event Action<InventoryItem> OnUnEquipped;
// public class EquippedItem
// {
// public InventoryItem Item { get; set; }
// public GameObject SpawnedObject { get; set; }
// }
public void AddItem( InventoryItem item )
{
Items.Add( item );
@@ -44,15 +36,30 @@ public class Inventar
OnChanged?.Invoke();
}
// public void EquipItem( InventoryItem item )
// {
// if ( EquippedItems.ContainsValue( item ) )
// {
// UnEquipItem( item );
// }
// else
// {
// EquippedItems.Add( item.Definition.Slot, item );
// OnEquipped?.Invoke( item );
// }
// }
public void EquipItem( InventoryItem item )
{
if ( item.Definition is not IEquipable equipable ) return;
if ( EquippedItems.ContainsValue( item ) )
{
UnEquipItem( item );
}
else
{
EquippedItems.Add( item.Definition.Slot, item );
EquippedItems[equipable.Slot] = item;
OnEquipped?.Invoke( item );
}
}

View File

@@ -4,12 +4,7 @@ namespace Sasalka;
public class InventoryItem : Component
{
public InventoryItemDefinition Definition { get; set; }
public BaseItemDefinition Definition { get; set; }
public int Count { get; set; } = 1;
public int MaxCount { get; set; } = 1;
// public GameObject SpawnedObject { get; set; }
}
// public int Count { get; set; } = 1;
// public int MaxCount { get; set; } = 1;

View File

@@ -18,22 +18,22 @@ public sealed partial class Dedugan : Component
Inventory.AddItem( new InventoryItem
{
Definition = ResourceLibrary.Get<InventoryItemDefinition>( "Items/Pijama.inv" )
Definition = ResourceLibrary.Get<ClothingItemDefinition>( "Items/cloth_pijama.clitem" )
} );
// Inventory.AddItem( new InventoryItem
// {
// Definition = ResourceLibrary.Get<BaseItemDefinition>( "Items/shorts_1.inv" )
// } );
Inventory.AddItem( new InventoryItem
{
Definition = ResourceLibrary.Get<InventoryItemDefinition>( "Items/shorts_1.inv" )
} );
Inventory.AddItem( new InventoryItem
{
Definition = ResourceLibrary.Get<InventoryItemDefinition>( "Items/pistol.inv" )
Definition = ResourceLibrary.Get<WeaponItemDefinition>( "Items/pistol_test.weapon" )
} );
var ammo = new InventoryItem
{
Definition = ResourceLibrary.Get<InventoryItemDefinition>( "Items/pistol_ammo.inv" )
Definition = ResourceLibrary.Get<BaseItemDefinition>( "Items/pistol_ammo.inv" )
};
ammo.Count = 30;
ammo.MaxCount = 130;
@@ -46,17 +46,16 @@ public sealed partial class Dedugan : Component
private void OnItemEquipped( InventoryItem item )
{
if ( item.Definition.Prefab.IsValid() )
// Если это оружие
if ( item.Definition is WeaponItemDefinition weaponDef && weaponDef.Prefab.IsValid() )
{
var go = item.Definition.Prefab.Clone();
var go = weaponDef.Prefab.Clone();
AnimationHelper.HoldType = item.Definition.HoldType;
AnimationHelper.HoldType = weaponDef.HoldType;
switch ( item.Definition.Slot )
switch ( weaponDef.Slot )
{
case Inventar.InventorySlot.LeftHand | Inventar.InventorySlot.RightHand:
go.Parent = Renderer.GetAttachmentObject( "hold_R" );
break;
case Inventar.InventorySlot.RightHand:
go.Parent = Renderer.GetAttachmentObject( "hold_R" );
break;
@@ -68,12 +67,12 @@ public sealed partial class Dedugan : Component
break;
}
go.LocalPosition = item.Definition.WeaponDefinition.Position;
go.LocalRotation = item.Definition.WeaponDefinition.Rotation;
go.LocalPosition = weaponDef.WeaponDefinition.Position;
go.LocalRotation = weaponDef.WeaponDefinition.Rotation;
go.NetworkSpawn();
var hand = item.Definition.Slot switch
var hand = weaponDef.Slot switch
{
Inventar.InventorySlot.LeftHand => CitizenAnimationHelper.Hand.Left,
Inventar.InventorySlot.RightHand => CitizenAnimationHelper.Hand.Right,
@@ -81,37 +80,34 @@ public sealed partial class Dedugan : Component
_ => CitizenAnimationHelper.Hand.Both
};
AnimationHelper.HoldType = item.Definition.HoldType;
AnimationHelper.Handedness = hand;
RpcSetHoldAnimation( item.Definition.HoldType, hand );
RpcSetHoldAnimation( weaponDef.HoldType, hand );
InAds = true;
// item.SpawnedObject = go;
}
else
// Если это одежда
else if ( item.Definition is ClothingItemDefinition clothingDef )
{
WearWorkshop( new List<string>() { item.Definition.ClothUrl } );
WearWorkshop( new List<string>() { clothingDef.ClothUrl } );
}
}
private void OnItemUnEquipped( InventoryItem item )
{
if ( item.Definition.Prefab.IsValid() )
if ( item.Definition is WeaponItemDefinition weaponDef && weaponDef.Prefab.IsValid() )
{
switch ( item.Definition.Slot )
switch ( weaponDef.Slot )
{
case Inventar.InventorySlot.LeftHand | Inventar.InventorySlot.RightHand:
case Inventar.InventorySlot.RightHand:
case Inventar.InventorySlot.LeftHand:
var attachmentName = !item.Definition.Slot.HasFlag( Inventar.InventorySlot.RightHand )
var attachmentName = !weaponDef.Slot.HasFlag( Inventar.InventorySlot.RightHand )
? "hold_L"
: "hold_R";
Renderer.GetAttachmentObject( attachmentName ).Children.ForEach( child => child.Destroy() );
// AnimationHelper.Handedness = CitizenAnimationHelper.Hand.Both;
// AnimationHelper.HoldType = CitizenAnimationHelper.HoldTypes.None;
RpcSetHoldAnimation( CitizenAnimationHelper.HoldTypes.None, CitizenAnimationHelper.Hand.Both );
break;
default:
@@ -120,15 +116,12 @@ public sealed partial class Dedugan : Component
break;
}
// item.SpawnedObject = null;
item.Destroy();
InAds = false;
}
else
else if ( item.Definition is ClothingItemDefinition clothingDef )
{
Log.Info( "STRIPPIN" );
StripByName( item.Definition.Name );
StripByName( clothingDef.Name );
}
}

View File

@@ -81,27 +81,24 @@ partial class Dedugan
CancellationTokenSource _cts;
[Rpc.Broadcast]
public async void WearWorkshop( List<string> workshopItems )
public void WearWorkshop( List<string> workshopItems )
{
_cts = new CancellationTokenSource();
var token = _cts.Token;
// var clothing = new ClothingContainer();
// clothing.AddRange( Clothings );
if ( workshopItems != null && workshopItems.Count > 0 )
{
var tasks = workshopItems.Select( x => InstallWorkshopClothing( x, token ) );
Task.WhenAll( workshopItems.Select( x => InstallWorkshopClothing( x, token ) ) )
.ContinueWith( ( tasks ) =>
{
foreach ( var cloth in tasks.Result )
{
if ( cloth is null )
continue;
foreach ( var task in tasks )
{
var c = await task;
if ( c is null )
continue;
CurrentClothing.Add( c );
}
CurrentClothing.Add( cloth );
}
} );
}
CurrentClothing.Normalize();
@@ -109,6 +106,31 @@ partial class Dedugan
Renderer.PostAnimationUpdate();
}
// public async void AsyncWearWorkshop( List<string> workshopItems )
// {
// _cts = new CancellationTokenSource();
// var token = _cts.Token;
//
// if ( workshopItems != null && workshopItems.Count > 0 )
// {
// var tasks = workshopItems.Select( x => InstallWorkshopClothing( x, token ) );
//
// foreach ( var task in tasks )
// {
// var c = await task;
//
// if ( c is null )
// continue;
//
// CurrentClothing.Add( c );
// }
// }
//
// CurrentClothing.Normalize();
// CurrentClothing.Apply( Renderer );
// Renderer.PostAnimationUpdate();
// }
[Rpc.Broadcast]
public void StripByName( string name )
{