예제 #1
0
        // -------------------------------------------------EVENTS-----------------------------------------------------
        public void CommandReceived(User user, bool IsMod, string Message)
        {
            // Should probably add an event handler, but RegisterLuaDelegateType is poorly documented.

            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
            {
                try
                {
                    List <string> strlist = new List <string>(Message.Split(" "));
                    if (Environment["command_" + strlist[0].Substring(1)] == null)
                    {
                        //IRC_Functions.SendMessage(ParentChannel, "Command not found.");
                        return;
                    }

                    NLua.LuaFunction MessageReceived = Environment["command_" + strlist[0].Substring(1)] as NLua.LuaFunction;
                    strlist.RemoveAt(0);
                    MessageReceived.Call(user.Username, IsMod, strlist); // Safer way to call than using DoString
                } catch (NLua.Exceptions.LuaScriptException e)
                {
                    //IRC_Functions.SendMessage(ParentChannel, "Script failed");
                    Log.Logger.OutputToConsole(e.ToString());
                } catch {
                    // Do nothing
                }
            }), null);
        }
예제 #2
0
        public void Wait(double Seconds, NLua.LuaFunction Action)
        {
            DispatcherTimer Timer = new DispatcherTimer()
            {
                Interval = System.TimeSpan.FromSeconds(Seconds)
            };

            Timer.Tick += delegate
            {
                Action.Call();
                Timer.Stop();
            };
            Timer.Start();
        }
예제 #3
0
        internal void Run(ISender sender, string args)
        {
            if (BeforeEvent != null)
            {
                BeforeEvent(this);
            }

            try
            {
                if (!CommandParser.CheckAccessLevel(this, sender))
                {
                    sender.SendMessage("You cannot perform that action.", 255, 238, 130, 238);
                    return;
                }

                if (stringCallback != null)
                {
                    stringCallback(sender, args);
                }
                else if (LuaCallback != null)
                {
                    LuaCallback.Call(this, sender, args);
                }
                else
                {
                    sender.SendMessage("This command is no longer available", 255, 238, 130, 238);
                }
            }
            finally
            {
                if (AfterEvent != null)
                {
                    AfterEvent(this);
                }
            }
        }
예제 #4
0
 public void ForEach(IEnumerable List, NLua.LuaFunction Function)
 {
     try
     {
         foreach (var Object in List)
         {
             Function.Call(Object);
         }
     }
     catch (Exception ex)
     {
         ((LuaDebug)LuaMain.LuaState["Debug"]).Log(
             ex.Message, "Red");
     }
 }
예제 #5
0
        public void AddEvent(Guid Id, string Occasion, NLua.LuaFunction Func)
        {
            Delegate Handler;

            switch (Occasion)
            {
            case "OnTurn":
                Handler = new EventHandler((Sender, Args) => { Console.WriteLine(@"CallSuccess"); Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                OnTurn += (EventHandler)Handler;
                break;

            case "Attacking":
                Handler = new EventHandler <DoingEventArgs>((Sender, Args) => { Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                Attacking += (EventHandler <DoingEventArgs>)Handler;
                break;

            case "Attacked":
                Handler = new EventHandler <DoneEventArgs>((Sender, Args) => { Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                Attacked += (EventHandler <DoneEventArgs>)Handler;
                break;

            case "UnderAttack":
                Handler = new EventHandler <UnderAttackEventArgs>((Sender, Args) => { Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                UnderAttack += (EventHandler <UnderAttackEventArgs>)Handler;
                break;

            case "Defending":
                Handler = new EventHandler <DoingEventArgs>((Sender, Args) => { Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                Defending += (EventHandler <DoingEventArgs>)Handler;
                break;

            case "Defended":
                Handler = new EventHandler <DoneEventArgs>((Sender, Args) => { Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                Defended += (EventHandler <DoneEventArgs>)Handler;
                break;

            case "CountAttacking":
                Handler = new EventHandler <DoingEventArgs>((Sender, Args) => { Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                CounterAttacking += (EventHandler <DoingEventArgs>)Handler;
                break;

            case "CountAttacked":
                Handler = new EventHandler <DoneEventArgs>((Sender, Args) => { Func.Call(Sender, Args); });
                EventDictionary.Add(Id, Handler);
                CounterAttacked += (EventHandler <DoneEventArgs>)Handler;
                break;
            }
        }
예제 #6
0
        public void ChatMessageReceived(User user, bool IsMod, string Message)
        {
            // Should probably add an event handler, but RegisterLuaDelegateType is poorly documented.

            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
            {
                try
                {
                    NLua.LuaFunction MessageReceived = Environment["event_MessageReceived"] as NLua.LuaFunction;
                    MessageReceived.Call(user.Username, IsMod, Message); // Safer way to call than using DoString
                } catch (NLua.Exceptions.LuaScriptException e)
                {
                    IRC_Functions.SendMessage(ParentChannel, "Script failed");
                    Log.Logger.OutputToConsole(e.ToString());
                } catch {
                    // Do nothing
                }
            }), null);
        }
        internal void Execute()
        {
            bool bDone = false;

            for (int i = 0; i < EncounterInfo.encounterGroups.Count; i++)
            {
                for (int j = 0; j < EncounterInfo.encounterGroups[i].charactersInGroup.Count; j++)
                {
                    if (parentLocation.positionGrid == EncounterInfo.encounterGroups[i].charactersInGroup[j].positionToMapCoords())
                    {
                        bDone = true;
                        if (callFunction != null)
                        {
                            try
                            {
                                callFunction.Call(EncounterInfo.encounterGroups[i].charactersInGroup[j].toCharInfo());
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                        break;
                    }
                }
                if (bDone)
                {
                    break;
                }
            }

            if (!ticksEveryTurn)
            {
                bRemove = true;
            }
            else if (timePassed >= timer)
            {
                bRemove = true;
            }
        }
예제 #8
0
            public int Compare(Object x, Object y)
            {
                var res = _callback.Call(x, y);

                return((int)(double)res[0]);
            }
예제 #9
0
 public virtual void Invoke(TArgs args) => BindFunction.Call(args);
예제 #10
0
 public void DiceControl(int Probability, NLua.LuaFunction EndAction)
 {
     DiceControlAction?.Invoke(Probability, delegate { EndAction.Call(); });
 }
예제 #11
0
        public override void AddEventScript(string EventType, NLua.LuaFunction Event)
        {
            EventHandler <MouseEventArgs> E = new EventHandler <MouseEventArgs>(delegate(object s, MouseEventArgs e) { Event.Call(this, e); });

            switch (EventType.ToLower())
            {
            case "click": OnClick += E; break;

            case "right-click": OnRightClick += E; break;

            case "mouse-over": OnMouseOver += E; break;

            case "mouse-out": OnMouseOut += E; break;

            case "leave": OnLeave += E; break;

            case "update": base.AddEventScript("update", Event); break;
            }
        }
예제 #12
0
 public LuaList <T> OrderByDescending(NLua.LuaFunction Function)
 {
     return(new LuaList <T>(Core.OrderByDescending(O =>
                                                   Function.Call(O)[0]).ToList()));
 }
예제 #13
0
 public LuaList <T> Where(NLua.LuaFunction Function)
 {
     return(new LuaList <T>(Core.Where(O =>
                                       (bool)Function.Call(O)[0]).ToList()));
 }
예제 #14
0
 public void SetAction(NLua.LuaFunction Action, object args)
 {
     _Load = delegate() { Action.Call(args); Finish(); };
 }