// Use this for initialization
    void Start()
    {
        // Loading Storage json with the Rules, files must be in the Streaming Assets Folder
        var storagetPath = Application.streamingAssetsPath + "/MultiCharacterv4.0/multicharstorage.json";
        var storage      = AssetStorage.FromJson(File.ReadAllText(storagetPath));

        //Loading Scenario information with data regarding characters and dialogue
        var iatPath = Application.streamingAssetsPath + "/MultiCharacterv4.0/scenario.json";

        _iat = IntegratedAuthoringToolAsset.FromJson(File.ReadAllText(iatPath), storage);


        var currentState = IATConsts.INITIAL_DIALOGUE_STATE;


        // Getting a list of all the Characters
        _rpcList = _iat.Characters.ToList();

        //Saving the World Model
        _worldModel = _iat.WorldModel;



        ChooseCharacterMenu();
    }
예제 #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var aux = EditorTools.OpenFileDialog("Asset Storage File (*.json)|*.json|All Files|*.*");

            if (aux != null)
            {
                _currentFilePath = aux;
                _storage         = AssetStorage.FromJson(File.ReadAllText(_currentFilePath));
                _loadedAsset     = EmotionalAppraisalAsset.CreateInstance(_storage);
                OnAssetDataLoaded();
            }
        }
예제 #3
0
        private static string HandleScenariosRequest(APIRequest req, ServerState serverState)
        {
            if (req.Method == HTTPMethod.GET)
            {
                return(JsonConvert.SerializeObject(serverState.Scenarios.Keys));
            }

            if (req.Method == HTTPMethod.POST)
            {
                if (!string.IsNullOrEmpty(req.RequestBody))
                {
                    IntegratedAuthoringToolAsset iat;
                    try
                    {
                        var request      = JsonConvert.DeserializeObject <CreateScenarioRequestDTO>(req.RequestBody);
                        var assetStorage = AssetStorage.FromJson(request.Assets);
                        iat = IntegratedAuthoringToolAsset.FromJson(request.Scenario, assetStorage);

                        serverState.Scenarios[iat.ScenarioName.ToLower()] = new IntegratedAuthoringToolAsset[HTTPFAtiMAServer.MAX_INSTANCES + 1];

                        //original is kept at 0 and will be left unchanged
                        serverState.Scenarios[iat.ScenarioName.ToLower()][0] = IntegratedAuthoringToolAsset.FromJson(request.Scenario, assetStorage);

                        //instance of id 1 is automatically created
                        serverState.Scenarios[iat.ScenarioName.ToLower()][1] = IntegratedAuthoringToolAsset.FromJson(request.Scenario, assetStorage);
                        if (!string.IsNullOrEmpty(req.Key))
                        {
                            serverState.ScenarioKeys[iat.ScenarioName.ToLower()] = req.Key;
                        }
                    }
                    catch (Exception ex)
                    {
                        return(JsonConvert.SerializeObject(ex.Message));
                    }
                    return(JsonConvert.SerializeObject("Scenario named '" + iat.ScenarioName + "' created containing " +
                                                       "'" + iat.Characters.Count() + "' characters"));
                }
                else
                {
                    return(JsonConvert.SerializeObject("Error: Empty body in a create scenario request!"));
                }
            }
            if (req.Method == HTTPMethod.DELETE)
            {
                serverState.Scenarios.TryRemove(req.ScenarioName, out var aux1);
                serverState.ScenarioKeys.TryRemove(req.ScenarioName, out var aux2);
                return(JsonConvert.SerializeObject("Scenario deleted."));
            }

            return(APIErrors.ERROR_INVALID_HTTP_METHOD);
        }
예제 #4
0
    void LoadWebGL()
    {
        Debug.Log("Loading Web Gl Method");

        Debug.Log("Loading Storage string");
        storage = AssetStorage.FromJson(storageInfo);

        Debug.Log("Loading IAT string");
        _iat = IntegratedAuthoringToolAsset.FromJson(scenarioInfo, storage);

        Debug.Log("Finished Loading Web-GL");

        LoadedScenario();
    }
예제 #5
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var aux = EditorTools.OpenFileDialog("Asset Storage File (*.json)|*.json|All Files|*.*");

            if (aux != null)
            {
                try
                {
                    _currentFilePath = aux;
                    _storage         = AssetStorage.FromJson(File.ReadAllText(_currentFilePath));
                    _loadedAsset     = CommeillFautAsset.CreateInstance(_storage);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Exception: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #6
0
    // Use this for initialization
    void Start()
    {
        // Loading Storage json with the Rules, files must be in the Streaming Assets Folder
        var storagetPath = Application.streamingAssetsPath + "/SingleCharacterv4.0/storage.json";
        var storage      = AssetStorage.FromJson(File.ReadAllText(storagetPath));

        //Loading Scenario information with data regarding characters and dialogue
        var iatPath = Application.streamingAssetsPath + "/SingleCharacterv4.0/scenario.json";

        _iat = IntegratedAuthoringToolAsset.FromJson(File.ReadAllText(iatPath), storage);

        var currentState = IATConsts.INITIAL_DIALOGUE_STATE;

        // Getting a list of all the Characters
        _rpcList = _iat.Characters.ToList();

        //Saving the World Model
        _worldModel = _iat.WorldModel;

        _playerRpc          = _rpcList.Find(x => x.CharacterName.ToString().Contains("Player"));
        _playerRpc.IsPlayer = true;
    }
예제 #7
0
        //This is a small console program to exemplify the main functionality of the Emotional Decision Making Asset
        static void Main(string[] args)
        {
            //First we construct a new instance of the EmotionalDecisionMakingAsset class
            var storage = new AssetStorage();
            var edm     = EmotionalDecisionMakingAsset.CreateInstance(storage);

            //Then, we have to register an existing knowledge base to the asset so it can check for
            //beliefs are true
            var kb = new KB((Name)"John");

            kb.Tell((Name)"LikesToFight(SELF)", (Name)"True");
            edm.RegisterKnowledgeBase(kb);
            //create an action rule
            var actionRule = new ActionRuleDTO {
                Action = Name.BuildName("Kick"), Priority = Name.BuildName("4"), Target = (Name)"Player"
            };


            //add the reaction rule
            var id   = edm.AddActionRule(actionRule);
            var rule = edm.GetActionRule(id);

            edm.AddRuleCondition(id, "LikesToFight(SELF) = True");
            var actions = edm.Decide(Name.UNIVERSAL_SYMBOL);
            var ea      = EmotionalAppraisalAsset.CreateInstance(storage);

            edm.Save();

            using (var writer = File.CreateText("D:\\test2.json"))
            {
                writer.Write(storage.ToJson());
            }

            string aux2 = File.ReadAllText("D:\\Test2.json");

            var storage2 = AssetStorage.FromJson(aux2);

            using (var writer = File.CreateText("D:\\test3.json"))
            {
                writer.Write(storage2.ToJson());
            }
            Console.WriteLine("Decisions: ");
            foreach (var a in actions)
            {
                Console.WriteLine(a.Name.ToString() + " p: " + a.Utility);
            }

            //this is how you can load the asset from a file
            Console.WriteLine("Loading From File: ");
            edm.RegisterKnowledgeBase(kb);
            actions = edm.Decide(Name.UNIVERSAL_SYMBOL);

            foreach (var a in actions)
            {
                Console.WriteLine(a.Name.ToString() + " p: " + a.Utility);
            }
            Console.WriteLine("Decisions: ");
            foreach (var a in actions)
            {
                Console.WriteLine(a.Name.ToString() + " p: " + a.Utility);
            }
            Console.ReadKey();
        }
예제 #8
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++;
            }
        }