mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 08:45:54 +00:00
Enhanced loot drops system
This commit is contained in:
parent
ddde409dbf
commit
acc61f9a0e
12 changed files with 661 additions and 443 deletions
|
|
@ -55,31 +55,43 @@ public partial class LootItem : Resource
|
|||
return spawnedItem;
|
||||
}
|
||||
|
||||
public ItemPickup3D Spawn3D(Node3D sibling, bool dropAsChild = false)
|
||||
/// <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)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(DropScenePath3D)) return null;
|
||||
var itemScene = GD.Load<PackedScene>(DropScenePath3D);
|
||||
|
||||
var spawnedItem = itemScene.Instantiate<ItemPickup3D>();
|
||||
spawnedItem.Name = this.ItemKey;
|
||||
|
||||
var position = spawnPosition ?? sibling.GlobalPosition;
|
||||
|
||||
if (dropAsChild)
|
||||
{
|
||||
CallDeferred(MethodName.DeferredSpawn3D, sibling, spawnedItem, sibling.GlobalPosition);
|
||||
//sibling.CallDeferred(Node.MethodName.AddChild, spawnedItem);
|
||||
//sibling.AddChild(spawnedItem);
|
||||
CallDeferred(MethodName.DeferredSpawn3D, sibling, spawnedItem, position);
|
||||
}
|
||||
else
|
||||
{
|
||||
CallDeferred(MethodName.DeferredSpawn3D, sibling.GetParentNode3D(), spawnedItem, sibling.GlobalPosition);
|
||||
//sibling.GetParent().CallDeferred(Node.MethodName.AddChild, spawnedItem);
|
||||
//sibling.GetParent().AddChild(spawnedItem);
|
||||
CallDeferred(MethodName.DeferredSpawn3D, sibling.GetParentNode3D(), spawnedItem, position);
|
||||
}
|
||||
|
||||
//spawnedItem.GlobalPosition = sibling.GlobalPosition;
|
||||
|
||||
spawnedItem.LootTable.Add(this);
|
||||
spawnedItem.SetSprite(InventorySprite);
|
||||
|
||||
if (launchVelocity.HasValue)
|
||||
{
|
||||
spawnedItem.Launch(launchVelocity.Value);
|
||||
}
|
||||
|
||||
return spawnedItem;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue