mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
91 lines
No EOL
3.2 KiB
C#
91 lines
No EOL
3.2 KiB
C#
using Cirno.Scripts.Interactables;
|
|
using Cirno.Scripts.Resources.ItemEffects;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Resources;
|
|
|
|
[GlobalClass]
|
|
[Tool]
|
|
public partial class LootItem : Resource
|
|
{
|
|
[Export] public StringName ItemName { get; set; }
|
|
[Export] public StringName ShortName { get; set; }
|
|
[Export] public StringName ItemDescription { get; set; }
|
|
[Export] public StringName ItemKey { get; set; }
|
|
[Export] public ItemTypes Item;
|
|
[Export] public int Tier { get; set; } = 0;
|
|
[Export] public int Price { get; set; }
|
|
[Export] public ItemEffectResource ItemEffect { get; private set; }
|
|
[Export] public WeaponResource WeaponData { get; set; }
|
|
[Export] public WeaponResource WeaponData3D { get; set; }
|
|
[Export] public int Amount;
|
|
[Export] public int Max;
|
|
[Export] public bool PickupIfMaxed;
|
|
[Export] public bool ConsumeOnUse;
|
|
|
|
[Export(PropertyHint.Flags, "Icon,Count,Ammo,Energy")]
|
|
public UiItemType UiType { get; set; } = 0;
|
|
|
|
[Export] public bool Selectable;
|
|
[Export] public bool AutoPickup { get; private set; } = false;
|
|
|
|
[Export] public Texture2D InventorySprite;
|
|
|
|
//[Export] public SpriteFrames WorldSprite;
|
|
//[Export] public PackedScene HudItemScene;
|
|
[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
|
|
|
|
public ItemPickup Spawn(Node2D sibling, bool dropAsChild = false)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(DropScenePath)) return null;
|
|
var itemScene = GD.Load<PackedScene>(DropScenePath);
|
|
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>();
|
|
spawnedItem.Name = this.ItemKey;
|
|
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;
|
|
|
|
spawnedItem.LootTable.Add(this);
|
|
spawnedItem.SetSprite(InventorySprite);
|
|
|
|
return spawnedItem;
|
|
}
|
|
|
|
private void DeferredSpawn3D(Node3D parent, Node3D instance, Vector3 position)
|
|
{
|
|
parent.AddChild(instance);
|
|
instance.GlobalPosition = position;
|
|
}
|
|
} |