Exemplo n.º 1
0
        public override void SetConfiguration(PluginV1 cf)
        {
            cf.STORAGE.AddIfNotExist(ConfigTitles.RESPONSE_VARIABLE, "$BotResponse");
            cf.STORAGE.AddIfNotExist(ConfigTitles.RESPONSE_SCRIPT, string.Empty);
            cf.STORAGE.AddIfNotExist(ConfigTitles.RESPONSE_XML, string.Empty);
            cf.STORAGE.AddIfNotExist(ConfigTitles.CONFIG_ROOT_FOLDER, EZ_Builder.Common.CombinePath(EZ_Builder.Constants.PLUGINS_FOLDER, cf._pluginGUID));

            EZ_Builder.Scripting.VariableManager.SetVariable(cf.STORAGE[ConfigTitles.RESPONSE_VARIABLE].ToString(), string.Empty);

            if (_bot == null)
            {
                try {
                    string configRootFolder = cf.STORAGE[ConfigTitles.CONFIG_ROOT_FOLDER].ToString();

                    string aimlFolder = EZ_Builder.Common.CombinePath(configRootFolder, "aiml");

                    string configFolder = EZ_Builder.Common.CombinePath(configRootFolder, "config");

                    string settingsFile = EZ_Builder.Common.CombinePath(configRootFolder, "config", "Settings.xml");

                    EZ_Builder.Invokers.SetAppendText(tbLog, false, "Loading AIM configuration... ");

                    _bot                   = new AIMLbot.Bot();
                    _bot.PathToAIML        = aimlFolder;
                    _bot.PathToConfigFiles = configFolder;
                    _bot.loadSettings(settingsFile);
                    _bot.loadAIMLFromFiles();
                    _bot.isAcceptingUserInput = true;
                    _bot.WrittenToLog        += _bot_WrittenToLog;

                    _user = new AIMLbot.User("DJ", _bot);

                    EZ_Builder.Invokers.SetAppendText(tbLog, true, "Success!");
                } catch (Exception ex) {
                    EZ_Builder.Invokers.SetAppendText(tbLog, true, ex.ToString());
                }
            }

            base.SetConfiguration(cf);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //powtarzamy czynnosci az nam się uda
            while (true)
            {
                agentVLuke_Jones = new AgentAPI(Listen); //tworzymy nowe AgentAPI,
                //podając w parametrze naszą metodę nasłuchującą

                // pobieramy parametry połączenia i agenta z klawiatury
                Console.Write("Wczytano IP serwera.\n");
                String ip = "atlantyda.vm.wmi.amu.edu.pl";

                Console.Write("Wczytano nazwe druzyny.\n");
                groupname = "VLuke_Jones";

                Console.Write("Wprowadzono haslo.\n");
                String grouppass = "******";

                Console.Write("Podaj nazwe swiata: ");
                String worldname = Console.ReadLine();

                Console.Write("Podaj imie: ");
                imie = Console.ReadLine();

                try
                {
                    //łączymy się z serwerem. Odbieramy parametry świata i wyświetlamy je
                    cennikSwiata = agentVLuke_Jones.Connect(ip, 6008, groupname, grouppass,
                        worldname, imie);
                    Console.WriteLine(cennikSwiata.initialEnergy + " - Maksymalna energia");
                    Console.WriteLine(cennikSwiata.maxRecharge + " - Maksymalne doładowanie");
                    Console.WriteLine(cennikSwiata.sightScope + " - Zasięg widzenia");
                    Console.WriteLine(cennikSwiata.hearScope + " - Zasięg słyszenia");
                    Console.WriteLine(cennikSwiata.moveCost + " - Koszt chodzenia");
                    Console.WriteLine(cennikSwiata.rotateCost + " - Koszt obrotu");
                    Console.WriteLine(cennikSwiata.speakCost + " - Koszt mówienia");

                    smallestCost = cennikSwiata.moveCost;
                    if (smallestCost > cennikSwiata.rotateCost)
                        smallestCost = cennikSwiata.rotateCost;
                    if (smallestCost > cennikSwiata.speakCost)
                        smallestCost = cennikSwiata.speakCost;
                    kosztDoZrodla = -1;

                    Console.Write("Wybierz tryb:\n(0)Random\n(1)SmartBot\n(2)Klawiatura\n");
                    String tryb = Console.ReadLine();

                    pozycjaRozmowcy = new int[2];
                    pozycjaRozmowcy[0] = -1000;
                    pozycjaRozmowcy[1] = -1000;
                    kierunekRozmowcy = 0;
                    czyRozmawiam = false;
                    gracz = false;

                    myBot = new AIMLbot.Bot();
                    myBot.loadSettings();
                    myBot.loadAIMLFromFiles();

                    //ustawiamy nasza energie na poczatkowa energie kazdego agenta w danym swiecie
                    myEnergy = cennikSwiata.initialEnergy;
                    if (tryb == "0")
                        Zachowanie("Random");
                    if (tryb == "1")
                        Zachowanie("SmartBot");
                    if (tryb == "2")
                    {
                        gracz = true;
                        KeyReader();
                    }
                    //na koncu rozlaczamy naszego agenta
                    try
                    {
                        agentVLuke_Jones.Disconnect();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Disconnected with problems! " + e.Message);
                    }
                    Console.ReadKey();
                    break;
                }
                //w przypadku mało poważnego błędu, jak podanie złego hasła,
                //rzucany jest wyjątek NonCriticalException; zaczynamy od nowa
                catch (NonCriticalException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                // w przypadku każdego innego wyjątku niż NonCriticalException
                //powinniśmy zakończyć program; taki wyjątek nie powinien się zdarzyć
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    Console.ReadKey();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Chatbot.Trigger"/> class.
        /// </summary>
        /// <param name="Chatbot">Chatbot.</param>
        public void Initialize(GameObject tmpchatbot)
        {
            // Save delivered GameObject
            chatbot = tmpchatbot;
            // Throw error if not Game Object delivered
            if (!chatbot)
            {
                Debug.LogWarning("To use chatbot you need to attatch ChatbotCore.cs script to a GameObject and pass GameObject to Chatbot. GameObject is empty.");
            }
            // Windows, Linux and Mac OSX
                        #if !(UNITY_WEBPLAYER || UNITY_WEBGL)
            else
            {
                // Initialize Program # variables
                bot     = new AIMLbot.Bot(this);
                user    = new AIMLbot.User("User", bot);
                request = new AIMLbot.Request("", user, bot);
                result  = new AIMLbot.Result(user, bot, request);
                // Global Settings
                Setting[] settings;
                // Gather all attatched settings from Scene
                settings = chatbot.GetComponentsInChildren <Setting>();
                // Loop through settings and
                foreach (Setting setting in settings)
                {
                    // Set global settings in Program# and Jurassic
                    SetGlobalSetting(setting.gameObject.name, setting.value);
                }
                // Load Settings from Scene Setting Components.
                bot.loadSettingsFromScene();
                // Load AIML files from AIML path defined in Settings.xml
                bot.loadAIMLFromFiles();

                // Define to or not to use JavaScript (Jurassic) in AIML
                bot.UseJavaScript = true;
                // Use Program # with Jurassic and Chatbot
                bot.ProgramSharpJSWithChatbot = true;
                // Create Triggers instance
                trigger = new Chatbot.Triggers();
                // Initializes triggers that are attatched
                // to the Chatbot. Needs to pass the
                // Chatbot Gameobject and Triggers instance
                trigger.Initialize(chatbot, this);
                // Create Motives instance
                motive = new Chatbot.Motives();
                // Initialize it
                motive.Initialize(chatbot);
                // Create Planner instance
                planner = new Chatbot.NestedPlanner();
                // Initialize planner
                planner.Initialize(chatbot, this, motive);
            }
                        #else
            // Webplayer plattform or WebGl
            ProgramSharpWebplayerCoroutine WebplayerCoroutine = chatbot.GetComponent <ProgramSharpWebplayerCoroutine>();
            if (WebplayerCoroutine != null && chatbot != null)
            {
                // Load settings from scene
                bot     = new AIMLbot.Bot(WebplayerCoroutine, Application.dataPath + "/Chatbot/Program #/advancedconfig/Settings.xml", true, this);
                user    = new AIMLbot.User("User", bot);
                request = new AIMLbot.Request("", user, bot);
                result  = new AIMLbot.Result(user, bot, request);

                // Define to or not to use JavaScript (Jurassic) in AIML
                bot.UseJavaScript = true;
                // Use Program # with Jurassic and Chatbot
                bot.ProgramSharpJSWithChatbot = true;
                // Create Triggers instance
                trigger = new Chatbot.Triggers();
                // Initializes triggers that are attatched
                // to the Chatbot. Needs to pass the
                // Chatbot Gameobject and Triggers instance
                trigger.Initialize(chatbot, this);
                // Create Motives instance
                motive = new Chatbot.Motives();
                // Initialize it
                motive.Initialize(chatbot);
                // Create Planner instance
                planner = new Chatbot.NestedPlanner();
                // Initialize planner
                planner.Initialize(chatbot, this, motive);
            }
            else
            {
                Debug.LogWarning("You need to attatch the Webplayer Component in Webplayer plattform mode.");
            }
                        #endif
        }