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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-01 19:14:34 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Spawns this item as an <see cref="ItemPickup3D"/> in the 3D world.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sibling">Reference node used to determine parent and default spawn position.</param>
|
|
|
|
|
|
/// <param name="dropAsChild">If true, spawns as a child of <paramref name="sibling"/>; otherwise as a sibling.</param>
|
|
|
|
|
|
/// <param name="spawnPosition">
|
|
|
|
|
|
/// Optional world-space position override. When null, the position of <paramref name="sibling"/> is used.
|
|
|
|
|
|
/// Pass a custom value to scatter drops instead of stacking them all at the same point.
|
|
|
|
|
|
/// </param>
|
|
|
|
|
|
/// <param name="launchVelocity">Optional initial velocity applied to the pickup so it arcs and falls to the floor.</param>
|
|
|
|
|
|
public ItemPickup3D Spawn3D(Node3D sibling, bool dropAsChild = false, Vector3? spawnPosition = null, Vector3? launchVelocity = null)
|
2025-06-17 17:49:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
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;
|
2026-03-01 19:14:34 +01:00
|
|
|
|
|
|
|
|
|
|
var position = spawnPosition ?? sibling.GlobalPosition;
|
|
|
|
|
|
|
2025-06-17 17:49:40 +02:00
|
|
|
|
if (dropAsChild)
|
|
|
|
|
|
{
|
2026-03-01 19:14:34 +01:00
|
|
|
|
CallDeferred(MethodName.DeferredSpawn3D, sibling, spawnedItem, position);
|
2025-06-17 17:49:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-03-01 19:14:34 +01:00
|
|
|
|
CallDeferred(MethodName.DeferredSpawn3D, sibling.GetParentNode3D(), spawnedItem, position);
|
2025-06-17 17:49:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-01 10:04:15 +02:00
|
|
|
|
spawnedItem.LootTable.Add(this);
|
|
|
|
|
|
spawnedItem.SetSprite(InventorySprite);
|
|
|
|
|
|
|
2026-03-01 19:14:34 +01:00
|
|
|
|
if (launchVelocity.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
spawnedItem.Launch(launchVelocity.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-01 10:04:15 +02:00
|
|
|
|
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
|
|
|
|
}
|