player can work now
This commit is contained in:
@@ -1,52 +1,88 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class CashierDesk : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
[SerializeField]
|
||||
private JobInfoSO _jobInfo;
|
||||
|
||||
//_optionsList.Add("Hamburgers - 83$", new Eat(6, 10, 83));
|
||||
//_optionsList.Add("Cheesburger - 94$", new Eat(6, 1, 94));
|
||||
//_optionsList.Add("Astro chicken - 131$", new Eat(6, 1, 131));
|
||||
//_optionsList.Add("Fries - 68$", new Eat(6, 1, 68));
|
||||
//_optionsList.Add("Shakes - 108$", new Eat(6, 1, 108));
|
||||
//_optionsList.Add("Colas - 73$", new Eat(6, 1, 73));
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
base.Interact(player);
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = player.GetContainerItem();
|
||||
if (playerContainer.IsSalebleItems())
|
||||
BuyItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
// if player work here
|
||||
if (player.JobPosition == _jobInfo.JobPosition)
|
||||
{
|
||||
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);
|
||||
UIManager.Instance.ShowTimeSliderDialog($"Work", $"Work as {_jobInfo.Description}", OnCancel, OnConfirm);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print("You don't work here");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuyItems()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCancel()
|
||||
{
|
||||
OnFastForwardEnd();
|
||||
}
|
||||
|
||||
float _totalSalary;
|
||||
private void OnConfirm(TimeSpan time)
|
||||
{
|
||||
_totalSalary = (float)(time.TotalHours * _jobInfo.Salary);
|
||||
_player.SetPlayerActing(PlayerStates.Working);
|
||||
TimeManager.Instance.FastForward(time);
|
||||
TimeManager.Instance.OnFastForwardEnd += OnFastForwardEnd;
|
||||
}
|
||||
|
||||
private void OnFastForwardEnd()
|
||||
{
|
||||
_player.AddMoney(_totalSalary);
|
||||
_player.SetPlayerActing(PlayerStates.Awake);
|
||||
TimeManager.Instance.OnFastForwardEnd -= OnFastForwardEnd;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user