Exemple #1
0
    private void ChangeState(Emotion.Type type, float change)
    {
        States[type] += change;
        Emotion emotion = new Emotion(type, States[type]);

        Send(emotion);

        if (myOutput.IsMe("Jack"))
        {
            AnimationController AC = myOutput.myStack.conversation.animationController;
            if (AC == null)
            {
                return;
            }
            float value = States[type];

            switch (type)
            {
            case Emotion.Type.Anger: AC.UpdateAnger(value / 100f); break;

            case Emotion.Type.Fear: AC.UpdateFear(value / 100f); break;

            case Emotion.Type.Ego: AC.UpdateEgo(value / 100f); break;
            }
        }
        else if (myOutput.IsMe("Joe") && States[Emotion.Type.Fear] >= 90f)
        {
            myOutput.myStack.conversation.manager.CallEvent(7);
        }
    }
Exemple #2
0
    public static Dictionary <string, HashSet <Thought> > LoadThoughts(TextAsset textAsset)
    {
        char[] nextLineChars     = { '\n' };
        char[] nextValueChars    = { '\t' };
        char[] nextSubValueChars = { ';' };

        string text = textAsset.text;

        string[] lines = text.Split(nextLineChars);

        Dictionary <string, HashSet <Thought> > newThoughts = new Dictionary <string, HashSet <Thought> >();
        string topic = null;

        Topic.Stage stage = Topic.Stage.None;
        string      actor = null;

        for (int i = 1; i < lines.Length; i++)
        {
            string   line   = lines[i];
            string[] values = line.Split(nextValueChars, 25);

            try
            {
                // Update running values: Topic, Stage, Actor
                if (!values[0].Equals(""))
                {
                    topic = values[0].Trim();
                }
                string stageText = values[1].Trim().ToLower();
                if (stageMap.ContainsKey(stageText))
                {
                    stage = stageMap[stageText];
                }
                string actorText = values[2].Trim();
                if (!actorText.Equals(""))
                {
                    actor = actorText;
                    if (!newThoughts.ContainsKey(actor))
                    {
                        newThoughts[actor] = new HashSet <Thought>();
                    }
                }

                // Read Complexity
                float complexity = 0f;
                if (!float.TryParse(values[3].Trim(), out complexity))
                {
                    Debug.Log("Failed to read: \"" + line + "\".");
                    continue;
                }

                // Read Text
                string thoughtText = values[4].Trim();
                if (values[4].Equals(""))
                {
                    continue;
                }

                // bruh moment (I get it, but still)
                if (thoughtText.Contains(",") || thoughtText.Contains("\"") &&
                    thoughtText[0] == '\"' &&
                    thoughtText[thoughtText.Length - 1] == '\"')
                {
                    thoughtText = thoughtText.Substring(1, thoughtText.Length - 2);
                }

                while (thoughtText.Contains("\"\""))
                {
                    thoughtText = thoughtText.Replace("\"\"", "\"");
                }

                // Read Social Expectations
                Thought.Interrupt interruptStrategy = Thought.Interrupt.None;
                string            interruptText     = values[5].Trim().ToLower();
                if (interruptMap.ContainsKey(interruptText))
                {
                    interruptStrategy = interruptMap[interruptText];
                }

                Thought.Turn turnStrategy = Thought.Turn.None;
                string       turnText     = values[6].Trim().ToLower();
                if (turnMap.ContainsKey(turnText))
                {
                    turnStrategy = turnMap[turnText];
                }

                Thought.Affinity affinity     = Thought.Affinity.None;
                string           affinityText = values[7].Trim().ToLower();
                if (affinityMap.ContainsKey(affinityText))
                {
                    affinity = affinityMap[affinityText];
                }

                // Read Tangental Topics
                string[]         tangentStrings = values[8].Trim().Split(nextSubValueChars);
                HashSet <string> tangents       = new HashSet <string>();
                foreach (var tangent in tangentStrings)
                {
                    if (!tangent.Equals(""))
                    {
                        tangents.Add(tangent.Trim());
                    }
                }

                // Read Special Event Codes
                int eventCode = -1;
                int.TryParse(values[9].Trim(), out eventCode);

                // Read Emotional Weight Values
                HashSet <Emotion> emotions = new HashSet <Emotion>();
                foreach (KeyValuePair <int, Emotion.Type> pair in emotionIndexMap)
                {
                    int index = pair.Key;
                    if (index > values.Length - 1)
                    {
                        continue;
                    }

                    Emotion.Type type = pair.Value;

                    float strength = 0f;
                    if (float.TryParse(values[index].Trim(), out strength))
                    {
                        Emotion emotion = new Emotion(type, strength);
                        emotions.Add(emotion);
                    }
                }

                // Read Emotional Attack Values
                HashSet <Argument> arguments = new HashSet <Argument>();
                foreach (KeyValuePair <int, Argument.Type> pair in argumentIndexMap)
                {
                    int index = pair.Key;
                    if (index > values.Length - 1)
                    {
                        continue;
                    }

                    Argument.Type type = pair.Value;

                    float strength = 0f;
                    if (float.TryParse(values[index].Trim(), out strength))
                    {
                        Argument argument = new Argument(type, strength);
                        arguments.Add(argument);
                    }
                }

                Thought thought = new Thought(topic, stage, actor, complexity, thoughtText, interruptStrategy, turnStrategy, affinity, tangents, eventCode, arguments, emotions);
                newThoughts[actor].Add(thought);
            } catch (Exception e)
            {
                Debug.Log("Skipped reading: \"" + line + "\" with value count " + values.Length + ". (" + e.Message + ")");
            }
        }

        foreach (KeyValuePair <string, HashSet <Thought> > pair in newThoughts)
        {
            string actorName = pair.Key;
            int    length    = pair.Value.Count;

            Debug.Log("Read in " + length + " thoughts for " + actorName + ".");
        }

        return(newThoughts);
    }