47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
public class CashierDesk : BaseInteractableObject
|
|
{
|
|
[SerializeField]
|
|
private ContainerSO _containerSO;
|
|
|
|
|
|
public override void Interact(Player player)
|
|
{
|
|
if (player.IsHoldContainerItem())
|
|
{
|
|
var playerContainer = player.GetContainerItem();
|
|
if (playerContainer.IsSalebleItems())
|
|
{
|
|
var playerItemsList = playerContainer.GetItems();
|
|
player.ClearContainerItem();
|
|
float finalPrice = 0;
|
|
foreach (SellableItemSO item in playerItemsList)
|
|
{
|
|
finalPrice += item.Price;
|
|
}
|
|
|
|
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
|
|
var containerItem = transform.GetComponent<ContainerItem>();
|
|
if (containerItem == null)
|
|
{
|
|
Debug.LogError("Container Item is null");
|
|
return;
|
|
}
|
|
player.Pay(finalPrice);
|
|
foreach (var item in playerContainer.GetItems())
|
|
{
|
|
|
|
var foodItemSO = ScriptableObject.CreateInstance<FoodItemSO>();
|
|
foodItemSO.ItemName = item.ItemName;
|
|
foodItemSO.Energy = 0;
|
|
containerItem.AddItem(foodItemSO);
|
|
}
|
|
player.SetContainerItem(containerItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|