Mehr reden

This commit is contained in:
klappstuhl24 2024-04-06 20:02:57 +02:00
parent f202aace09
commit 2f5f25d0bd
7 changed files with 120 additions and 20 deletions

View File

@ -94,17 +94,6 @@ public class Developer : MonoBehaviour
public string Name => _name; public string Name => _name;
[Serializable, Flags]
public enum WantedConsumable
{
None,
Food = 0x01,
Drink = 0x02,
Coffee = Drink | 0x04,
Mate = Drink | 0x08,
Pizza = Food | 0x10
}
[SerializeField] [SerializeField]
private GameObject _caffeineNeed; private GameObject _caffeineNeed;
@ -122,6 +111,8 @@ public class Developer : MonoBehaviour
private float _talkPauseTime = 15.0f; private float _talkPauseTime = 15.0f;
[SerializeField, ShowOnly] [SerializeField, ShowOnly]
private float _talkTimer; private float _talkTimer;
private bool _hasTalkedWhileHyperactive = false;
private bool _hasTalkedWhileOvercaffeinated = false;
private List<GameObject> _needList = new List<GameObject>(); private List<GameObject> _needList = new List<GameObject>();
@ -191,10 +182,16 @@ public class Developer : MonoBehaviour
{ {
// TODO: Wie wäre es damit, das nicht fest zu coden? // TODO: Wie wäre es damit, das nicht fest zu coden?
if (drinkType == _wantedDrink) if (drinkType == _wantedDrink)
{
Talk($"The Devolper thanks Gottfried for the {drinkType.GetAsString()}");
_happiness += 0.2; _happiness += 0.2;
}
else else
{
Talk($"The Devolper blames Gottfried for bringing {drinkType.GetAsString()} but he actaully wanted a {_wantedDrink.GetAsString()}");
_happiness -= 0.2; _happiness -= 0.2;
} }
}
else else
{ {
_happiness += 0.2; _happiness += 0.2;
@ -217,6 +214,7 @@ public class Developer : MonoBehaviour
_needList.Remove(_hungerNeed); _needList.Remove(_hungerNeed);
NeedFullfilled(_hungerNeed); NeedFullfilled(_hungerNeed);
_hungerNeed = null; _hungerNeed = null;
Talk("The Developer thanks Gottfried for the Pizza");
} }
if (_wantedFood != WantedConsumable.None) if (_wantedFood != WantedConsumable.None)
@ -249,6 +247,7 @@ public class Developer : MonoBehaviour
_needList.Remove(_toiletNeed); _needList.Remove(_toiletNeed);
NeedFullfilled(_toiletNeed); NeedFullfilled(_toiletNeed);
_toiletNeed = null; _toiletNeed = null;
Talk("The Developer finally can go to the toilet");
} }
if (onToilet) if (onToilet)
@ -269,7 +268,7 @@ public class Developer : MonoBehaviour
_urgeToUrinateLevel = Math.Max(_urgeToUrinateLevel, 0.0); _urgeToUrinateLevel = Math.Max(_urgeToUrinateLevel, 0.0);
_happiness = Math.Max(_happiness, 0.0); _happiness = Math.Max(_happiness, 0.0);
_isHyperactive = _caffeineLevel > 1.0; _isHyperactive = _caffeineLevel > 1.0 && _caffeineLevel <= 1.5;
_isOvercaffeinated = _caffeineLevel > 1.5; _isOvercaffeinated = _caffeineLevel > 1.5;
_isSleeping = _caffeineLevel <= 0.0; _isSleeping = _caffeineLevel <= 0.0;
@ -351,12 +350,32 @@ public class Developer : MonoBehaviour
if (_isSleeping) if (_isSleeping)
return 0.0; return 0.0;
// Die Formel hat schon recht vielversprechendes Verhalten im Bereich > 1 if (_isHyperactive)
//if (_isHyperactive) {
// return 1.0 + (_caffeineLevel - 1.0) * (_caffeineLevel - 1.0); if (!_hasTalkedWhileHyperactive)
{
Talk("The Developer is surprisingly productive right now duo to caffeine");
_hasTalkedWhileHyperactive = true;
}
}
else
{
_hasTalkedWhileHyperactive = false;
}
if (_isOvercaffeinated) if (_isOvercaffeinated)
{
if (!_hasTalkedWhileOvercaffeinated)
{
Talk("The Developer drank too much caffeine, The Developer needs a break immediately");
_hasTalkedWhileOvercaffeinated = true;
}
return 0.0; return 0.0;
}
else
{
_hasTalkedWhileOvercaffeinated = false;
}
// https://easings.net/#easeOutCubic // https://easings.net/#easeOutCubic
return 1.0 - Math.Pow(1.0 - _caffeineLevel, 3.0); return 1.0 - Math.Pow(1.0 - _caffeineLevel, 3.0);
@ -423,9 +442,12 @@ public class Developer : MonoBehaviour
/// <summary> /// <summary>
/// Dev starts talking. /// Dev starts talking.
/// </summary> /// </summary>
public void Talk() public void Talk(string context = null)
{ {
string context = GameManager.Instance.GetContextAsString(); if (context == null)
{
context = GameManager.Instance.GetContextAsString();
}
if (!_audioSource.isPlaying) if (!_audioSource.isPlaying)
{ {
GetComponent<Text2Speech>().Generate(context); GetComponent<Text2Speech>().Generate(context);

View File

@ -49,7 +49,7 @@ public class DeveloperNeeds : MonoBehaviour
break; break;
case "toilet": case "toilet":
spawnedNeed = Instantiate(Needs[2], new Vector3(0.0f, 2f + (numNeeds * 0.5f), 0.0f), Needs[0].transform.rotation); spawnedNeed = Instantiate(Needs[2], new Vector3(0.0f, 2f + (numNeeds * 0.5f), 0.0f), Needs[0].transform.rotation);
context = "The Developer wants to go to the toilet, toilet is clogged and dirty"; context = "The Developer wants to go to the toilet";
break; break;
case "hunger": case "hunger":
spawnedNeed = Instantiate(Needs[3], new Vector3(0.0f, 2f + (numNeeds * 0.5f), 0.0f), Needs[0].transform.rotation); spawnedNeed = Instantiate(Needs[3], new Vector3(0.0f, 2f + (numNeeds * 0.5f), 0.0f), Needs[0].transform.rotation);

View File

@ -11,6 +11,7 @@ using OpenAI_API.Models;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Google.Cloud.TextToSpeech.V1;
[Serializable] [Serializable]
public class TextToSpeechResponse public class TextToSpeechResponse
@ -21,12 +22,22 @@ public class TextToSpeechResponse
public class Text2Speech : MonoBehaviour public class Text2Speech : MonoBehaviour
{ {
[SerializeField]
public string context = "going for a walk, falling, explosion, blood"; public string context = "going for a walk, falling, explosion, blood";
[SerializeField]
public string gender = "MALE"; public string gender = "MALE";
[SerializeField]
public JToken voice = null; public JToken voice = null;
[SerializeField]
public double speakingSpeed = 1.1; public double speakingSpeed = 1.1;
[SerializeField]
public bool playSound = false; public bool playSound = false;
[SerializeField]
public bool generate = false; public bool generate = false;
[SerializeField]
public bool newVoiceAndGenerate = false;
[SerializeField]
public string Voice;
private AudioSource _audioSource; private AudioSource _audioSource;
@ -60,6 +71,7 @@ public class Text2Speech : MonoBehaviour
{ {
GetRandomGermanVoice(gender, (v) => { GetRandomGermanVoice(gender, (v) => {
voice = v; voice = v;
Voice = voice.ToString();
//Debug.Log($"GoogleCloud: Choosen voice is\n{voice}"); //Debug.Log($"GoogleCloud: Choosen voice is\n{voice}");
StartCoroutine(GenerateAndSynthesizeText(context)); StartCoroutine(GenerateAndSynthesizeText(context));
}); });
@ -69,6 +81,13 @@ public class Text2Speech : MonoBehaviour
StartCoroutine(GenerateAndSynthesizeText(context)); StartCoroutine(GenerateAndSynthesizeText(context));
} }
} }
if (newVoiceAndGenerate)
{
newVoiceAndGenerate = false;
voice = null;
Voice = null;
generate = true;
}
} }
public void Generate(string c) public void Generate(string c)

View File

@ -0,0 +1,10 @@
{
"languageCodes": [
"en-AU"
],
"name": "en-AU-News-G",
"ssmlGender": "MALE",
"naturalSampleRateHertz": 24000,
"pitch": -2
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 23e2a6475b913ee4b8746739f66bccfe
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,31 @@
using System;
namespace Utility
{
[Serializable, Flags]
public enum WantedConsumable
{
None,
Food = 0x01,
Drink = 0x02,
Coffee = Drink | 0x04,
Mate = Drink | 0x08,
Pizza = Food | 0x10
}
public static class WantedConsumableExtension
{
public static string GetAsString(this WantedConsumable wantedConsumable) =>
wantedConsumable switch
{
WantedConsumable.None => "None",
WantedConsumable.Food => "Food",
WantedConsumable.Drink => "Drink",
WantedConsumable.Coffee => "Coffee",
WantedConsumable.Mate => "Blub Mate",
WantedConsumable.Pizza => "Pizza",
_ => ""
};
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7aa5732bd4e078f4aafd3188c4976d5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: