Devs sprechen jetzt wenn sie was wollen
This commit is contained in:
@ -37,15 +37,16 @@ public class NPC_Behavior : MonoBehaviour
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
[SerializeField] private bool _deleteManually = false;
|
||||
[SerializeField] private bool _fullfillNeedManually = false;
|
||||
[SerializeField] private float _timer;
|
||||
[SerializeField] private float _newNeedDelay = 3.0f;
|
||||
[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;
|
||||
private float _newNeedDelayTimer = 0.0f;
|
||||
private float _effectCreationTime;
|
||||
private GameObject _effect;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the current need
|
||||
@ -67,42 +68,31 @@ public class NPC_Behavior : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
WatchEffect();
|
||||
_timer -= Time.deltaTime;
|
||||
_justFullfilledNeedTimer -= Time.deltaTime;
|
||||
|
||||
if (_justFullfilledNeedTimer <= 0 && _justFullfilledNeed)
|
||||
if (_newNeedDelayTimer <= 0)
|
||||
{
|
||||
_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 )
|
||||
if (_timer <= 0 && _currentNeed == null)
|
||||
{
|
||||
_lastTenNeeds.RemoveAt(0);
|
||||
GenerateNeed();
|
||||
ResetTimer();
|
||||
}
|
||||
ResetTimer();
|
||||
}
|
||||
else
|
||||
{
|
||||
_newNeedDelayTimer -= Time.deltaTime;
|
||||
}
|
||||
|
||||
// for Debugging
|
||||
if (_deleteManually)
|
||||
if (_fullfillNeedManually)
|
||||
{
|
||||
_deleteManually = false;
|
||||
_fullfillNeedManually = false;
|
||||
NeedFullfilled();
|
||||
}
|
||||
}
|
||||
|
||||
void ResetTimer()
|
||||
private void ResetTimer()
|
||||
{
|
||||
if (eventRate <= 0)
|
||||
{
|
||||
@ -111,10 +101,44 @@ public class NPC_Behavior : MonoBehaviour
|
||||
else
|
||||
{
|
||||
_timeBetweenEvents = 60f / (float)eventRate;
|
||||
_timer = Random.Range(0.5f * _timeBetweenEvents, 1.5f * _timeBetweenEvents);
|
||||
_timer = Random.Range(0.5f * _timeBetweenEvents, 1.25f * _timeBetweenEvents);
|
||||
}
|
||||
}
|
||||
|
||||
private void WatchEffect()
|
||||
{
|
||||
if (_effect != null && GetEffectLifetime() >= 3.0f)
|
||||
{
|
||||
RemoveEffect();
|
||||
}
|
||||
}
|
||||
|
||||
private float GetEffectLifetime()
|
||||
{
|
||||
return Time.time - _effectCreationTime;
|
||||
}
|
||||
|
||||
private bool RemoveEffect()
|
||||
{
|
||||
Destroy(_effect);
|
||||
return _effect != null;
|
||||
}
|
||||
|
||||
public bool GenerateNeed()
|
||||
{
|
||||
List<string> needs = new List<string>() { "coffee", "mate", "toilet", "money" };
|
||||
|
||||
string need = needs[UnityEngine.Random.Range(0, needs.Count)];
|
||||
_currentNeed = _developerNeeds.spawnNeed(need);
|
||||
HasNeed = true;
|
||||
_lastTenNeeds.Add(need);
|
||||
if (_lastTenNeeds.Count > 10)
|
||||
{
|
||||
_lastTenNeeds.RemoveAt(0);
|
||||
}
|
||||
return _currentNeed != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the current need and its gameobject.
|
||||
/// </summary>
|
||||
@ -125,9 +149,10 @@ public class NPC_Behavior : MonoBehaviour
|
||||
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);
|
||||
_newNeedDelayTimer = _newNeedDelay;
|
||||
_effect = Instantiate(confettiEffect, new Vector3(0.0f, 1.5f, 0.0f), confettiEffect.transform.rotation);
|
||||
_effect.transform.SetParent(transform, false);
|
||||
_effectCreationTime = Time.time;
|
||||
}
|
||||
return _currentNeed == null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user