示例#1
0
        static void TickPlayer(Player p)
        {
            if (p.following.Length > 0)
            {
                Player who = PlayerInfo.FindExact(p.following);
                if (who == null || who.level != p.level)
                {
                    p.following = "";
                    if (!p.canBuild)
                    {
                        p.canBuild = true;
                    }
                    if (who != null && who.possess == p.name)
                    {
                        who.possess = "";
                    }
                    return;
                }

                p.SendPos(Entities.SelfID, who.Pos, who.Rot);
            }
            else if (p.possess.Length > 0)
            {
                Player who = PlayerInfo.FindExact(p.possess);
                if (who == null || who.level != p.level)
                {
                    p.possess = "";
                }
            }

            SchedulerTask[] tasks = p.CriticalTasks.Items;
            DateTime        now   = DateTime.UtcNow;

            for (int i = 0; i < tasks.Length; i++)
            {
                SchedulerTask task = tasks[i];
                if (now < task.NextRun)
                {
                    continue;
                }

                task.Callback(task);
                task.NextRun = now.Add(task.Delay);

                if (task.Repeating)
                {
                    continue;
                }
                p.CriticalTasks.Remove(task);
            }
        }
示例#2
0
        void DoTask(SchedulerTask task)
        {
            try {
                task.Callback(task);
            } catch (Exception ex) {
                Logger.LogError(ex);
            }

            if (task.Repeating)
            {
                task.NextRun = DateTime.UtcNow.Add(task.Delay);
            }
            else
            {
                lock (taskLock)
                    tasks.Remove(task);
            }
        }