Пример #1
0
        public int StateExists(string s)
        {
            var r = SBubble.HaveState(s);

            //BubConsole.CSay($"Sending outcome {r} to Lua!");
            if (r)
            {
                return(1);
            }
            return(0);
        }
Пример #2
0
 public void KillFlow(string flow)
 {
     flow = flow.ToUpper();
     if (!qstr.Prefixed(flow, "FLOW_"))
     {
         flow = $"FLOW_{flow}";
     }
     if (SBubble.HaveState(flow))
     {
         SBubble.MyError("Flow Management Error", $"KillFlow: Flow {flow} doesn't exist!", SBubble.TraceLua(State));
     }
     SBubble.KillState(flow);
 }
Пример #3
0
 static public void KillSoftFlow(string tag)
 {
     tag = tag.ToUpper();
     if (!qstr.Prefixed(tag, "FLOW_"))
     {
         tag = $"FLOW_{tag}";
     }
     if (SBubble.HaveState(tag))
     {
         SBubble.MyError($"KillFlow(\"{tag}\"):", "Tag non-existent", "");
     }
     else
     {
         SBubble.KillState(tag);
     }
 }
Пример #4
0
 public void GoToFlow(string flow)
 {
     flow = flow.ToUpper();
     if (!qstr.Prefixed(flow, "FLOW_"))
     {
         flow = $"FLOW_{flow}";
     }
     if (!SBubble.HaveState(flow))
     {
         SBubble.MyError("Flow Management Error", $"GoToFlow: Flow {flow} doesn't exist!", SBubble.TraceLua(State));
     }
     else
     {
         FlowManager.CurrentFlow = flow;
         BubConsole.WriteLine($"Flow set to: {flow}");
         SBubble.State(flow).DoString("if BUB_Arrive then assert(type(BUB_Arrive)=='function','BUB_Arrive must be a function but it is a '..type(BUB_Arrive)) BUB_Arrive() end");
     }
 }
Пример #5
0
        void Exe(string rawcmd)
        {
            rawcmd = rawcmd.Trim();
            if (rawcmd == "")
            {
                return;
            }
            string[] chopped;
            {
                var chop = new List <string>();
                var str  = false;
                var s    = "";
                for (int i = 0; i < rawcmd.Length; i++)
                {
                    switch (rawcmd[i])
                    {
                    case '"': str = !str; break;

                    case ' ':
                        if (str)
                        {
                            goto default;          // diryt way to fallthrough, but it's the only thing C# supports!
                        }
                        chop.Add(s);
                        s = "";
                        break;

                    default:
                        s += rawcmd[i];
                        break;
                    }
                }
                chop.Add(s);
                chopped = chop.ToArray();
            }
            string cmd = chopped[0].ToUpper();

            string[] arg = new string[0];
            if (chopped.Length > 1)
            {
                arg = chopped.Skip(1).Take(chopped.Length - 1).ToArray();
            }

            switch (cmd)
            {
            case "F**K":
            case "PISS":
            case "SHIT":
                WriteLine("?Did you mother never tell you not to say such words?", 255, 0, 0);
                break;

            case "BYE":
            case "EXIT":
            case "QUIT":
                FlowManager.TimeToDie = true;
                break;

            case "SAY":
                foreach (string a in arg)
                {
                    CSay(a);
                }
                break;

            default:
                try {
                    // Need to group as some extra vars are needed!
                    {
                        var CFlow = FlowManager.CurrentFlow;
                        var FFlow = $"FLOW_{CFlow}";
                        var SFlow = SBubble.State(CFlow);
                        var JArgs = "";
                        BubConsScriptSuccess = false;
                        foreach (string a in arg)
                        {
                            if (JArgs != "")
                            {
                                JArgs += ", ";
                            }
                            JArgs += $"\"{a}\"";
                        }
                        // Execute local if available
                        SFlow.DoString($"if not ConsoleCommands then ConsoleSuccess(false) return end\nif not ConsoleCommands['.hasmember']('{cmd}') then ConsoleSuccess(false) return end\nConsoleSuccess(true)\nConsoleCommands.{cmd}({JArgs})");
                        if (BubConsScriptSuccess)
                        {
                            break;                           // If done, get outta here
                        }
                        // Load the global commands if needed
                        if (!SBubble.HaveState("DEBUG_CONSOLE_COMMANDS"))
                        {
                            WriteLine("Since this is the first time the Debug Console Commands are neeed", 255, 180, 0);
                            WriteLine("The commands need to be loaded now, just a moment", 255, 180, 0);
                            SBubble.NewState("DEBUG_CONSOLE_COMMANDS", "Script/System/Console.nil");
                            WriteLine("Ok", 0, 255, 255);
                        }
                        // Execute gloal
                        SBubble.State("DEBUG_CONSOLE_COMMANDS").DoString($"if not ConsoleCommands then CSay('Hey buddy! No ConsoleCommands group exists!') ConsoleSuccess(false) return end\nif not ConsoleCommands['.hasmember']('{cmd}') then ConsoleSuccess(false) return end\nConsoleSuccess(true)\nConsoleCommands.{cmd}({JArgs})");
                        if (BubConsScriptSuccess)
                        {
                            break;                          // If done, get outta here
                        }
                    }
                    // Failure, or so it seems.
                    WriteLine("?Not understood", 255, 0, 0);
                } catch (Exception NietGoed) {
                    WriteLine("?.NET error", 255, 0, 0);
                    WriteLine($"  {NietGoed.Message}", 255, 255, 0);
                }
                break;
            }
        }