player can work now
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
using UnityEngine;
|
||||
using static UnityEditor.Experimental.GraphView.GraphView;
|
||||
|
||||
public class BaseInteractableObject : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public Transform _interactionPoint;
|
||||
|
||||
protected Player _player;
|
||||
public virtual void Interact(Player player)
|
||||
{
|
||||
Debug.Log("Interact with some object");
|
||||
_player=player;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ using System;
|
||||
|
||||
public class Bed : BaseInteractableObject
|
||||
{
|
||||
private Player _player;
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
_player = player;
|
||||
base.Interact(player);
|
||||
_player.SetPlayerAnimation(AnimationStates.Sitting, OnAnimationFinished);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Door : BaseInteractableObject
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
print($"Player go to {_scene}");
|
||||
base.Interact(player);
|
||||
if (!string.IsNullOrEmpty(_exitName))
|
||||
{
|
||||
PlayerPrefs.SetString("lastExitName", _exitName.ToLower());
|
||||
|
||||
@@ -9,13 +9,12 @@ public class Fridge : BaseInteractableObject
|
||||
private ContainerSO _containerSO;
|
||||
[SerializeField]
|
||||
//private ItemActionsUI _actionsMenu;
|
||||
|
||||
private Player _player;
|
||||
|
||||
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
_player = player;
|
||||
base.Interact(player);
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = player.GetContainerItem();
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using static UnityEditor.Experimental.GraphView.GraphView;
|
||||
|
||||
public class OfficeTable : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private JobsListSO _jobPositionsSO;
|
||||
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
UIManager.Instance.ShowJobSelectionDialog("Job agency", "job offers", null, null);
|
||||
base.Interact(player);
|
||||
UIManager.Instance.ShowJobSelectionDialog("Job agency", "job offers", null, OnConfirm);
|
||||
}
|
||||
|
||||
|
||||
private void OnConfirm()
|
||||
{
|
||||
_player.JobPosition = JobPositions.Clerk;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public class ShopingContainer : BaseInteractableObject
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
base.Interact(player);
|
||||
if (!player.IsHoldContainerItem())
|
||||
{
|
||||
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
|
||||
|
||||
@@ -8,6 +8,7 @@ public class StoreContainer : BaseInteractableObject
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
base.Interact(player);
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var clone = Instantiate(_sellableItemSO);
|
||||
|
||||
Reference in New Issue
Block a user