create base item SO for container. still need to set container type for different item types (sellable or not)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class CashierDesk : BaseInteractableObject
|
||||
@@ -6,17 +5,18 @@ public class CashierDesk : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = player.GetContainerItem();
|
||||
var playerItemsList = playerContainer.GetItems();
|
||||
player.ClearContainerItem();
|
||||
if (playerItemsList.Any())
|
||||
if (playerContainer.IsSalebleItems())
|
||||
{
|
||||
var playerItemsList = playerContainer.GetItems();
|
||||
player.ClearContainerItem();
|
||||
float finalPrice = 0;
|
||||
foreach (var item in playerItemsList)
|
||||
foreach (SellableItemSO item in playerItemsList)
|
||||
{
|
||||
finalPrice += item.Price;
|
||||
}
|
||||
@@ -29,7 +29,14 @@ public class CashierDesk : BaseInteractableObject
|
||||
return;
|
||||
}
|
||||
player.Pay(finalPrice);
|
||||
containerItem.AddItems(playerItemsList);
|
||||
foreach (var item in playerContainer.GetItems())
|
||||
{
|
||||
|
||||
var foodItemSO = ScriptableObject.CreateInstance<FoodItemSO>();
|
||||
foodItemSO.ItemName = item.ItemName;
|
||||
foodItemSO.Energy = 0;
|
||||
containerItem.AddItem(foodItemSO);
|
||||
}
|
||||
player.SetContainerItem(containerItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,29 @@ public class Fridge : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private ItemActionsUI _actionsMenu;
|
||||
|
||||
private List<FoodItem> _foodObjects = new List<FoodItem>();
|
||||
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = player.GetContainerItem();
|
||||
if (!playerContainer.IsSalebleItems())
|
||||
{
|
||||
if (_foodObjects.Count + playerContainer.GetItems().Count <= _containerSO.MaxCapacity)
|
||||
{
|
||||
foreach (FoodItemSO item in playerContainer.GetItems())
|
||||
{
|
||||
_foodObjects.Add(item);
|
||||
}
|
||||
|
||||
//_actionsMenu.Show(_containerSO.Name, $"Max items:{_containerSO.MaxCapacity} current items: {_containerSO.CurrentItemsCount}");
|
||||
//if (player.IsHoldContainer())
|
||||
//{
|
||||
// if (_foodObjects.Count < _containerSO.MaxCapacity)
|
||||
// {
|
||||
// _foodObjects.Add(player.GetFoodObject());
|
||||
// player.ClearFoodObject();
|
||||
// Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||
// }
|
||||
// else
|
||||
// Debug.Log($"Fridge is full");
|
||||
//}
|
||||
player.ClearContainerItem();
|
||||
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||
}
|
||||
else
|
||||
Debug.Log($"Fridge is full");
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// //Eat menu
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ContainerItem : MonoBehaviour
|
||||
@@ -7,19 +8,14 @@ public class ContainerItem : MonoBehaviour
|
||||
private ContainerSO _containerSO;
|
||||
|
||||
|
||||
private List<SellableItemSO> _items;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_items = new List<SellableItemSO>();
|
||||
}
|
||||
private List<BaseItemSO> _items = new List<BaseItemSO>();
|
||||
|
||||
public ContainerSO GetContainerObjectSO()
|
||||
{
|
||||
return _containerSO;
|
||||
}
|
||||
|
||||
public void AddItem(SellableItemSO item)
|
||||
public void AddItem(BaseItemSO item)
|
||||
{
|
||||
if (_items.Count < _containerSO.MaxCapacity)
|
||||
{
|
||||
@@ -32,8 +28,22 @@ public class ContainerItem : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public List<SellableItemSO> GetItems()
|
||||
public List<BaseItemSO> GetItems()
|
||||
{
|
||||
return _items;
|
||||
}
|
||||
|
||||
public bool IsSalebleItems()
|
||||
{
|
||||
return _items.Any(x => x is SellableItemSO);
|
||||
}
|
||||
|
||||
public void AddItems(List<BaseItemSO> playerItemsList)
|
||||
{
|
||||
foreach (var item in playerItemsList)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
public class FoodItem
|
||||
public class FoodItemSO : BaseItemSO
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Energy { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user