182 lines
5.8 KiB
C#
182 lines
5.8 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine.EventSystems;
|
||
|
|
using UnityEngine;
|
||
|
|
using TMPro;
|
||
|
|
|
||
|
|
public enum TableState {
|
||
|
|
Empty,
|
||
|
|
Deciding, // Deciding on an order or task
|
||
|
|
ReadyToOrder, // Actively waiting for an employee
|
||
|
|
WaitingOnOrder, // Specifically for food
|
||
|
|
Escorting, // Moving to backroom. Transitions to Empty
|
||
|
|
Eating, // Transitions to Deciding or Done
|
||
|
|
WaitingOnCheck, // Interaction takes the check. Transitions to Plates
|
||
|
|
Plates // The table needs to be bussed. Transitions to Empty
|
||
|
|
}
|
||
|
|
|
||
|
|
public class TableController : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
||
|
|
{
|
||
|
|
[SerializeField] public int tableId = 0;
|
||
|
|
|
||
|
|
[SerializeField] public Transform waypoint;
|
||
|
|
|
||
|
|
[SerializeField] public Transform pornModal;
|
||
|
|
[SerializeField] public Animator pornAnimator;
|
||
|
|
|
||
|
|
// Autograb.
|
||
|
|
[HideInInspector] public List<ChairController> chairs;
|
||
|
|
|
||
|
|
[HideInInspector] public float patienceTimeStart = 0.0f;
|
||
|
|
[HideInInspector] public float maxWait = 30.0f;
|
||
|
|
|
||
|
|
// Should increase significantly with tasks.
|
||
|
|
[HideInInspector] public float tipMultiplier = 0.3f;
|
||
|
|
|
||
|
|
[HideInInspector] public List<float> remainingPatience = new List<float>();
|
||
|
|
|
||
|
|
// TODO: Implement patron actions, timeouts, etc.
|
||
|
|
|
||
|
|
// Not owned.
|
||
|
|
private GameStateController gameStateController;
|
||
|
|
|
||
|
|
[SerializeField] TextMeshPro debugText;
|
||
|
|
|
||
|
|
// Gameplay fields.
|
||
|
|
[HideInInspector] public Party party = null;
|
||
|
|
[HideInInspector] public TableState state = TableState.Empty;
|
||
|
|
[HideInInspector] public bool waiting = false;
|
||
|
|
// Mutex.
|
||
|
|
[HideInInspector] public bool servicing = false;
|
||
|
|
|
||
|
|
public void OnPointerClick(PointerEventData eventData) {
|
||
|
|
Debug.Log("I'm a table and you clicked on me!!");
|
||
|
|
gameStateController.HandleTableClick(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerEnter(PointerEventData eventData) {
|
||
|
|
Debug.Log("I'm a table and you're hovering on me!");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerExit(PointerEventData eventData) {
|
||
|
|
Debug.Log("I'm a table and you left!");
|
||
|
|
}
|
||
|
|
|
||
|
|
private void StartWait() {
|
||
|
|
waiting = true;
|
||
|
|
patienceTimeStart = Time.time;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void EndWait() {
|
||
|
|
waiting = false;
|
||
|
|
float waited = 1.0f - (Time.time - patienceTimeStart) / maxWait;
|
||
|
|
Debug.Log("Table patience remaining on complete: " + waited.ToString());
|
||
|
|
remainingPatience.Add(waited);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void ResetPatience() {
|
||
|
|
waiting = false;
|
||
|
|
remainingPatience.Clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
public int GetPay() {
|
||
|
|
if (remainingPatience.Count == 0 || party.patrons.Count == 0) {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
Debug.Log("Make dynamic based on other party stats");
|
||
|
|
float pay = party.patrons.Count
|
||
|
|
* gameStateController.baseMoneyMultiplier
|
||
|
|
/ gameStateController.difficulty;
|
||
|
|
return Mathf.FloorToInt(pay);
|
||
|
|
}
|
||
|
|
|
||
|
|
public int GetTip() {
|
||
|
|
if (remainingPatience.Count == 0 || party.patrons.Count == 0) {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
float avgPatience = 0.0f;
|
||
|
|
foreach (float p in remainingPatience) {
|
||
|
|
avgPatience += Mathf.Max(0.0f, p);
|
||
|
|
}
|
||
|
|
avgPatience /= remainingPatience.Count;
|
||
|
|
Debug.Log("Make dynamic based on party stats");
|
||
|
|
float pay = party.patrons.Count
|
||
|
|
* gameStateController.baseMoneyMultiplier
|
||
|
|
* tipMultiplier
|
||
|
|
* (1.0f - avgPatience)
|
||
|
|
/ gameStateController.difficulty;
|
||
|
|
return Mathf.FloorToInt(pay);
|
||
|
|
}
|
||
|
|
|
||
|
|
public Order GenerateOrder() {
|
||
|
|
Debug.Log("TODO: Capture event where employee picks up a ticket");
|
||
|
|
state = TableState.WaitingOnOrder;
|
||
|
|
EndWait();
|
||
|
|
StartWait();
|
||
|
|
return new Order(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
private IEnumerator DecideOnOrder() {
|
||
|
|
Debug.Log("TODO: Make order time dynamic and based on day's difficulty");
|
||
|
|
yield return new WaitForSeconds(5);
|
||
|
|
state = TableState.ReadyToOrder;
|
||
|
|
StartWait();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void AssignParty(Party p) {
|
||
|
|
party = p;
|
||
|
|
state = TableState.Deciding;
|
||
|
|
remainingPatience.Clear();
|
||
|
|
Debug.Log("Make maxWait dynamic based on Party and GameState difficulty");
|
||
|
|
maxWait = 30.0f; // 30 seconds
|
||
|
|
StartCoroutine("DecideOnOrder");
|
||
|
|
Debug.Log("TODO: Update chairs after being seated");
|
||
|
|
}
|
||
|
|
|
||
|
|
private IEnumerator FinishEating() {
|
||
|
|
Debug.Log("TODO: Make order time dynamic and based on day's difficulty");
|
||
|
|
yield return new WaitForSeconds(5);
|
||
|
|
state = TableState.WaitingOnCheck;
|
||
|
|
StartWait();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StartEating() {
|
||
|
|
EndWait();
|
||
|
|
state = TableState.Eating;
|
||
|
|
StartCoroutine("FinishEating");
|
||
|
|
Debug.Log("TODO: Update chairs to start eating");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void PickUpCheck() {
|
||
|
|
EndWait();
|
||
|
|
state = TableState.Plates;
|
||
|
|
Debug.Log("TODO: Update chairs to go yay and make money");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void CleanUpDishes() {
|
||
|
|
Debug.Log("TODO: Implement dishes or empty state depending on backroom vs escort");
|
||
|
|
state = TableState.Empty;
|
||
|
|
party = null;
|
||
|
|
ResetPatience();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Start is called before the first frame update
|
||
|
|
void Start() {
|
||
|
|
gameStateController = GameObject.FindGameObjectWithTag("GameStateController").GetComponent<GameStateController>();
|
||
|
|
chairs = new List<ChairController>(transform.GetComponentsInChildren<ChairController>());
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void LateUpdate() {
|
||
|
|
if (waiting && Time.time - patienceTimeStart > maxWait) {
|
||
|
|
// Debug.Log("TIME'S OUT, SUCKER");
|
||
|
|
}
|
||
|
|
|
||
|
|
debugText.SetText("Table: " + tableId.ToString()
|
||
|
|
+ "\nCapacity: " + chairs.Count.ToString()
|
||
|
|
+ "\nOccupancy: " + ((party == null) ? "0" : party.patrons.Count.ToString())
|
||
|
|
+ "\nTableState: " + state.ToString()
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|