// 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();
    }
Example #2
0
        private static string HandleInstancesRequest(APIRequest req, ServerState serverState)
        {
            if (req.Method == HTTPMethod.GET)
            {
                var result = new List <int>();
                for (int i = 1; i < HTTPFAtiMAServer.MAX_INSTANCES + 1; i++)
                {
                    if (serverState.Scenarios[req.ScenarioName][i] != null)
                    {
                        result.Add(i);
                    }
                }
                return(JsonConvert.SerializeObject(result));
            }
            else if (req.Method == HTTPMethod.POST)
            {
                for (int i = 1; i < HTTPFAtiMAServer.MAX_INSTANCES + 1; i++)
                {
                    if (serverState.Scenarios[req.ScenarioName][i] == null)
                    {
                        var scenarioJson = serverState.Scenarios[req.ScenarioName][0].ToJson();
                        serverState.Scenarios[req.ScenarioName][i] = IntegratedAuthoringToolAsset.FromJson(scenarioJson, serverState.Scenarios[req.ScenarioName][0].Assets);
                        return(JsonConvert.SerializeObject(i));
                    }
                }
            }
            else if (req.Method == HTTPMethod.DELETE)
            {
                serverState.Scenarios[req.ScenarioName][req.ScenarioInstance] = null;
                return(JsonConvert.SerializeObject("Instance deleted."));
            }

            return(APIErrors.ERROR_INVALID_HTTP_METHOD);
        }
Example #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);
        }
Example #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();
    }
Example #5
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;
    }
Example #6
0
        static void Main(string[] args)
        {
            var playerStr = IATConsts.PLAYER;

            //Loading the asset
            var iat          = IntegratedAuthoringToolAsset.FromJson(File.ReadAllText("../../../../Examples/IAT-Tutorial/Scenarios/ForTheRecord.iat"), new GAIPS.Rage.AssetStorage());
            var currentState = IATConsts.INITIAL_DIALOGUE_STATE;
            var rpc          = iat.Characters.ElementAt(0);

            while (currentState != IATConsts.TERMINAL_DIALOGUE_STATE)
            {
                var playerDialogs = iat.GetDialogueActionsByState(currentState);

                Console.WriteLine("Current Dialogue State: " + currentState);
                Console.WriteLine("Available choices: ");

                for (int i = 0; i < playerDialogs.Count(); i++)
                {
                    Console.WriteLine(i + " - " + playerDialogs.ElementAt(i).Utterance);
                }
                int pos = -1;

                do
                {
                    Console.Write("Select Option: ");
                } while (!Int32.TryParse(Console.ReadLine(), out pos) || pos >= playerDialogs.Count() || pos < 0);

                var chosenDialog = playerDialogs.ElementAt(pos);

                var actionName = iat.BuildSpeakActionName(chosenDialog.Id);
                var speakEvt   = EventHelper.ActionEnd(playerStr, actionName.ToString(), rpc.CharacterName.ToString());

                currentState = chosenDialog.NextState;
                var dialogStateChangeEvt = EventHelper.PropertyChange(string.Format(IATConsts.DIALOGUE_STATE_PROPERTY, playerStr), chosenDialog.NextState, playerStr);

                rpc.Perceive(speakEvt);
                rpc.Perceive(dialogStateChangeEvt);
                var characterActions = rpc.Decide();

                var characterAction = characterActions.FirstOrDefault();

                if (characterAction.Key.ToString() == IATConsts.DIALOG_ACTION_KEY)
                {
                    var dialog = iat.GetDialogueActions(
                        characterAction.Parameters[0],
                        characterAction.Parameters[1],
                        characterAction.Parameters[2],
                        characterAction.Parameters[3]).FirstOrDefault();
                    Console.WriteLine("\n" + rpc.CharacterName + ": " + dialog.Utterance + "\n");
                    currentState = characterAction.Parameters[1].ToString();
                    Console.WriteLine("\nMood: " + rpc.Mood);
                }
                else
                {
                    Console.WriteLine("\n" + rpc.CharacterName + ": " + characterAction.Name + "\n");
                }
            }


            // The next step in this tutorrial is to start using the World Model to cause effects in the belief state of the characters

            Console.WriteLine("Dialogue Reached a Terminal State");
            Console.ReadKey();
        }
Example #7
0
        static void Main(string[] args)
        {
            var iat = IntegratedAuthoringToolAsset.FromJson(File.ReadAllText("../../../Examples/CiF-Tutorial/JobInterview.iat"), new GAIPS.Rage.AssetStorage());

            rpcList = new List <RolePlayCharacterAsset>();
            var wm = new WorldModelAsset();

            wm.AddActionEffect((Name)"Event(Action-End, *, Speak(*,*,*,*), [t])", new EffectDTO()
            {
                PropertyName  = (Name)"Has(Floor)",
                NewValue      = (Name)"[t]",
                ObserverAgent = (Name)"*"
            });

            wm.AddActionEffect((Name)"Event(Action-End, [i], Speak([cs],[ns],*,*), SELF)", new EffectDTO()
            {
                PropertyName  = (Name)"DialogueState([i])",
                NewValue      = (Name)"[ns]",
                ObserverAgent = (Name)"[t]"
            });


            wm.AddActionEffect((Name)"Event(Action-End, SELF, Speak([cs],[ns],*,*), [t])", new EffectDTO()
            {
                PropertyName  = (Name)"DialogueState([t])",
                NewValue      = (Name)"[ns]",
                ObserverAgent = (Name)"[i]"
            });

            foreach (var actor in rpcList)
            {
                foreach (var anotherActor in rpcList)
                {
                    if (actor != anotherActor)
                    {
                        var changed = new[] { EventHelper.ActionEnd(anotherActor.CharacterName.ToString(), "Enters", "Room") };
                        actor.Perceive(changed);
                    }
                }
            }



            List <Name>    _events  = new List <Name>();
            List <IAction> _actions = new List <IAction>();

            IAction action = null;

            while (true)
            {
                _actions.Clear();
                foreach (var rpc in rpcList)
                {
                    rpc.Tick++;

                    Console.WriteLine("Character perceiving: " + rpc.CharacterName + " its mood: " + rpc.Mood);

                    rpc.Perceive(_events);
                    var decisions = rpc.Decide();
                    _actions.Add(decisions.FirstOrDefault());

                    foreach (var act in decisions)
                    {
                        Console.WriteLine(rpc.CharacterName + " has this action: " + act.Name);
                    }
                }

                _events.Clear();

                var randomGen = new Random(Guid.NewGuid().GetHashCode());

                var pos = randomGen.Next(rpcList.Count);


                var initiator = rpcList[pos];


                action = _actions.ElementAt(pos);

                Console.WriteLine();
                if (action == null)
                {
                    Console.WriteLine(initiator.CharacterName + " does not have any action to do ");
                }

                if (action != null)
                {
                    var initiatorName = initiator.CharacterName.ToString();
                    var targetName    = action.Target.ToString();
                    var nextState     = action.Parameters[1].ToString();
                    var currentState  = action.Parameters[0].ToString();

                    Console.WriteLine("Action: " + initiatorName + " does " + action.Name + " to " +
                                      targetName + "\n" + action.Parameters[1]);

                    _events.Add(EventHelper.ActionEnd(initiatorName, action.Name.ToString(),
                                                      action.Target.ToString()));



                    Console.WriteLine();
                    Console.WriteLine("Dialogue:");
                    Console.WriteLine("Current State: " + currentState);
                    if (iat.GetDialogueActions(action.Parameters[0], action.Parameters[1], action.Parameters[2], action.Parameters[3]).FirstOrDefault() != null)
                    {
                        Console.WriteLine(initiator.CharacterName + " says: ''" +
                                          iat.GetDialogueActions(action.Parameters[0], action.Parameters[1], action.Parameters[2], action.Parameters[3]).FirstOrDefault().Utterance + "'' to " + targetName);
                    }
                    else
                    {
                        Console.WriteLine(initiator.CharacterName + " says: " + "there is no dialogue suited for this action");
                    }


                    // WORLD MODEL
                    var effects = wm.Simulate(_events.ToArray());
                    foreach (var ef in effects)
                    {
                        if (ef.ObserverAgent == (Name)"*")
                        {
                            foreach (var rpc in rpcList)
                            {
                                var proChange =
                                    EventHelper.PropertyChange(ef.PropertyName.ToString(), ef.NewValue.ToString(), "World");
                                rpc.Perceive(proChange);
                            }
                        }

                        else
                        {
                            var proChange =
                                EventHelper.PropertyChange(ef.PropertyName.ToString(), ef.NewValue.ToString(), "World");
                            rpcList.Find(x => x.CharacterName == ef.ObserverAgent).Perceive(proChange);
                        }
                    }

                    Console.WriteLine("Next State: " + nextState);
                }
                Console.WriteLine();
                Console.ReadKey();
            }
        }