44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class Chest : Inventory, IInteractable
|
|
{
|
|
private bool isLooted = false;
|
|
|
|
// This method is required by the IInteractable interface.
|
|
// It will display a prompt when the player hovers over the chest.
|
|
public string GetInteractPrompt()
|
|
{
|
|
if (isLooted)
|
|
return "Empty";
|
|
else
|
|
return "Open Chest";
|
|
}
|
|
|
|
// This method is also required by IInteractable.
|
|
// It runs when the player clicks on the chest.
|
|
public void OnInteract()
|
|
{
|
|
// If the chest has already been looted, do nothing.
|
|
if (isLooted) return;
|
|
|
|
Debug.Log("Looting chest...");
|
|
|
|
// This logic is similar to your LootDrop script.
|
|
// It iterates through the chest's items and adds them to the player's inventory.
|
|
foreach (var item in items)
|
|
{
|
|
PlayerInventory.instance.AddItem(item.Key, item.Value);
|
|
}
|
|
|
|
// Add the chest's gold to the player.
|
|
if (Gold > 0)
|
|
{
|
|
PlayerInventory.instance.AddItem("Gold", Gold);
|
|
}
|
|
|
|
// Mark the chest as looted to prevent it from being opened again.
|
|
isLooted = true;
|
|
|
|
// Optional: You could play an "open" animation or sound effect here.
|
|
}
|
|
} |