zwischencommit
This commit is contained in:
@ -18,7 +18,7 @@ public class DeveloperNeeds : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public bool spawnNeed(string needName)
|
||||
public GameObject spawnNeed(string needName)
|
||||
{
|
||||
|
||||
GameObject spawnedNeed = null;
|
||||
@ -44,8 +44,8 @@ public class DeveloperNeeds : MonoBehaviour
|
||||
if (spawnedNeed != null)
|
||||
{
|
||||
spawnedNeed.transform.SetParent(transform, false);
|
||||
return true;
|
||||
return spawnedNeed;
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Unity.PlasticSCM.Editor.WebApi;
|
||||
using UnityEngine;
|
||||
|
||||
public class NPC_Behavior : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject confettiEffect;
|
||||
[SerializeField] private double _caffeineLevel = 0.0; // max 100, min 0
|
||||
[SerializeField] private double _hungerLevel = 0.0; // max 100, min 0
|
||||
[SerializeField] private double _happinessLevel = 100.0; // max 100, min 0
|
||||
@ -34,9 +36,25 @@ public class NPC_Behavior : MonoBehaviour
|
||||
public double DevelopmentPower => _developementPower;
|
||||
|
||||
private GameManager _gameManager;
|
||||
private DeveloperNeeds _developerNeeds;
|
||||
|
||||
[SerializeField] private bool _deleteManually = false;
|
||||
[SerializeField] private float _timer;
|
||||
[SerializeField] private List<string> _lastTenNeeds = new List<string>();
|
||||
private DeveloperNeeds _developerNeeds;
|
||||
private float _timeBetweenEvents;
|
||||
private GameObject _currentNeed = null;
|
||||
private bool _justFullfilledNeed = false;
|
||||
private float _justFullfilledNeedTimer = 2.0f;
|
||||
private bool _canNeedNewNeed = true;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the current need
|
||||
/// </summary>
|
||||
public string CurrentNeed => _lastTenNeeds[_lastTenNeeds.Count - 1];
|
||||
/// <summary>
|
||||
/// Indicates if the developer has a need right now
|
||||
/// </summary>
|
||||
public bool HasNeed = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@ -50,13 +68,38 @@ public class NPC_Behavior : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
_timer -= Time.deltaTime;
|
||||
_justFullfilledNeedTimer -= Time.deltaTime;
|
||||
|
||||
if (_timer <= 0)
|
||||
if (_justFullfilledNeedTimer <= 0 && _justFullfilledNeed)
|
||||
{
|
||||
List<string> needs = new List<string>() { "coffee", "mate", "toilet" };
|
||||
_developerNeeds.spawnNeed(needs[UnityEngine.Random.Range(0, needs.Count)]);
|
||||
_canNeedNewNeed = true;
|
||||
_justFullfilledNeed = false;
|
||||
_justFullfilledNeedTimer = 2.0f;
|
||||
}
|
||||
|
||||
if (_timer <= 0 && _currentNeed == null && _canNeedNewNeed)
|
||||
{
|
||||
// List<string> needs = new List<string>() { "coffee", "mate", "toilet" };
|
||||
_justFullfilledNeed = false;
|
||||
_canNeedNewNeed = false;
|
||||
|
||||
string need = "coffee";
|
||||
_currentNeed = _developerNeeds.spawnNeed(need);
|
||||
HasNeed = true;
|
||||
_lastTenNeeds.Add(need);
|
||||
if (_lastTenNeeds.Count > 10 )
|
||||
{
|
||||
_lastTenNeeds.RemoveAt(0);
|
||||
}
|
||||
ResetTimer();
|
||||
}
|
||||
|
||||
// for Debugging
|
||||
if (_deleteManually)
|
||||
{
|
||||
_deleteManually = false;
|
||||
NeedFullfilled();
|
||||
}
|
||||
}
|
||||
|
||||
void ResetTimer()
|
||||
@ -72,11 +115,28 @@ public class NPC_Behavior : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the current need and its gameobject.
|
||||
/// </summary>
|
||||
/// <returns>bool: wether successfully deleted the gameobject or not</returns>
|
||||
public bool NeedFullfilled()
|
||||
{
|
||||
Destroy(_currentNeed);
|
||||
if (HasNeed)
|
||||
{
|
||||
HasNeed = false;
|
||||
_justFullfilledNeed = true;
|
||||
_canNeedNewNeed = false;
|
||||
Instantiate(confettiEffect, new Vector3(0.0f, 1.5f, 0.0f), confettiEffect.transform.rotation).transform.SetParent(transform, false);
|
||||
}
|
||||
return _currentNeed == null;
|
||||
}
|
||||
|
||||
public Dictionary<string, double> GetStats()
|
||||
{
|
||||
return new Dictionary<string, double>
|
||||
{
|
||||
{ "Caffine", _caffeineLevel },
|
||||
{ "Caffeine", _caffeineLevel },
|
||||
{ "Hunger", _hungerLevel },
|
||||
{ "Happiness", _happinessLevel },
|
||||
{ "Developement Power", _developementPower }
|
||||
@ -89,7 +149,7 @@ public class NPC_Behavior : MonoBehaviour
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case "Caffine":
|
||||
case "Caffeine":
|
||||
_caffeineLevel = stats[key];
|
||||
break;
|
||||
case "Hunger":
|
||||
|
||||
Reference in New Issue
Block a user