2025-05-01 10:04:15 +02:00
|
|
|
|
using Cirno.Scripts.Interactables;
|
|
|
|
|
|
using Cirno.Scripts.Resources.ItemEffects;
|
2025-03-17 16:20:22 +01:00
|
|
|
|
using Godot;
|
2025-01-28 14:05:38 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Cirno.Scripts.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
[GlobalClass]
|
2025-04-28 10:52:50 +02:00
|
|
|
|
[Tool]
|
2025-01-28 14:05:38 +01:00
|
|
|
|
public partial class LootItem : Resource
|
|
|
|
|
|
{
|
2025-03-13 13:29:13 +01:00
|
|
|
|
[Export] public StringName ItemName { get; set; }
|
2025-03-28 10:29:04 +01:00
|
|
|
|
[Export] public StringName ShortName { get; set; }
|
2025-03-13 13:29:13 +01:00
|
|
|
|
[Export] public StringName ItemDescription { get; set; }
|
|
|
|
|
|
[Export] public StringName ItemKey { get; set; }
|
2025-01-28 14:05:38 +01:00
|
|
|
|
[Export] public ItemTypes Item;
|
2025-05-01 11:10:36 +02:00
|
|
|
|
[Export] public int Tier { get; set; } = 0;
|
2025-04-25 11:29:21 +02:00
|
|
|
|
[Export] public int Price { get; set; }
|
2025-03-17 16:20:22 +01:00
|
|
|
|
[Export] public ItemEffectResource ItemEffect { get; private set; }
|
2025-02-11 11:50:45 +01:00
|
|
|
|
[Export] public WeaponResource WeaponData { get; set; }
|
2025-06-18 18:09:30 +02:00
|
|
|
|
[Export] public WeaponResource WeaponData3D { get; set; }
|
2025-01-28 14:05:38 +01:00
|
|
|
|
[Export] public int Amount;
|
2025-01-30 17:24:40 +01:00
|
|
|
|
[Export] public int Max;
|
2025-01-31 13:03:38 +01:00
|
|
|
|
[Export] public bool PickupIfMaxed;
|
|
|
|
|
|
[Export] public bool ConsumeOnUse;
|
2025-05-15 20:29:02 +02:00
|
|
|
|
|
|
|
|
|
|
[Export(PropertyHint.Flags, "Icon,Count,Ammo,Energy")]
|
|
|
|
|
|
public UiItemType UiType { get; set; } = 0;
|
2025-06-17 17:49:40 +02:00
|
|
|
|
|
2025-02-25 18:11:57 +01:00
|
|
|
|
[Export] public bool Selectable;
|
2025-03-28 15:38:55 +01:00
|
|
|
|
[Export] public bool AutoPickup { get; private set; } = false;
|
2025-06-17 17:49:40 +02:00
|
|
|
|
|
2025-02-16 17:36:33 +01:00
|
|
|
|
[Export] public Texture2D InventorySprite;
|
2025-06-17 17:49:40 +02:00
|
|
|
|
|
2025-03-28 10:29:04 +01:00
|
|
|
|
//[Export] public SpriteFrames WorldSprite;
|
|
|
|
|
|
//[Export] public PackedScene HudItemScene;
|
2025-06-17 17:49:40 +02:00
|
|
|
|
[Export(PropertyHint.File)]
|
|
|
|
|
|
public StringName DropScenePath { get; private set; } // Has to be a string path to avoid recursion issues
|
|
|
|
|
|
|
|
|
|
|
|
[Export(PropertyHint.File)]
|
|
|
|
|
|
public StringName DropScenePath3D { get; private set; } // Has to be a string path to avoid recursion issues
|
2025-05-01 10:04:15 +02:00
|
|
|
|
|
2025-05-01 14:43:30 +02:00
|
|
|
|
public ItemPickup Spawn(Node2D sibling, bool dropAsChild = false)
|
2025-05-01 10:04:15 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(DropScenePath)) return null;
|
|
|
|
|
|
var itemScene = GD.Load<PackedScene>(DropScenePath);
|
2025-06-17 17:49:40 +02:00
|
|
|
|
var spawnedItem = dropAsChild
|
|
|
|
|
|
? sibling.CreateChild<ItemPickup>(itemScene)
|
|
|
|
|
|
: sibling.CreateSibling<ItemPickup>(itemScene);
|
|
|
|
|
|
|
|
|
|
|
|
spawnedItem.Name = this.ItemKey;
|
|
|
|
|
|
|
|
|
|
|
|
spawnedItem.LootTable.Add(this);
|
|
|
|
|
|
spawnedItem.SetSprite(InventorySprite);
|
|
|
|
|
|
|
|
|
|
|
|
return spawnedItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ItemPickup3D Spawn3D(Node3D sibling, bool dropAsChild = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(DropScenePath3D)) return null;
|
|
|
|
|
|
var itemScene = GD.Load<PackedScene>(DropScenePath3D);
|
|
|
|
|
|
|
|
|
|
|
|
var spawnedItem = itemScene.Instantiate<ItemPickup3D>();
|
2025-05-01 10:04:15 +02:00
|
|
|
|
spawnedItem.Name = this.ItemKey;
|
2025-06-17 17:49:40 +02:00
|
|
|
|
if (dropAsChild)
|
|
|
|
|
|
{
|
|
|
|
|
|
CallDeferred(MethodName.DeferredSpawn3D, sibling, spawnedItem, sibling.GlobalPosition);
|
|
|
|
|
|
//sibling.CallDeferred(Node.MethodName.AddChild, spawnedItem);
|
|
|
|
|
|
//sibling.AddChild(spawnedItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
CallDeferred(MethodName.DeferredSpawn3D, sibling.GetParentNode3D(), spawnedItem, sibling.GlobalPosition);
|
|
|
|
|
|
//sibling.GetParent().CallDeferred(Node.MethodName.AddChild, spawnedItem);
|
|
|
|
|
|
//sibling.GetParent().AddChild(spawnedItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//spawnedItem.GlobalPosition = sibling.GlobalPosition;
|
|
|
|
|
|
|
2025-05-01 10:04:15 +02:00
|
|
|
|
spawnedItem.LootTable.Add(this);
|
|
|
|
|
|
spawnedItem.SetSprite(InventorySprite);
|
|
|
|
|
|
|
|
|
|
|
|
return spawnedItem;
|
|
|
|
|
|
}
|
2025-06-17 17:49:40 +02:00
|
|
|
|
|
|
|
|
|
|
private void DeferredSpawn3D(Node3D parent, Node3D instance, Vector3 position)
|
|
|
|
|
|
{
|
|
|
|
|
|
parent.AddChild(instance);
|
|
|
|
|
|
instance.GlobalPosition = position;
|
|
|
|
|
|
}
|
2025-01-28 14:05:38 +01:00
|
|
|
|
}
|