Esempio n. 1
0
        private void insert_Click(object sender, System.EventArgs e)
        {
            MacroAction a = null;

            try
            {
                if (varList.SelectedIndex == (int)IfAction.IfVarType.SysMessage)
                {
                    a = new IfAction((IfAction.IfVarType)varList.SelectedIndex, txtAmount.Text);
                }
                else if (varList.SelectedIndex >= (int)IfAction.IfVarType.BeginCountersMarker)
                {
                    a = new IfAction(IfAction.IfVarType.Counter, (sbyte)opList.SelectedIndex, Utility.ToInt32(txtAmount.Text, 0), varList.SelectedItem as string);
                }
                else
                {
                    a = new IfAction((IfAction.IfVarType)varList.SelectedIndex, (sbyte)opList.SelectedIndex, Utility.ToInt32(txtAmount.Text, 0));
                }
            }
            catch
            {
                return;
            }

            if (m_Action == null)
            {
                m_Macro.Insert(m_Idx + 1, a);
            }
            else
            {
                m_Action.Parent.Convert(m_Action, a);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Esempio n. 2
0
        private void insert_Click(object sender, System.EventArgs e)
        {
            MacroAction a = null;

            try
            {
                if (varList.SelectedIndex == (int)IfAction.IfVarType.SysMessage)
                {
                    a = new IfAction((IfAction.IfVarType)varList.SelectedIndex, txtAmount.Text);
                }
                else if (varList.SelectedIndex >= m_SkillStart)
                {
                    int skillId = -1;

                    foreach (Skill skill in World.Player.Skills)
                    {
                        if (Skills.GetSkillDisplayName(skill.Index).Equals(varList.SelectedItem as string))
                        {
                            skillId = skill.Index;
                            break;
                        }
                    }

                    if (skillId != -1)
                    {
                        a = new IfAction(IfAction.IfVarType.Skill, (sbyte)opList.SelectedIndex,
                                         Utility.ToDouble(txtAmount.Text, 0.0), skillId);
                    }
                }
                else if (varList.SelectedIndex >= (int)IfAction.IfVarType.BeginCountersMarker)
                {
                    a = new IfAction(IfAction.IfVarType.Counter, (sbyte)opList.SelectedIndex,
                                     Utility.ToInt32(txtAmount.Text, 0), varList.SelectedItem as string);
                }
                else
                {
                    a = txtAmount.Text.Contains("{") // using an if variable
                        ? new IfAction((IfAction.IfVarType)varList.SelectedIndex, (sbyte)opList.SelectedIndex,
                                       txtAmount.Text)
                        : new IfAction((IfAction.IfVarType)varList.SelectedIndex, (sbyte)opList.SelectedIndex,
                                       Utility.ToInt32(txtAmount.Text, 0));
                }
            }
            catch
            {
                return;
            }

            if (m_Action == null)
            {
                m_Macro.Insert(m_Idx + 1, a);
            }
            else
            {
                m_Action.Parent.Convert(m_Action, a);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Esempio n. 3
0
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (IfAction)actionHolder.Action;
     actionIfView.Refresh(new ActionHolder(_action.ActionIf), algoContext);
     actionElseView.Refresh(new ActionHolder(_action.ActionElse), algoContext);
     checkerView.Refresh(new ActionHolder(_action.Checker), algoContext);
 }
Esempio n. 4
0
        public static FlowActions <T> If <T>(
            this FlowActions <T> actions,
            Func <FlowContext <T>, Boolean> condition,
            Action <FlowActions <T> > trueActions,
            Action <FlowActions <T> > falseActions)
        {
            IFlowAction <T> ifaction = new IfAction <T>(condition, trueActions).Else(falseActions);

            return(actions.Add(ifaction));
        }
Esempio n. 5
0
        public static IfFlowActions <T> If <T>(
            this FlowActions <T> actions,
            Func <FlowContext <T>, Boolean> condition,
            Action <FlowActions <T> > action,
            String conditionText = Defaults.ConditionText,
            String actionText    = Defaults.ConditionActionText)
        {
            IfAction <T>      ifaction      = new IfAction <T>(condition, action, conditionText, actionText);
            IfFlowActions <T> ifFlowActions = new IfFlowActions <T>(actions, ifaction);

            return(ifFlowActions);
        }
Esempio n. 6
0
        public void TestMethod1()
        {
            ExpressionParser Parser   = ExpressionParser.CreateParser();
            IfAction         ifAction = new IfAction
            {
                Parser = Parser,
                ConditionExpression = "1=1$",
                IfTrueAction        = new DummyAction
                {
                    Parser = Parser
                }
            };

            ifAction.ExecuteAction();
            Assert.AreEqual(1, (ifAction.IfTrueAction as DummyAction).Count);
        }
Esempio n. 7
0
 private static void iffn(Tokenizer tokenizer, WordListBuilder wlb)
 {
     IfAction.If(tokenizer, wlb);
 }
Esempio n. 8
0
        public static void CreateSampleBot()
        {
            //create sample data
            var botConfig = new Models.BotConfig();

            botConfig.BotName     = "Platform Test Bot";
            botConfig.BotGreeting = "Hi! Welcome to chattr.  chattr is an easy-to-use chatbot platform which easily lets you build and deploy chatbots.  The platform supports exact phrase matches and machine learning to classify a request.";

            //create greeting FAQ
            var helpFAQ = new Conversation();

            helpFAQ.Name = "helpSample";
            helpFAQ.AddUtterance("help");
            helpFAQ.AddUtterance("!help");
            helpFAQ.AddUtterance("what can I ask you");
            helpFAQ.AddUtterance("halp");
            helpFAQ.AddUtterance("what can you do");
            helpFAQ.AddUtterance("what can I ask");
            helpFAQ.AddResponse("This is a sample use case -- you can ask me what chattr is. I also understand various hello/goodbye phrases.");
            botConfig.Conversations.Add(helpFAQ);

            var gitFAQ = new Conversation();

            gitFAQ.Name = "gitSample";
            gitFAQ.AddUtterance("what is github");
            gitFAQ.AddUtterance("whats github");
            gitFAQ.AddUtterance("define github");
            gitFAQ.AddUtterance("github");
            gitFAQ.AddUtterance("tell me about github");
            gitFAQ.AddResponse("GitHub brings together the world's largest community of developers to discover, share, and build better software.");
            botConfig.Conversations.Add(gitFAQ);

            var stackFAQ = new Conversation();

            stackFAQ.Name = "stackFAQ";
            stackFAQ.AddUtterance("tell me about the stack");
            stackFAQ.AddUtterance("what software stack is this");
            stackFAQ.AddUtterance("what is running this");
            stackFAQ.AddUtterance("what powers this application");
            stackFAQ.AddUtterance("what is powering this app");
            stackFAQ.AddResponse("This application is powered by C# -- ML.NET and Blazor!");
            botConfig.Conversations.Add(stackFAQ);

            //create greeting FAQ
            var greetingFAQ = new Conversation();

            greetingFAQ.Name = "greetingSample";
            greetingFAQ.AddUtterance("hello");
            greetingFAQ.AddUtterance("hi");
            greetingFAQ.AddUtterance("hi!");
            greetingFAQ.AddUtterance("hey");
            greetingFAQ.AddUtterance("good morning");
            greetingFAQ.AddUtterance("whats up");
            greetingFAQ.AddUtterance("how are you?");
            greetingFAQ.AddUtterance("Hi! How can I help you today?");
            greetingFAQ.AddResponse("Hi! How can I help you today?");
            greetingFAQ.AddResponse("Hey!");
            greetingFAQ.AddResponse("Hello. What can I do for you?");
            botConfig.Conversations.Add(greetingFAQ);

            //create farewell FAQ
            var farewellFAQ = new Conversation();

            farewellFAQ.Name = "farewellSample";
            farewellFAQ.AddUtterance("goodbye");
            farewellFAQ.AddUtterance("bye");
            farewellFAQ.AddUtterance("later");
            farewellFAQ.AddUtterance("see ya");
            farewellFAQ.AddUtterance("c ya");
            farewellFAQ.AddUtterance("lates");
            farewellFAQ.AddUtterance("Bye!");
            farewellFAQ.AddUtterance("ttyl");
            farewellFAQ.AddResponse("Take Care!");
            botConfig.Conversations.Add(farewellFAQ);

            //create csharp FAQ
            var csharpFAQ = new Conversation();

            csharpFAQ.Name = "chatterFAQ";
            csharpFAQ.AddUtterance("What is chattr");
            csharpFAQ.AddUtterance("Whats chattr");
            csharpFAQ.AddUtterance("tell me about chattr");
            csharpFAQ.AddResponse("chattr is a free and open source platform to build chatbots!");
            csharpFAQ.AddSynonym("chattr", "this platform");
            botConfig.Conversations.Add(csharpFAQ);

            //create custom conversation with two responses
            var weatherRequest = new Conversation();

            weatherRequest.Name           = "weatherRequest";
            weatherRequest.StartNode.Name = "weatherStart";

            //add utterances to trigger this intent
            weatherRequest.AddUtterance("Check the weather");
            weatherRequest.AddUtterance("Weather check");
            weatherRequest.AddUtterance("weather");
            weatherRequest.AddUtterance("Check Weather");

            //create reply action
            var firstReply = new ReplyAction();

            firstReply.AddResponse("The weather is 85 degrees in Florida");
            weatherRequest.Actions.Add(firstReply);
            weatherRequest.StartNode.LinkTo(firstReply);

            //create another reply
            var secondReply = new ReplyAction();

            secondReply.AddResponse("The weather is 70 degrees in New York");
            weatherRequest.Actions.Add(secondReply);
            firstReply.LinkTo(secondReply);

            botConfig.Conversations.Add(weatherRequest);



            //Showcase ability to conditionally check data, and ask/store what the user's color preference is.
            //On the second time, the bot will tell the stored data instead of asking for it
            var favColorConvo = new Conversation();

            favColorConvo.SetConversationName("favoriteColorPref");
            favColorConvo.SetStartActionName("favoriteColorPrefStart");
            favColorConvo.AddUtterances(new[] { "What color do I prefer?", "Ask me my favorite color", "Ask what my favorite color is", "Ask me my color preference" });

            //create input action when color is unknown
            var askForColorPreference = new InputAction();

            askForColorPreference.SetActionName("favoriteColor");
            askForColorPreference.AddResponse("Ok, tell me your color preference and I will store it between conversations.  What is your favorite color?  You can say 'red', 'blue', or 'green'.  I will not allow any other values.");
            askForColorPreference.EnableContextStorage(true, "colorpref");
            askForColorPreference.RequireValidation(true, new[] { "red", "blue", "green" });
            favColorConvo.AddAction(askForColorPreference);

            //create confirmation when color is unknown
            var confirmColorPreference = new ReplyAction();

            confirmColorPreference.SetActionName("replyPrefSet");
            confirmColorPreference.AddResponse("Ok, I now know your favorite color which is {colorpref}.  You can ask me this same question again and I will reply it back to you!");
            favColorConvo.AddAction(confirmColorPreference);

            //create confirmation reply when color is known
            var knownReply = new ReplyAction();

            knownReply.SetActionName("replyPrefKnown");
            knownReply.AddResponse("Ha! I remember you told my that your favorite color is {colorpref}.");
            favColorConvo.AddAction(knownReply);

            //create conditional check
            var performColorCheck = new IfAction();

            performColorCheck.SetActionName("colorCheck");
            favColorConvo.AddAction(performColorCheck);

            //Link all of the actions above together

            //Link Start > Conditional Check
            favColorConvo.LinkStartNodeTo(performColorCheck);

            //Conditional Check:
            // > Default to Input Action to get data
            // > If colorpref variable exists (this question was asked already) then skip to 'Known' Reply Node amd
            performColorCheck.DefaultTo(askForColorPreference);
            performColorCheck.Unless(IfTestType.ContextVariableExists, "", "colorpref", knownReply);

            //Link Input Action > 'Confirmation' Reply Node
            askForColorPreference.LinkTo(confirmColorPreference);

            //add this conversation to the collection
            botConfig.AddConversation(favColorConvo);


            //train a model based on the created configuration
            var modelName = Platform.AIService.Train(botConfig);

            botConfig.ModelFile = modelName;

            //save bot
            botConfig.Save();
        }
Esempio n. 9
0
    public bool ifValid(IfAction nextIf, GameObject scripted)
    {
        bool ifok = nextIf.ifNot;

        Debug.Log("ifvalid " + ifok);
        Vector2 vec = new Vector2();

        switch (getDirection(scripted.GetComponent <Direction>().direction, nextIf.ifDirection))
        {
        case Direction.Dir.North:
            vec = new Vector2(0, 1);
            break;

        case Direction.Dir.South:
            vec = new Vector2(0, -1);
            break;

        case Direction.Dir.East:
            vec = new Vector2(1, 0);
            break;

        case Direction.Dir.West:
            vec = new Vector2(-1, 0);
            break;
        }
        switch (nextIf.ifEntityType)
        {
        case 0:
            foreach (GameObject go in wallGO)
            {
                if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * nextIf.range &&
                    go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * nextIf.range)
                {
                    ifok = !nextIf.ifNot;
                }
            }
            break;

        case 1:
            foreach (GameObject go in doorGO)
            {
                if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * nextIf.range &&
                    go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * nextIf.range)
                {
                    ifok = !nextIf.ifNot;
                }
            }
            break;

        case 2:
            foreach (GameObject go in droneGO)
            {
                if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * nextIf.range &&
                    go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * nextIf.range)
                {
                    ifok = !nextIf.ifNot;
                }
            }
            break;

        case 3:
            foreach (GameObject go in playerGO)
            {
                if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * nextIf.range &&
                    go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * nextIf.range)
                {
                    ifok = !nextIf.ifNot;
                }
            }
            break;

        case 4:
            foreach (GameObject go in activableConsoleGO)
            {
                if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * nextIf.range &&
                    go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * nextIf.range)
                {
                    ifok = !nextIf.ifNot;
                }
            }
            break;

        case 5:
            foreach (GameObject go in redDetectorGO)
            {
                if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * nextIf.range &&
                    go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * nextIf.range)
                {
                    ifok = !nextIf.ifNot;
                }
            }
            break;

        case 6:
            foreach (GameObject go in coinGO)
            {
                if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * nextIf.range &&
                    go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * nextIf.range)
                {
                    ifok = !nextIf.ifNot;
                }
            }
            break;
        }
        return(ifok);
    }