mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Dropping and picking up
This commit is contained in:
parent
488d02ef81
commit
bcd007fa1e
14 changed files with 294 additions and 62 deletions
|
|
@ -2,15 +2,21 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using GTweens.Builders;
|
||||
using GTweensGodot.Extensions;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class ItemPickup : Interactable
|
||||
{
|
||||
[Export] public Array<LootItem> LootTable = [];
|
||||
|
||||
|
||||
private bool _autoPickup = false;
|
||||
|
||||
|
||||
public bool AutoPickup => _autoPickup;
|
||||
|
||||
public ItemDrop Parent { get; set; } = null;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_autoPickup = LootTable.Any(x => x.AutoPickup);
|
||||
|
|
@ -21,18 +27,18 @@ public partial class ItemPickup : Interactable
|
|||
|
||||
//this.AreaEntered += _on_area_entered;
|
||||
}
|
||||
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
GD.Print("Attempting to Pickup Item");
|
||||
|
||||
|
||||
if (!MeetsRequirements()) return false;
|
||||
AddItemsToInventory();
|
||||
|
||||
Collect();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AddItemsToInventory()
|
||||
public void AddItemsToInventory()
|
||||
{
|
||||
var failedItems = new Array<LootItem>();
|
||||
foreach (var item in LootTable)
|
||||
|
|
@ -52,23 +58,46 @@ public partial class ItemPickup : Interactable
|
|||
dup.LootTable = [failedItem];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Delet This
|
||||
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public void Collect()
|
||||
{
|
||||
AddItemsToInventory();
|
||||
// if (Owner is ItemDrop dropWrapper)
|
||||
// {
|
||||
// // move the wrapper
|
||||
// var tween = GTweenSequenceBuilder.New()
|
||||
// .Append(dropWrapper.TweenGlobalPosition(GameManager.Instance.PlayerPosition.Value, 0.5f))
|
||||
// .AppendCallback(() =>
|
||||
// {
|
||||
// AddItemsToInventory();
|
||||
// Owner.QueueFree();
|
||||
// })
|
||||
// .Build();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // move this
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
private void _on_area_entered(Area2D area)
|
||||
{
|
||||
if (!_autoPickup) return;
|
||||
if (area is InteractionController interactionController)
|
||||
{
|
||||
//Check if items are not maxed to avoid a looping autopickup situation
|
||||
var canAdd = LootTable.Aggregate(false, (current, item) => current || InventoryManager.Instance.CanAddItem(item.ItemKey));
|
||||
|
||||
if (canAdd)
|
||||
{
|
||||
AddItemsToInventory();
|
||||
}
|
||||
}
|
||||
// if (!_autoPickup) return;
|
||||
// if (area is InteractionController interactionController)
|
||||
// {
|
||||
// //Check if items are not maxed to avoid a looping autopickup situation
|
||||
// var canAdd = LootTable.Aggregate(false, (current, item) => current || InventoryManager.Instance.CanAddItem(item.ItemKey));
|
||||
//
|
||||
// if (canAdd)
|
||||
// {
|
||||
// AddItemsToInventory();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue