示例#1
0
    public void OnDialogueSelected(Guid dialogId)
    {
        /*var d =*/ iat.GetDialogActionById(dialogId);

        if (ResetEmotions)
        {
            var currentMood = agent1RPC.Mood;
            agent1RPC.ResetEmotionalState();
            agent1RPC.Mood = currentMood;
        }
        HandleSpeakAction(dialogId, "Player", agent1RPC.CharacterName.ToString());
    }
示例#2
0
        private void UpdateCoroutine()
        {
            string currentBelief = _rpc.GetBeliefValue(Consts.DIALOGUE_STATE_PROPERTY);

            while (currentBelief != Consts.STATE_SESSION_END)
            {
                //showEmotions();
                _rpc.Update();
                currentBelief = _rpc.GetBeliefValue(Consts.DIALOGUE_STATE_PROPERTY);
                if (_events.Count > 0)
                {
                    SuecaEvent ev;
                    lock (eventsLock)
                    {
                        ev = _events.First();
                        _events.RemoveAt(0);
                    }

                    //wait until event is finished
                    while (!ev.Finished)
                    {
                    }

                    if (ev.Name == Consts.STATE_SHUFFLE || ev.Name == Consts.STATE_SESSION_START)
                    {
                        //Console.WriteLine("Resetting Posture");
                        EmotionalSuecaPlayer.SuecaPub.SetPosture("", "neutral");
                    }
                    if (ev.Name == Consts.INIT)
                    {
                        _rpc.CharacterName = (Name)ev.OtherStringInfos[0];
                        _rpc.m_kb.SetPerspective((Name)ev.OtherStringInfos[0]);
                    }
                    if (ev.Name == Consts.STATE_TRICK_END)
                    {
                        Console.WriteLine("\nCLEANING EMOTIONAL POOL\n");
                        _rpc.ResetEmotionalState();
                    }

                    perceive(ev);

                    if (ev.Name == Consts.STATE_NEXT_PLAYER)
                    {
                        if (ev.OtherIntInfos.Length > 0 && !_esp.Talking)
                        {
                            Thread.Sleep(_randomNumberGenerator.Next(0, 2000));
                            EmotionalSuecaPlayer.SuecaPub.GazeAtTarget("player" + ev.OtherIntInfos[0]);
                        }

                        if (_randomNumberGenerator.Next(0, 10) < 6)
                        {
                            // Sleep randomly until decide
                            Thread waitForDeciding = new Thread(this.SleepForNextPlayerEvent);
                            waitForDeciding.Start();
                            while (!_sleepNotify && _events.Count == 0)
                            {
                            }
                            waitForDeciding.Interrupt();
                            _sleepNotify = false;
                            if (_events.Count == 0)
                            {
                                //decide only if after sleeping no one has played
                                decide(ev);
                            }
                        }
                    }
                    else if (ev.Name == Consts.STATE_PLAYSELF)
                    {
                        EmotionalSuecaPlayer.SuecaPub.GazeAtTarget("cardsZone");
                        if (ev.OtherStringInfos.Length > 0)
                        {
                            Thread.Sleep(1000);
                            decide(ev);
                            Thread.Sleep(1000);
                            EmotionalSuecaPlayer.SuecaPub.Play(ev.OtherIntInfos[0], ev.OtherStringInfos[0], ev.OtherStringInfos[1]);
                        }
                    }
                    else if (ev.Name == Consts.STATE_PLAYPARTNER)
                    {
                        Thread.Sleep(1000);
                        decide(ev);

                        if (ev.OtherIntInfos[0] == ((_esp._id + 2) % 4))
                        {
                            string attributionEmotion = getStrongestAttributionEmotion(_rpc.GetAllActiveEmotions());
                            EmotionalSuecaPlayer.SuecaPub.SetPosture("", attributionEmotion);
                        }
                        else
                        {
                            string wellbeingEmotion = getStrongestWellbeingEmotion(_rpc.GetAllActiveEmotions());
                            EmotionalSuecaPlayer.SuecaPub.SetPosture("", wellbeingEmotion);
                        }
                    }
                    else if (ev.Name != Consts.INIT)
                    {
                        decide(ev);
                    }
                }
                Thread.Sleep(100);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            //AssetStorage
            var storage = AssetStorage.FromJson(File.ReadAllText("../../../../Examples/AssetStorage.json"));
            //Loading the asset
            var rpc = new RolePlayCharacterAsset();

            rpc.LoadAssociatedAssets(storage);
            rpc.ActivateIdentity(new Identity((Name)"Portuguese", (Name)"Culture", 1));
            Console.WriteLine("Starting Mood: " + rpc.Mood);
            var actions = rpc.Decide();
            var action  = actions.FirstOrDefault();

            rpc.Update();

            Console.WriteLine("The name of the character loaded is: " + rpc.CharacterName);
            // Console.WriteLine("The following event was perceived: " + event1);
            Console.WriteLine("Mood after event: " + rpc.Mood);
            Console.WriteLine("Strongest emotion: " + rpc.GetStrongestActiveEmotion()?.EmotionType + "-" + rpc.GetStrongestActiveEmotion()?.Intensity);
            Console.WriteLine("First Response: " + action?.Name + ", Target:" + action?.Target.ToString());

            var busyAction = rpc.Decide().FirstOrDefault();

            Console.WriteLine("Second Response: " + busyAction?.Name + ", Target:" + action?.Target.ToString());

            var event3 = EventHelper.ActionEnd(rpc.CharacterName.ToString(), action?.Name.ToString(), "Player");

            rpc.Perceive(new[] { event3 });
            action = rpc.Decide().FirstOrDefault();

            Console.WriteLine("Third Response: " + action?.Name + ", Target:" + action?.Target.ToString());


            int x = 0;

            while (true)
            {
                Console.WriteLine("Mood after tick: " + rpc.Mood + " x: " + x + " tick: " + rpc.Tick);
                Console.WriteLine("Strongest emotion: " + rpc.GetStrongestActiveEmotion()?.EmotionType + "-" + rpc.GetStrongestActiveEmotion()?.Intensity);
                rpc.Update();
                Console.ReadLine();

                if (x == 10)
                {
                    var event1 = EventHelper.ActionEnd("Player", "Kick", rpc.CharacterName.ToString());

                    rpc.Perceive(new[] { event1 });
                    action = rpc.Decide().FirstOrDefault();
                    rpc.Update();
                }


                if (x == 11)
                {
                    rpc.ResetEmotionalState();
                }
                if (x == 25)
                {
                    var event1 = EventHelper.ActionEnd("Player", "Kick", rpc.CharacterName.ToString());

                    rpc.Perceive(new[] { event1 });
                    action = rpc.Decide().FirstOrDefault();
                    rpc.Update();
                }


                else if (x == 30)
                {
                    Console.WriteLine("Reloading " + rpc.GetStrongestActiveEmotion().Intensity + " " + rpc.GetStrongestActiveEmotion().EmotionType + " mood: " + rpc.Mood);

                    Console.WriteLine("Reloading result: " + rpc.GetStrongestActiveEmotion().Intensity + " " + rpc.GetStrongestActiveEmotion().EmotionType + " mood: " + rpc.Mood);
                }

                x++;
            }
        }