Esempio n. 1
0
        /// <summary>
        /// Track when and how this event was invoked first time;
        /// Only for development to learn if and when events are called.
        /// </summary>
        private static void TrackInvocation(ScriptEvent eventType, ScriptEventArgs eventArgs)
        {
            var invocationLog = Environment.NewLine +
                                DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine +
                                JsonMapper.ToJson(eventArgs) + Environment.NewLine +
                                Environment.StackTrace;

            var invokedEvent = PersistentData.Instance.InvokedEvents.FirstOrDefault(ie => ie.EventName == eventType.ToString());

            if (invokedEvent == null)
            {
                invokedEvent = new PersistentData.InvokedEvent()
                {
                    EventName = eventType.ToString(),
                    LastCalls = new List <string>()
                };
                PersistentData.Instance.InvokedEvents.Add(invokedEvent);
            }

            // Rotate last 10 call logs with newest on top
            if (invokedEvent.LastCalls.Count == 10)
            {
                invokedEvent.LastCalls.RemoveAt(invokedEvent.LastCalls.Count - 1);
            }
            invokedEvent.LastCalls.Insert(0, invocationLog.Indent(10) + Environment.NewLine + new string(' ', 8));

            PersistentData.Instance.SaveLater();
        }
Esempio n. 2
0
        public override IEnumerator <YieldInstruction> Apply(GameEventOwner owner, Character ownerChar, Character character)
        {
            object[]    parameters = new object[] { owner, ownerChar, character };
            LuaFunction func_iter  = LuaEngine.Instance.CreateCoroutineIterator(Script, parameters);

            return(ScriptEvent.ApplyFunc(func_iter));
        }
Esempio n. 3
0
        public void RenderActions()
        {
            ActionPoker a = new ActionPoker();
            ScriptEvent e = new ScriptEvent(a, "HelloEvent", true);

            StringWriter     sw;
            ScriptTextWriter w;

            // test an empty event
            sw = new StringWriter();
            w  = new ScriptTextWriter(sw);

            e.RenderActions(w);
            Assert.AreEqual("", sw.ToString(), "A1");

            // now add an action and see what happens
            ActionPoker action = new ActionPoker();

            action.ID     = "action_id";
            action.Target = "action_target";

            e.Actions.Add(action);

            e.RenderActions(w);
            Assert.AreEqual("<HelloEvent>\n  <poker id=\"action_id\" target=\"action_target\" />\n</HelloEvent>", sw.ToString().Replace("\r\n", "\n"), "A2");
        }
Esempio n. 4
0
        public void AddZoneScriptEvent(int idx, LuaEngine.EZoneCallbacks ev)
        {
            string assetName = "zone_" + idx;

            DiagManager.Instance.LogInfo(String.Format("Zone.AddZoneScriptEvent(): Added event {0} to zone {1}!", ev.ToString(), assetName));
            ScriptEvents[ev] = new ScriptEvent(LuaEngine.MakeZoneScriptCallbackName(assetName, ev));
        }
 public static void RunEventScripts(GitModuleForm form, ScriptEvent scriptEvent)
 {
     foreach (var scriptInfo in GetScripts().Where(scriptInfo => scriptInfo.Enabled && scriptInfo.OnEvent == scriptEvent))
     {
         ScriptRunner.RunScript(form, form.Module, scriptInfo.Name, null);
     }
 }
Esempio n. 6
0
        public void ExecuteEvent(string filePath, ScriptEvent eventType, object eventArgs)
        {
            ResetEngine();
            InitCommonValues();
            SetValue("eventType", eventType.ToString());
            SetValue("event", eventArgs);

            var oldDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(Path.GetDirectoryName(filePath) ?? Path.PathSeparator.ToString());

            try
            {
                ExecuteFile(filePath);
            }
            // LuaScriptException is already handled in LuaEngine
            // JavaScriptException is already handled in JsEngine
            catch (Exception ex)
            {
                var fileRelativePath = FileTools.GetRelativePath(filePath, Constants.ScriptsFolder);
                Log.Error($"Script {fileRelativePath} failed: " + ex);
            }

            Directory.SetCurrentDirectory(oldDirectory);
        }
Esempio n. 7
0
        public void Ctor()
        {
            ActionPoker a = new ActionPoker();
            ScriptEvent e = new ScriptEvent(a, "HelloEvent", true);

            Assert.AreEqual("HelloEvent", e.Name, "A1");
            Assert.IsTrue(e.SupportsActions, "A2");
        }
Esempio n. 8
0
        public void No_SupportsActions()
        {
            ActionPoker a = new ActionPoker();
            ScriptEvent e = new ScriptEvent(a, "HelloEvent", false);

            Assert.IsNotNull(e.Actions, "A1");
            e.Actions.Add(new ActionPoker());
        }
Esempio n. 9
0
 public SelectBox(WidgetFactory ace)
     : base(ace)
 {
     this.Widget      = "selectbox";
     this.PanelWidth  = 750;
     this.PanelHeight = 450;
     ScriptEvent.Regist(Events, OnBeforeShowPanel, "AX.selShow");
 }
Esempio n. 10
0
    public void AddEvent(ScriptEvent _event)
    {
        if (!_event)
        {
            return;
        }

        eventlist.Add(_event);
    }
Esempio n. 11
0
            public static ScriptEvent CreateFromXml(System.Xml.XmlElement n)
            {
                ScriptEvent e = new ScriptEvent();

                e.key = n.GetAttribute("key");
                e.val = n.GetAttribute("value");

                return(e);
            }
Esempio n. 12
0
 public void AddEventHandler(ScriptEvent @event, Action <object> handler)
 {
     if (!handlers.TryGetValue(@event, out var eventHandlers))
     {
         eventHandlers    = new List <Action <object> >();
         handlers[@event] = eventHandlers;
     }
     eventHandlers.Add(handler);
 }
Esempio n. 13
0
        void DoPropertyChanged(IScriptObject owner, ScriptEvent PropertyChanged)
        {
            Assert.AreEqual("propertyChanged", PropertyChanged.Name, "p1");
            Assert.AreEqual(true, PropertyChanged.SupportsActions, "p2");
            Assert.AreEqual("", PropertyChanged.Handler, "p3");
            Assert.IsNotNull(PropertyChanged.Actions, "p4");

            DoActions(owner, PropertyChanged.Actions);
        }
Esempio n. 14
0
        public void SupportsActions()
        {
            ActionPoker a = new ActionPoker();
            ScriptEvent e = new ScriptEvent(a, "HelloEvent", true);

            Assert.IsNotNull(e.Actions, "A1");
            e.Actions.Add(new ActionPoker());
            Assert.AreEqual(1, e.Actions.Count, "A2");
        }
Esempio n. 15
0
 /// <summary>
 /// Call event handlers defined at user-defined scripts.
 /// </summary>
 /// <param name="event">
 /// Fired event.
 /// </param>
 public void FireScriptEvent(ScriptEvent @event)
 {
     foreach (var scriptFile in ScriptFiles)
     {
         foreach (var program in Programs)
         {
             scriptFile.FireEvent(@event, program);
         }
     }
 }
Esempio n. 16
0
 public void LoadScriptEvents(List <LuaEngine.EZoneCallbacks> scriptEvents)
 {
     ScriptEvents.Clear();
     foreach (LuaEngine.EZoneCallbacks ev in scriptEvents)
     {
         string assetName = "zone_" + this.ID;
         DiagManager.Instance.LogInfo(String.Format("Zone.LoadScriptEvents(): Added event {0} to zone {1}!", ev.ToString(), assetName));
         ScriptEvents[ev] = new ScriptEvent(LuaEngine.MakeZoneScriptCallbackName(assetName, ev));
     }
 }
Esempio n. 17
0
        private void RenderScriptEvent(HtmlTextWriter writer, ScriptEvent script)
        {
            RenderCommonScriptAttributes(writer, script);
            writer.AddAttribute(HtmlTextWriterAttribute.For, script.Element);
            writer.AddAttribute("event", script.EventName);

            writer.RenderBeginTag(HtmlTextWriterTag.Script);
            writer.WriteLine(script.Script);
            writer.RenderEndTag();
        }
Esempio n. 18
0
 /// <summary>
 /// Search the current dungeon's lua package for defined floor callbacks functions, and add those that were found.
 /// </summary>
 private void LoadScriptEvents()
 {
     foreach (var ev in LuaEngine.EnumerateDungeonFloorCallbackTypes())
     {
         string cbackn = LuaEngine.MakeDungeonMapScriptCallbackName(AssetName, ev);
         if (LuaEngine.Instance.DoesFunctionExists(cbackn))
         {
             ScriptEvents[ev] = new ScriptEvent(cbackn);
         }
     }
 }
Esempio n. 19
0
 public void FireEvent(ScriptEvent @event, object programWrapper)
 {
     if (!handlers.TryGetValue(@event, out var eventHandlers))
     {
         return;
     }
     foreach (var eventHandler in eventHandlers)
     {
         eventHandler(programWrapper);
     }
 }
Esempio n. 20
0
 /// <inheritdoc />
 public string GetScriptName(Entity entity, ScriptEvent @event)
 {
     try
     {
         var scriptGroup = entity.GetComponent <ScriptGroup>();
         return(scriptGroup[@event]);
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
Esempio n. 21
0
        public static void RunEventScripts(GitModule aModule, ScriptEvent scriptEvent)
        {
            foreach (ScriptInfo scriptInfo in GetScripts())
                if (scriptInfo.Enabled && scriptInfo.OnEvent == scriptEvent)
                {
                    if (scriptInfo.AskConfirmation)
                        if (MessageBox.Show(String.Format("Do you want to execute '{0}'?", scriptInfo.Name), "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            continue;

                    ScriptRunner.RunScript(aModule, scriptInfo.Name, null);
                }
        }
 private void CheckInvoke(ScriptEvent e)
 {
                 #if UNITY_EDITOR
     if (!Application.isPlaying && !_editMode)
     {
         return;
     }
                 #endif
     if (_event == e)
     {
         _onEvent.Invoke();
     }
 }
Esempio n. 23
0
    public static void HandleNpcTalkEventType(GameSession session, NpcScript npcScript, int eventId)
    {
        ScriptEvent scriptEvent = npcScript.Contents.First().Events.FirstOrDefault(x => x.Id == eventId);

        if (scriptEvent is null)
        {
            return;
        }

        int          indexContent  = Random.Shared.Next(scriptEvent.Contents.Count);
        EventContent eventContents = scriptEvent.Contents[indexContent];

        session.Send(NpcTalkPacket.CustomText(eventContents.Text, eventContents.VoiceId, eventContents.Illustration));
    }
Esempio n. 24
0
            public async void Publish(ScriptEvent scriptEvent)
            {
                // Emulate long worker status latency
                await Task.Delay(WaitBeforePublish);

                try
                {
                    _scriptEventManager.Publish(scriptEvent);
                }
                catch (ObjectDisposedException)
                {
                    // Do no throw ObjectDisposedException
                }
            }
Esempio n. 25
0
        /// <summary>
        /// shortcut function to write to the console
        /// </summary>
        /// <param name="text"></param>
        //public static void Write(string text)
        //{
        //    Console.WriteLine("[{0}] {1}", DateTime.Now.ToShortTimeString(), text);
        //}

        /// <summary>
        /// swaps position of two elements in a collection
        /// </summary>
        /// <param name="list"></param>
        /// <param name="indexA"></param>
        /// <param name="indexB"></param>
        public static void Swap(IList <ScriptEvent> list, int indexA, int indexB)
        {
            // store temp version of element object
            //
            ScriptEvent tmp = list[indexA];

            // move element at index b to the location of the element we stored
            //
            list[indexA] = list[indexB];

            // move the stored element to the location of index b
            //
            list[indexB] = tmp;
        }
Esempio n. 26
0
        void DoScriptEvents(IScriptObject owner, ScriptEventCollection ScriptEvents)
        {
            Assert.AreEqual(1, ((ICollection)ScriptEvents).Count, "e1");
            IEnumerator <ScriptEvent> e = ((IEnumerable <ScriptEvent>)ScriptEvents).GetEnumerator();

            e.MoveNext();

            ScriptEvent ev = e.Current;

            Assert.AreEqual("propertyChanged", ev.Name, "p1");
            Assert.AreEqual(true, ev.SupportsActions, "p2");
            Assert.AreEqual("", ev.Handler, "p3");
            Assert.IsNotNull(ev.Actions, "p4");

            DoActions(owner, ev.Actions);
        }
Esempio n. 27
0
        public void Properties()
        {
            ActionPoker a = new ActionPoker();
            ScriptEvent e = new ScriptEvent(a, "HelloEvent", true);

            // defaults not specified in the ctor
            Assert.AreEqual("", e.Handler, "A1");

            // getter/setter
            e.Handler = "foo";
            Assert.AreEqual("foo", e.Handler, "A2");

            // setting to null
            e.Handler = null;
            Assert.AreEqual("", e.Handler, "A5");
        }
Esempio n. 28
0
        public void RenderHandlers()
        {
            ActionPoker a = new ActionPoker();
            ScriptEvent e = new ScriptEvent(a, "HelloEvent", true);

            StringWriter     sw;
            ScriptTextWriter w;

            sw = new StringWriter();
            w  = new ScriptTextWriter(sw);

            e.Handler = "hi there";

            e.RenderHandlers(w);
            Assert.AreEqual("HelloEvent=\"hi there\"", sw.ToString(), "A1");
        }
Esempio n. 29
0
        public static void RunEventScripts(ScriptEvent scriptEvent)
        {
            foreach (ScriptInfo scriptInfo in GetScripts())
            {
                if (scriptInfo.Enabled && scriptInfo.OnEvent == scriptEvent)
                {
                    if (scriptInfo.AskConfirmation)
                    {
                        if (MessageBox.Show("Do you want to execute '" + scriptInfo.Name + "'?", "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            continue;
                        }
                    }

                    ScriptRunner.RunScript(scriptInfo.Name, null);
                }
            }
        }
Esempio n. 30
0
        public static void RunEventScripts(GitModuleForm form, ScriptEvent scriptEvent)
        {
            foreach (ScriptInfo scriptInfo in GetScripts())
            {
                if (scriptInfo.Enabled && scriptInfo.OnEvent == scriptEvent)
                {
                    if (scriptInfo.AskConfirmation)
                    {
                        if (MessageBox.Show(form, String.Format("Do you want to execute '{0}'?", scriptInfo.Name), "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            continue;
                        }
                    }

                    ScriptRunner.RunScript(form, form.Module, scriptInfo.Name, null);
                }
            }
        }
Esempio n. 31
0
 public override void FireEvent(ScriptEvent @event, Program program)
 {
     try
     {
         var programAPI     = new RekoProgramAPI(program);
         var programWrapper = pythonAPI.CreateProgramWrapper(
             programAPI);
         eventsAPI.FireEvent(@event, programWrapper);
     }
     catch (Exception ex)
     {
         eventListener.Error(
             new NullCodeLocation(Filename),
             ex,
             "An error occurred while running the Python script.");
         DumpPythonStack(ex, engine);
     }
 }
Esempio n. 32
0
            public static ScriptEvent CreateFromXml( System.Xml.XmlElement n)
            {
                ScriptEvent e = new ScriptEvent();

                e.key = n.GetAttribute("key");
                e.val = n.GetAttribute("value");

                return e;
            }
Esempio n. 33
0
        public ScriptNode CompileScriptNode(string nodeName, string text, StringTable stringTable, Type self)
        {
            if (String.IsNullOrEmpty(text))
                throw new GossipScriptException("Script cannot be null or empty");

            var scriptletInfo = ScriptNodeParser.ParseScriptNode(text);

            var rv = new ScriptNode(nodeName);

            if (scriptletInfo.OnUpdateScript != null)
            {
                var tokens = Lexer.Tokenize(scriptletInfo.OnUpdateScript.EventScript).ToList();
                PopulateStringTable(tokens, stringTable);
                rv.OnUpdateEvent = new ScriptEvent(CompileEvent(tokens, self, stringTable), 0);
            }

            if (scriptletInfo.OnExitScript != null)
            {
                List<Token> tokens = Lexer.Tokenize(scriptletInfo.OnExitScript.EventScript).ToList();
                PopulateStringTable(tokens, stringTable);
                rv.OnEndEvent = new ScriptEvent(CompileEvent(tokens, self, stringTable), 0);
            }

            if (scriptletInfo.OnEnterScript != null)
            {
                List<Token> tokens = Lexer.Tokenize(scriptletInfo.OnEnterScript.EventScript).ToList();
                PopulateStringTable(tokens, stringTable);
                rv.OnStartEvent = new ScriptEvent(CompileEvent(tokens, self, stringTable), 0);
            }

            if (scriptletInfo.OnInterruptScript != null)
            {
                List<Token> tokens = Lexer.Tokenize(scriptletInfo.OnInterruptScript.EventScript).ToList();
                PopulateStringTable(tokens, stringTable);
                rv.OnInterruptEvent = new ScriptEvent(CompileEvent(tokens, self, stringTable), 0);
            }

            // Custom events
            foreach (ScriptNodeEventInfo customEvent in scriptletInfo.CustomEventScripts)
            {
                List<Token> tokens = Lexer.Tokenize(customEvent.EventScript).ToList();
                PopulateStringTable(tokens, stringTable);

                EventBinding binding = m_Engine.HostBridge.EventBindingTable.GetBindingByName(customEvent.Token.Value);
                var scriptletEvent =
                    new ScriptEvent(CompileEvent(tokens, self, stringTable, binding.EventParameterType), binding.Id);

                rv.OnCustomEvents.Add(scriptletEvent);
            }

            return rv;
        }