mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
68 lines
1.5 KiB
C#
68 lines
1.5 KiB
C#
|
|
using System.Linq;
|
|||
|
|
using Cirno.Scripts.Resources;
|
|||
|
|
using Godot;
|
|||
|
|
using Godot.Collections;
|
|||
|
|
|
|||
|
|
namespace Cirno.Scripts.Interactables;
|
|||
|
|
|
|||
|
|
public partial class ItemPickup3D : Interactable3D
|
|||
|
|
{
|
|||
|
|
[Export] public Array<LootItem> LootTable = [];
|
|||
|
|
|
|||
|
|
private bool _autoPickup = false;
|
|||
|
|
|
|||
|
|
public bool AutoPickup => _autoPickup;
|
|||
|
|
|
|||
|
|
public override void _Ready()
|
|||
|
|
{
|
|||
|
|
_autoPickup = LootTable.Any(x => x.AutoPickup);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
|||
|
|
{
|
|||
|
|
if (!MeetsRequirements()) return false;
|
|||
|
|
Collect();
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void AddItemsToInventory()
|
|||
|
|
{
|
|||
|
|
var failedItems = new Array<LootItem>();
|
|||
|
|
foreach (var item in LootTable)
|
|||
|
|
{
|
|||
|
|
if (!InventoryManager.Instance.AddItem(item))
|
|||
|
|
{
|
|||
|
|
failedItems.Add(item);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (failedItems.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (var failedItem in failedItems)
|
|||
|
|
{
|
|||
|
|
var dup = this.Duplicate() as ItemPickup;
|
|||
|
|
this.AddSibling(dup);
|
|||
|
|
dup.LootTable = [failedItem];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Delet This
|
|||
|
|
|
|||
|
|
QueueFree();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Collect()
|
|||
|
|
{
|
|||
|
|
AddItemsToInventory();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SetSprite(Texture2D sprite)
|
|||
|
|
{
|
|||
|
|
var spriteNode = GetNodeOrNull<Sprite3D>("Sprite3D");
|
|||
|
|
if (spriteNode is null) return;
|
|||
|
|
spriteNode.Texture = sprite;
|
|||
|
|
}
|
|||
|
|
}
|