2024-04-05 19:24:26 +02:00
|
|
|
using System;
|
2024-04-04 12:14:58 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-04-04 15:26:31 +02:00
|
|
|
using System.Linq;
|
2024-04-04 22:57:07 +02:00
|
|
|
using UnityEditor;
|
2024-04-04 12:14:58 +02:00
|
|
|
using UnityEngine;
|
2024-04-04 19:41:19 +02:00
|
|
|
using Utility;
|
2024-04-06 16:47:41 +02:00
|
|
|
using Microsoft.VisualStudio.Utilities;
|
2024-04-04 12:14:58 +02:00
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
public partial class GameManager : MonoBehaviourSingleton<GameManager>
|
2024-04-04 12:14:58 +02:00
|
|
|
{
|
2024-04-05 19:24:26 +02:00
|
|
|
[SerializeField] private Difficulty _difficulty = Difficulty.Medium;
|
|
|
|
|
|
|
|
public GameObject NeedFullfilledParticleEffect;
|
2024-04-07 01:22:42 +02:00
|
|
|
public GameObject ZombieDeathByDisableParticleEffect;
|
2024-04-07 03:38:32 +02:00
|
|
|
[SerializeField]
|
|
|
|
public List<GameObject> Needs = new List<GameObject>();
|
2024-04-06 16:47:41 +02:00
|
|
|
|
|
|
|
[SerializeField]
|
2024-04-07 00:09:53 +02:00
|
|
|
private Character _player;
|
2024-04-06 16:47:41 +02:00
|
|
|
|
2024-04-04 15:26:31 +02:00
|
|
|
[SerializeField]
|
2024-04-04 22:57:07 +02:00
|
|
|
private double _totalGameDurationSeconds;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
2024-04-04 15:26:31 +02:00
|
|
|
[SerializeField]
|
2024-04-04 16:33:12 +02:00
|
|
|
private double _remainingGameDurationSeconds = 0.0;
|
2024-04-04 15:26:31 +02:00
|
|
|
|
|
|
|
[SerializeField, ShowOnly]
|
|
|
|
private double _currentEfficiency = 0.0;
|
|
|
|
|
2024-04-05 19:24:26 +02:00
|
|
|
[SerializeField]
|
|
|
|
private double _generalNeedDrainScaling = 0.001;
|
|
|
|
|
2024-04-04 15:26:31 +02:00
|
|
|
[SerializeField]
|
|
|
|
private List<Developer> _developers = new();
|
2024-04-04 18:05:27 +02:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private MultiFalsableBool _gameRunning = new(false);
|
2024-04-05 19:24:26 +02:00
|
|
|
|
|
|
|
[SerializeField, Tooltip("Der Schwellwert am dem eine Benachrichtigung für das Bedürfnis ausgelöst wird.")]
|
|
|
|
private double _needNotificationThreshold = 0.25;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private DifficultySettings _difficultySettings;
|
2024-04-06 16:47:41 +02:00
|
|
|
|
|
|
|
[SerializeField]
|
2024-04-06 21:43:51 +02:00
|
|
|
private int _maxContextBufferSize = 3;
|
2024-04-06 16:47:41 +02:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private CircularBuffer<string> _contextBuffer;
|
|
|
|
|
|
|
|
public CircularBuffer<string> ContextBuffer => _contextBuffer;
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
public Difficulty Difficulty => _difficulty;
|
|
|
|
|
2024-04-05 19:24:26 +02:00
|
|
|
public double NeedNotificationThreshold => _needNotificationThreshold;
|
2024-04-06 16:47:41 +02:00
|
|
|
|
2024-04-07 00:09:53 +02:00
|
|
|
public Character Player => _player;
|
|
|
|
|
2024-04-06 16:47:41 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Die Transform des Spielers.
|
|
|
|
/// </summary>
|
|
|
|
public Transform PlayerTransform => _player.transform;
|
2024-04-05 19:24:26 +02:00
|
|
|
|
2024-04-04 15:26:31 +02:00
|
|
|
/// <summary>
|
2024-04-04 18:05:27 +02:00
|
|
|
/// Wie weit das Spiel bereits fortgeschritten ist.
|
2024-04-04 15:26:31 +02:00
|
|
|
/// </summary>
|
2024-04-04 22:57:07 +02:00
|
|
|
public double GameProgress => 1.0 - (_remainingGameDurationSeconds / _totalGameDurationSeconds);
|
2024-04-04 15:26:31 +02:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Wie Effizient das Team derzeit arbeitet.
|
|
|
|
/// </summary>
|
|
|
|
public double CurrentEfficiency => _currentEfficiency;
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-04 18:05:27 +02:00
|
|
|
/// Wie viele Sekunden das Spiel voraussichtlich noch dauern wird, würde die Effizienz sich nicht verändern.
|
2024-04-04 15:26:31 +02:00
|
|
|
/// </summary>
|
2024-04-04 16:33:12 +02:00
|
|
|
public double ExpectedRemainingGameDuration => _remainingGameDurationSeconds / _currentEfficiency;
|
2024-04-04 18:05:27 +02:00
|
|
|
|
|
|
|
public bool IsGameRunning => _gameRunning.IsTrue;
|
2024-04-04 15:26:31 +02:00
|
|
|
|
2024-04-04 16:33:12 +02:00
|
|
|
private void Start()
|
2024-04-04 18:05:27 +02:00
|
|
|
{
|
|
|
|
StartGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Startet ein neues Spiel.
|
|
|
|
/// </summary>
|
|
|
|
[ContextMenu("Start Game")]
|
|
|
|
private void StartGame()
|
2024-04-04 16:33:12 +02:00
|
|
|
{
|
2024-04-04 22:57:07 +02:00
|
|
|
TimeManager.Instance.Init();
|
|
|
|
|
2024-04-06 16:47:41 +02:00
|
|
|
_contextBuffer = new CircularBuffer<string>(_maxContextBufferSize);
|
2024-04-06 21:43:51 +02:00
|
|
|
_contextBuffer.Add("The Developer is greatful to work at this office with Gottfried");
|
|
|
|
_contextBuffer.Add("The Developer excited to develope the new game");
|
2024-04-06 16:47:41 +02:00
|
|
|
|
2024-04-05 19:24:26 +02:00
|
|
|
_difficultySettings = _difficulty.GetSettings();
|
|
|
|
|
|
|
|
_totalGameDurationSeconds = TimeManager.Instance.CalculateActualDeveloperTime(_difficultySettings, 4);
|
2024-04-04 18:05:27 +02:00
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
_remainingGameDurationSeconds = _totalGameDurationSeconds;
|
|
|
|
|
2024-04-04 18:05:27 +02:00
|
|
|
ResumeGame();
|
2024-04-04 16:33:12 +02:00
|
|
|
}
|
|
|
|
|
2024-04-04 18:05:27 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Hebt eine Pausierung auf und setzt das Spiel fort, wenn alle Pausierungen aufgehoben wurden.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Hinweis: Für jedes PauseGame muss ein ResumeGame aufgerufen werden.</remarks>
|
|
|
|
[ContextMenu("Resume Game")]
|
|
|
|
public void ResumeGame()
|
|
|
|
{
|
|
|
|
if (_gameRunning.MakeTruer())
|
|
|
|
{
|
|
|
|
InvokeRepeating(nameof(UpdateProgress), 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Pausiert das Spiel. Ist Stapelbar.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Hinweis: Für jedes PauseGame muss ein ResumeGame aufgerufen werden.</remarks>
|
|
|
|
[ContextMenu("Pause Game")]
|
|
|
|
public void PauseGame()
|
|
|
|
{
|
|
|
|
_gameRunning.MakeFalslier();
|
|
|
|
CancelInvoke(nameof(UpdateProgress));
|
|
|
|
}
|
|
|
|
|
2024-04-04 16:33:12 +02:00
|
|
|
void UpdateProgress()
|
2024-04-04 12:14:58 +02:00
|
|
|
{
|
2024-04-04 15:26:31 +02:00
|
|
|
UpdateEfficiency();
|
|
|
|
UpdateGameDuration();
|
2024-04-04 22:57:07 +02:00
|
|
|
CheckGameEndConditions();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CheckGameEndConditions()
|
|
|
|
{
|
|
|
|
if (_remainingGameDurationSeconds <= 0.0)
|
|
|
|
{
|
|
|
|
EndGame(EndGameCondition.Win_GamePublished);
|
|
|
|
}
|
|
|
|
else if (_developers.Count == 0)
|
|
|
|
{
|
|
|
|
EndGame(EndGameCondition.Lose_NoDevelopersLeft);
|
|
|
|
}
|
|
|
|
else if (TimeManager.Instance.MissedDeadline)
|
|
|
|
{
|
|
|
|
EndGame(EndGameCondition.Lose_DeadlineMissed);
|
|
|
|
}
|
2024-04-04 15:26:31 +02:00
|
|
|
}
|
|
|
|
|
2024-04-08 21:24:13 +02:00
|
|
|
[SerializeField]
|
|
|
|
private bool _won;
|
|
|
|
|
|
|
|
public bool Won => _won;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private bool _lost;
|
|
|
|
|
|
|
|
public bool Lost => _lost;
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
private void EndGame(EndGameCondition endGameCondition)
|
|
|
|
{
|
|
|
|
if (endGameCondition.IsWin())
|
|
|
|
{
|
|
|
|
Debug.Log("You won!");
|
2024-04-08 21:24:13 +02:00
|
|
|
_won = true;
|
2024-04-04 22:57:07 +02:00
|
|
|
}
|
|
|
|
else if (endGameCondition.IsLose())
|
|
|
|
{
|
|
|
|
Debug.Log("You lost!");
|
2024-04-08 21:24:13 +02:00
|
|
|
_lost = true;
|
2024-04-04 22:57:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug.Log(endGameCondition.GetEndGameMessage());
|
|
|
|
|
|
|
|
PauseGame();
|
|
|
|
}
|
|
|
|
|
2024-04-04 15:26:31 +02:00
|
|
|
void UpdateEfficiency()
|
|
|
|
{
|
2024-04-04 16:33:12 +02:00
|
|
|
double developerEfficiency = 0.0f;
|
|
|
|
|
2024-04-06 00:57:29 +02:00
|
|
|
// TODO: Und eine weitere absolut nicht handle-bare variable...
|
2024-04-05 19:24:26 +02:00
|
|
|
double caffeineDrain = _generalNeedDrainScaling * Math.Pow(2, _difficultySettings.CaffeineDrainScaling * GameProgress);
|
|
|
|
double hungerDrain = _generalNeedDrainScaling * Math.Pow(2, _difficultySettings.HungerDrainScaling * GameProgress);
|
|
|
|
double urinationDrain = _generalNeedDrainScaling * Math.Pow(2, _difficultySettings.UrinationDrainScaling * GameProgress);
|
2024-04-06 00:57:29 +02:00
|
|
|
double happinessDrain = _generalNeedDrainScaling * Math.Pow(2, _difficultySettings.HappinessDrainScaling * GameProgress);
|
2024-04-05 19:24:26 +02:00
|
|
|
|
2024-04-04 16:33:12 +02:00
|
|
|
foreach (Developer developer in _developers)
|
|
|
|
{
|
2024-04-06 00:57:29 +02:00
|
|
|
developer.UpdateStats(caffeineDrain, hungerDrain, urinationDrain, happinessDrain);
|
2024-04-04 16:33:12 +02:00
|
|
|
developer.UpdateEfficiency();
|
2024-04-04 18:13:08 +02:00
|
|
|
developerEfficiency += developer.CurrentEfficiency;
|
2024-04-04 16:33:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_currentEfficiency = developerEfficiency;
|
2024-04-04 15:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateGameDuration()
|
|
|
|
{
|
2024-04-04 16:33:12 +02:00
|
|
|
// Entwickler Effizienz ist im Grunde wie viele Entwicklersekunden wir pro Sekunde verrichten können.
|
|
|
|
_remainingGameDurationSeconds -= _currentEfficiency;
|
2024-04-04 12:14:58 +02:00
|
|
|
}
|
2024-04-06 16:47:41 +02:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the context stored in the contextBuffer seperated with ',' as a string
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public string GetContextAsString()
|
|
|
|
{
|
|
|
|
if (_contextBuffer.Count != 0)
|
|
|
|
{
|
|
|
|
string output = "";
|
|
|
|
foreach (string context in _contextBuffer)
|
|
|
|
{
|
|
|
|
output += context + ", ";
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2024-04-06 21:43:51 +02:00
|
|
|
return string.Empty;
|
2024-04-06 16:47:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds the given string to the context
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="context"></param>
|
|
|
|
public void AddContext(string context)
|
|
|
|
{
|
|
|
|
_contextBuffer.Add(context);
|
|
|
|
}
|
2024-04-07 00:12:15 +02:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Removes the given string from the context
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="context"></param>
|
|
|
|
public void RemoveContext(string context)
|
|
|
|
{
|
|
|
|
if ( _contextBuffer.Contains(context) )
|
|
|
|
{
|
|
|
|
List<string> contextAsList = _contextBuffer.ToArray().ToList();
|
|
|
|
_contextBuffer.Clear();
|
|
|
|
contextAsList.Remove(context);
|
|
|
|
foreach (var c in contextAsList)
|
|
|
|
{
|
|
|
|
_contextBuffer.Add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-04 12:14:58 +02:00
|
|
|
}
|