stack item pickup (in progress), throwable hand consumes items, spawnable objects tied to item definitions

This commit is contained in:
2026-09-16 22:48:52 -05:00
parent d8295719b0
commit f4642ea005
17 changed files with 444 additions and 26 deletions
+53 -8
View File
@@ -8,7 +8,8 @@ public class ThrowableHand : Tool
public float range;
public float forceModifier;
public float loft;
public GameObject testBomb;
public ItemIdEnum activeThrowable;
private int activeThrowableIndex;
// Mathematical plane used to catch the raycast from camera to get direction for
// looking at the mouse
@@ -89,20 +90,64 @@ private void DrawTargetProjection()
targetProjection.transform.position = finalPosition;
}
private ItemIdEnum GetNextThrowable()
{
// Use active throwable index to let us continue to search for throwables
if (activeThrowableIndex >= GameManager.Instance.Inventory.itemSlots.Length)
activeThrowableIndex = 0;
// Search starting at throwable index
for (int i = activeThrowableIndex; i < GameManager.Instance.Inventory.itemSlots.Length; i++)
{
if (ItemUtilities.GetItemFromId(GameManager.Instance.Inventory.itemSlots[i].item).throwable)
{
activeThrowableIndex = i;
return GameManager.Instance.Inventory.itemSlots[i].item;
}
}
// Wrap back around to 0 if we didn't find anything
for (int i = 0; i < activeThrowableIndex; i++)
{
if (ItemUtilities.GetItemFromId(GameManager.Instance.Inventory.itemSlots[i].item).throwable)
{
activeThrowableIndex = i;
return GameManager.Instance.Inventory.itemSlots[i].item;
}
}
// We have no throwable items...
activeThrowableIndex = 0;
return ItemIdEnum.NONE;
}
public override void Use()
{
GameObject newBomb = Instantiate(testBomb);
newBomb.transform.position = transform.position;
if (activeThrowable == ItemIdEnum.NONE)
{
activeThrowable = GetNextThrowable();
}
Vector3 direction = transform.forward * throwForce * forceModifier;
direction += GameManager.Instance.PlayerController.GetVelocity();
direction.y = loft;
if (activeThrowable != ItemIdEnum.NONE && GameManager.Instance.Inventory.GetItemQuantity(activeThrowable) > 0)
{
GameObject throwable = Instantiate(GameManager.Instance.ItemInstantiationManager.GetThrowablePrefab(activeThrowable));
newBomb.GetComponent<Rigidbody>().AddForce(direction, ForceMode.Impulse);
if (throwable != null)
{
throwable.transform.position = transform.position;
Vector3 direction = transform.forward * throwForce * forceModifier;
direction += GameManager.Instance.PlayerController.GetVelocity();
direction.y = loft;
throwable.GetComponent<Rigidbody>().AddForce(direction, ForceMode.Impulse);
GameManager.Instance.Inventory.RemoveItemQuantity(activeThrowable, 1);
}
}
}
public override void UseAlt()
{
throw new System.NotImplementedException();
activeThrowable = GetNextThrowable();
}
}