mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 08:15:53 +00:00
Box models and item drops
This commit is contained in:
parent
cc9c4e5aa1
commit
2fe9618942
132 changed files with 9210 additions and 999 deletions
68
Scripts/Interactables/ItemPickup3D.cs
Normal file
68
Scripts/Interactables/ItemPickup3D.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
1
Scripts/Interactables/ItemPickup3D.cs.uid
Normal file
1
Scripts/Interactables/ItemPickup3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cc60s31w2sive
|
||||
Loading…
Add table
Add a link
Reference in a new issue