player can work now
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
public enum JobPositions { Unemployed, Clerk, ManagerAssistaint, Manager };
|
||||
public enum PlayerStates { Awake, Sleeping, Eating }
|
||||
public enum PlayerStates { Awake, Sleeping, Eating,Working }
|
||||
public enum StatsId { Money, RentAccount, Food, Energy, BankAccount, Job, }
|
||||
public enum Tasks { Move, Interact, Rotate };
|
||||
public enum TaskStatus { Waiting, InProgress, Complete };
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Player : MonoBehaviour
|
||||
private AnimationStates _currentAnimation;
|
||||
|
||||
public Dictionary<StatsId, Stat> Stats;
|
||||
public JobPositions JobPosition { get; set; }
|
||||
|
||||
private readonly Queue<PlayerTasks> _tasks = new Queue<PlayerTasks>();
|
||||
private PlayerTasks _currentTask;
|
||||
@@ -43,6 +44,8 @@ public class Player : MonoBehaviour
|
||||
PlayerPrefs.SetString("lastExitName", string.Empty);
|
||||
Instance = this;
|
||||
Stats = PlayerStats.CreateInitialStats();
|
||||
JobPosition = JobPositions.Unemployed;
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
@@ -227,6 +230,11 @@ public class Player : MonoBehaviour
|
||||
Stats[StatsId.Money].deduct(amount);
|
||||
}
|
||||
|
||||
public void AddMoney(float amount)
|
||||
{
|
||||
Stats[StatsId.Money].increase(amount);
|
||||
}
|
||||
|
||||
public void SetContainerItem(ContainerItem containerItem)
|
||||
{
|
||||
containerItem.transform.parent = _holdPoint;
|
||||
|
||||
@@ -10,11 +10,11 @@ public class PlayerStats
|
||||
{StatsId.Money, new Stat("Money", 100.0f,10000000f)},
|
||||
{StatsId.RentAccount, new Stat("Rent Account", 0,10f)},
|
||||
{StatsId.Food, new Stat("Food Energy", 50f,100f) },
|
||||
{StatsId.Energy,new Stat("Energy", 50f,100f) },
|
||||
//{StatsId.BankAccount,new Stat("Bank Account", 0) },
|
||||
{StatsId.Job, new Stat("Unemployed", 0, 100f) },
|
||||
{StatsId.Energy,new Stat("Energy", 50f,100f) },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//// Knowledge for University Jobs
|
||||
//public Stat literatureKnowledge = new Stat("LiteratureKnowledge", 0);
|
||||
//public Stat mathematicsKnowledge = new Stat("MathematicsKnowledge", 0);
|
||||
|
||||
@@ -23,7 +23,7 @@ public class JobSelectorUI : MonoBehaviour
|
||||
[SerializeField]
|
||||
private JobsListSO _jobs;
|
||||
|
||||
public void ShowJobSelectionDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
public void ShowJobSelectionDialog(string title, string description, Action onCancel, Action onConfirm)
|
||||
{
|
||||
UIManager.Instance.Freeze();
|
||||
|
||||
@@ -42,10 +42,10 @@ public class JobSelectorUI : MonoBehaviour
|
||||
{
|
||||
onCancel?.Invoke();
|
||||
Hide();
|
||||
CloseDialog();
|
||||
});
|
||||
_btnOk.onClick.AddListener(() =>
|
||||
{
|
||||
onConfirm?.Invoke();
|
||||
Hide();
|
||||
});
|
||||
}
|
||||
@@ -58,6 +58,7 @@ public class JobSelectorUI : MonoBehaviour
|
||||
private void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
CloseDialog();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public class TimeSliderUI : MonoBehaviour
|
||||
[SerializeField]
|
||||
private Slider _slider;
|
||||
|
||||
private TimeSpan _time;
|
||||
public void ShowTimeSliderDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
{
|
||||
TimeManager.Instance.OnFastForwardEnd += CloseDialog;
|
||||
@@ -34,7 +35,7 @@ public class TimeSliderUI : MonoBehaviour
|
||||
});
|
||||
_btnOk.onClick.AddListener(() =>
|
||||
{
|
||||
onConfirm?.Invoke(TimeSpan.FromSeconds(_slider.value));
|
||||
onConfirm?.Invoke(_time);
|
||||
Hide();
|
||||
});
|
||||
|
||||
@@ -52,9 +53,9 @@ public class TimeSliderUI : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var time = TimeSpan.FromSeconds(_slider.value);
|
||||
_time = TimeSpan.FromHours(_slider.value);
|
||||
|
||||
_description.text = $"{time.Hours} hours {time.Minutes} minutes";
|
||||
_description.text = $"{_time.Hours} hours";
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
|
||||
@@ -32,7 +32,7 @@ public class UIManager : MonoBehaviour
|
||||
timeSlider.ShowTimeSliderDialog(title, description, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void ShowJobSelectionDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
public void ShowJobSelectionDialog(string title, string description, Action onCancel, Action onConfirm)
|
||||
{
|
||||
var jobSelector = Instantiate(_jobSelectorPrefab, transform);
|
||||
jobSelector.ShowJobSelectionDialog(title, description, onCancel, onConfirm);
|
||||
|
||||
Reference in New Issue
Block a user