当前位置: 首页>>代码示例>>C#>>正文


C# fCraft.SchedulerTask类代码示例

本文整理汇总了C#中fCraft.SchedulerTask的典型用法代码示例。如果您正苦于以下问题:C# SchedulerTask类的具体用法?C# SchedulerTask怎么用?C# SchedulerTask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SchedulerTask类属于fCraft命名空间,在下文中一共展示了SchedulerTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Beat

        static void Beat( SchedulerTask scheduledTask ) {
            if( Server.IsShuttingDown ) return;

            if( ConfigKey.HeartbeatEnabled.Enabled() ) {
                SendMinecraftNetBeat();
                if( ConfigKey.IsPublic.Enabled() && ConfigKey.HeartbeatToWoMDirect.Enabled() ) {
                    SendWoMDirectBeat();
                }

            } else {
                // If heartbeats are disabled, the server data is written
                // to a text file instead (heartbeatdata.txt)
                string[] data = new[] {
                    Salt,
                    Server.InternalIP.ToString(),
                    Server.Port.ToStringInvariant(),
                    Server.CountPlayers( false ).ToStringInvariant(),
                    ConfigKey.MaxPlayers.GetString(),
                    ConfigKey.ServerName.GetString(),
                    ConfigKey.IsPublic.GetString(),
                    ConfigKey.WoMDirectDescription.GetString(),
                    ConfigKey.WoMDirectFlags.GetString(),
                    ConfigKey.HeartbeatToWoMDirect.Enabled().ToString()
                };
                const string tempFile = Paths.HeartbeatDataFileName + ".tmp";
                File.WriteAllLines( tempFile, data, Encoding.ASCII );
                Paths.MoveOrReplaceFile( tempFile, Paths.HeartbeatDataFileName );
            }
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:29,代码来源:Heartbeat.cs

示例2: ZombieGame

 public ZombieGame( World world )
 {
     _world = world;
     startTime = DateTime.Now;
     _humanCount = _world.Players.Length;
     _task = new SchedulerTask( Interval, false ).RunForever( TimeSpan.FromSeconds( 1 ) );
     _world.gameMode = GameMode.ZombieSurvival;
     Player.Moved += OnPlayerMoved;
     Player.JoinedWorld += OnChangedWorld;
 }
开发者ID:727021,项目名称:800craft,代码行数:10,代码来源:ZombieGame.cs

示例3: GetInstance

 public static TeamDeathMatch GetInstance(World world)
 {
     if (instance == null)
     {
         TDMworld_ = world;
         instance = new TeamDeathMatch();
         startTime = DateTime.UtcNow;
         task_ = new SchedulerTask(Interval, true).RunForever(TimeSpan.FromSeconds(1));
     }
     return instance;
 }
开发者ID:venofox,项目名称:AtomicCraft,代码行数:11,代码来源:TeamDeathMatch.cs

示例4: Interval

 public void Interval( SchedulerTask task )
 {
     //check to stop Interval
     if ( _world.gameMode != GameMode.ZombieSurvival || _world == null ) {
         _world = null;
         task.Stop();
         return;
     }
     if ( !_started ) {
         if ( startTime != null && ( DateTime.Now - startTime ).TotalMinutes > 1 ) {
             /*if (_world.Players.Length < 3){
                 _world.Players.Message("&WThe game failed to start: 2 or more players need to be in the world");
                 Stop(null);
                 return;
             }*/
             ShufflePlayerPositions();
             _started = true;
             RandomPick();
             lastChecked = DateTime.Now;
             return;
         }
     }
     //calculate humans
     _humanCount = _world.Players.Where( p => p.iName != _zomb ).Count();
     //check if zombies have won already
     if ( _started ) {
         if ( _humanCount == 1 && _world.Players.Count() == 1 ) {
             _world.Players.Message( "&WThe Zombies have failed to infect everyone... &9HUMANS WIN!" );
             Stop( null );
             return;
         }
         if ( _humanCount == 0 ) {
             _world.Players.Message( "&WThe Humans have failed to survive... &9ZOMBIES WIN!" );
             Stop( null );
             return;
         }
     }
     //check if 5mins is up and all zombies have failed
     if ( _started && startTime != null && ( DateTime.Now - startTime ).TotalMinutes > 6 ) {
         _world.Players.Message( "&WThe Zombies have failed to infect everyone... &9HUMANS WIN!" );
         Stop( null );
         return;
     }
     //if no one has won, notify players of their status every 31s
     if ( lastChecked != null && ( DateTime.Now - lastChecked ).TotalSeconds > 30 ) {
         _world.Players.Message( "&WThere are {0} humans", _humanCount.ToString() );
         foreach ( Player p in _world.Players ) {
             if ( p.iName == _zomb ) p.Message( "&8You are " + _zomb );
             else p.Message( "&8You are a Human" );
         }
         lastChecked = DateTime.Now;
     }
 }
开发者ID:727021,项目名称:800craft,代码行数:53,代码来源:ZombieGame.cs

示例5: GetInstance

 public static ZombieGame GetInstance(World world)
 {
     if (instance == null)
     {
         _world = world;
         instance = new ZombieGame();
         startTime = DateTime.Now;
         _humanCount = _world.Players.Length;
         _world.Players.Message(_humanCount.ToString());
         Player.Moved += OnPlayerMoved;
         _task = new SchedulerTask(Interval, true).RunForever(TimeSpan.FromSeconds(1));
         //_world.positions = new Player[_world.Map.Width,
                // _world.Map.Length, _world.Map.Height];
         _world.gameMode = GameMode.ZombieSurvival;
     }
     return instance;
 }
开发者ID:zINaPalm,项目名称:LegendCraftSource,代码行数:17,代码来源:ZombieGame.cs

示例6: UpdateTask

 void UpdateTask( SchedulerTask task ) {
     Map tempMap = Map;
     if( tempMap != null ) {
         tempMap.ProcessUpdates();
     }
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:6,代码来源:World.cs

示例7: FireEvent

 static void FireEvent( EventHandler<SchedulerTaskEventArgs> eventToFire, SchedulerTask task ) {
     var h = eventToFire;
     if( h != null ) h( null, new SchedulerTaskEventArgs( task ) );
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:4,代码来源:Scheduler.cs

示例8: MonitorProcessorUsage

 static void MonitorProcessorUsage( SchedulerTask task ) {
     TimeSpan newCPUTime = Process.GetCurrentProcess().TotalProcessorTime - cpuUsageStartingOffset;
     CPUUsageLastMinute = ( newCPUTime - oldCPUTime ).TotalSeconds /
                          ( Environment.ProcessorCount * DateTime.UtcNow.Subtract( lastMonitorTime ).TotalSeconds );
     lastMonitorTime = DateTime.UtcNow;
     CPUUsageTotal = newCPUTime.TotalSeconds /
                     ( Environment.ProcessorCount * DateTime.UtcNow.Subtract( StartTime ).TotalSeconds );
     oldCPUTime = newCPUTime;
     IsMonitoringCPUUsage = true;
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:10,代码来源:Server.cs

示例9: TimeCheck

        static void TimeCheck(SchedulerTask task)
        {
            foreach (World world in WorldManager.Worlds)
            {
                if (world.RealisticEnv)
                {
                    int sky;
                    int clouds;
                    int fog;
                    DateTime now = DateTime.Now;
                    var SunriseStart = new TimeSpan(6, 30, 0);
                    var SunriseEnd = new TimeSpan(7, 29, 59);
                    var MorningStart = new TimeSpan(7, 30, 0);
                    var MorningEnd = new TimeSpan(11, 59, 59);
                    var NormalStart = new TimeSpan(12, 0, 0);
                    var NormalEnd = new TimeSpan(16, 59, 59);
                    var EveningStart = new TimeSpan(17, 0, 0);
                    var EveningEnd = new TimeSpan(18, 59, 59);
                    var SunsetStart = new TimeSpan(19, 0, 0);
                    var SunsetEnd = new TimeSpan(19, 29, 59);
                    var NightaStart = new TimeSpan(19, 30, 0);
                    var NightaEnd = new TimeSpan(1, 0, 1);
                    var NightbStart = new TimeSpan(1, 0, 2);
                    var NightbEnd = new TimeSpan(6, 29, 59);

                    if (now.TimeOfDay > SunriseStart && now.TimeOfDay < SunriseEnd) //sunrise
                    {
                        sky = ParseHexColor("ffff33");
                        clouds = ParseHexColor("ff0033");
                        fog = ParseHexColor("ff3333");
                        world.SkyColor = sky;
                        world.CloudColor = clouds;
                        world.FogColor = fog;
                        world.EdgeBlock = Block.Water;
                        WorldManager.SaveWorldList();
                        return;
                    }

                    if (now.TimeOfDay > MorningStart && now.TimeOfDay < MorningEnd) //end of sunrise
                    {
                        sky = -1;
                        clouds = ParseHexColor("ff0033");
                        fog = ParseHexColor("fffff0");
                        world.SkyColor = sky;
                        world.CloudColor = clouds;
                        world.FogColor = fog;
                        world.EdgeBlock = Block.Water;
                        WorldManager.SaveWorldList();
                        return;
                    }

                    if (now.TimeOfDay > NormalStart && now.TimeOfDay < NormalEnd)//env normal
                    {
                        sky = -1;
                        clouds = -1;
                        fog = -1;
                        world.SkyColor = sky;
                        world.CloudColor = clouds;
                        world.FogColor = fog;
                        world.EdgeBlock = Block.Water;
                        WorldManager.SaveWorldList();
                        return;
                    }

                    if (now.TimeOfDay > EveningStart && now.TimeOfDay < EveningEnd) //evening
                    {
                        sky = ParseHexColor("99cccc");
                        clouds = -1;
                        fog = ParseHexColor("99ccff");
                        world.SkyColor = sky;
                        world.CloudColor = clouds;
                        world.FogColor = fog;
                        world.EdgeBlock = Block.Water;
                        WorldManager.SaveWorldList();
                        return;
                    }

                    if (now.TimeOfDay > SunsetStart && now.TimeOfDay < SunsetEnd) //sunset
                    {
                        sky = ParseHexColor("9999cc");
                        clouds = ParseHexColor("000033");
                        fog = ParseHexColor("cc9966");
                        world.SkyColor = sky;
                        world.CloudColor = clouds;
                        world.FogColor = fog;
                        world.EdgeBlock = Block.Water;
                        WorldManager.SaveWorldList();
                        return;
                    }

                    if (now.TimeOfDay > NightaStart && now.TimeOfDay < NightaEnd) //end of sunset
                    {
                        sky = ParseHexColor("003366");
                        clouds = ParseHexColor("000033");
                        fog = ParseHexColor("000033");
                        world.SkyColor = sky;
                        world.CloudColor = clouds;
                        world.FogColor = fog;
                        world.EdgeBlock = Block.Black;
                        WorldManager.SaveWorldList();
//.........这里部分代码省略.........
开发者ID:Rhinovex,项目名称:LegendCraft,代码行数:101,代码来源:WorldCommands.cs

示例10: DoGC

        static void DoGC( SchedulerTask task ) {
            if( !gcRequested ) return;
            gcRequested = false;

            Process proc = Process.GetCurrentProcess();
            proc.Refresh();
            long usageBefore = proc.PrivateMemorySize64 / ( 1024 * 1024 );

            GC.Collect( GC.MaxGeneration, GCCollectionMode.Forced );

            proc.Refresh();
            long usageAfter = proc.PrivateMemorySize64 / ( 1024 * 1024 );

            Logger.Log( LogType.Debug,
                        "Server.DoGC: Collected on schedule ({0}->{1} MB).",
                        usageBefore, usageAfter );
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:17,代码来源:Server.cs

示例11: ShowRandomAnnouncement

 // shows announcements
 static void ShowRandomAnnouncement( SchedulerTask task ) {
     if( !File.Exists( Paths.AnnouncementsFileName ) ) return;
     string[] lines = File.ReadAllLines( Paths.AnnouncementsFileName );
     if( lines.Length == 0 ) return;
     string line = lines[new Random().Next( 0, lines.Length )].Trim();
     if( line.Length == 0 ) return;
     foreach( Player player in Players.Where( player => player.World != null ) ) {
         string announcementLine = Chat.ReplaceTextKeywords( player, line );
         announcementLine = Chat.ReplaceEmoteKeywords( announcementLine );
         announcementLine = Chat.ReplaceUnicodeWithEmotes( announcementLine );
         player.Message( "&R" + announcementLine );
     }
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:14,代码来源:Server.cs

示例12: ChatTimer

 ChatTimer( TimeSpan duration, [CanBeNull] string message, [NotNull] string startedBy )
 {
     if( startedBy == null ) throw new ArgumentNullException( "startedBy" );
     StartedBy = startedBy;
     Message = message;
     StartTime = DateTime.UtcNow;
     EndTime = StartTime.Add( duration );
     Duration = duration;
     int oneSecondRepeats = (int)duration.TotalSeconds + 1;
     if( duration > Hour ) {
         announceIntervalIndex = AnnounceIntervals.Length - 1;
         lastHourAnnounced = (int)duration.TotalHours;
     } else {
         for( int i = 0; i < AnnounceIntervals.Length; i++ ) {
             if( duration <= AnnounceIntervals[i] ) {
                 announceIntervalIndex = i - 1;
                 break;
             }
         }
     }
     task = Scheduler.NewTask( TimerCallback, this );
     Id = Interlocked.Increment( ref timerCounter );
     AddTimerToList( this );
     IsRunning = true;
     task.RunRepeating( TimeSpan.Zero,
                        TimeSpan.FromSeconds( 1 ),
                        oneSecondRepeats );
 }
开发者ID:Blingpancakeman,项目名称:800craft,代码行数:28,代码来源:ChatTimer.cs

示例13: ExplodingBug

 public ExplodingBug( Player p )
 {
     player = p;
     world = player.World;
     guild = GuildManager.PlayersGuild( player.Info );
     end = player.Position.ToBlockCoords();
     block = new Vector3I( end.X, end.Y, end.Z - 1 );
     Started = true;
     task = Scheduler.NewBackgroundTask( t => StartAI() ).RunForever( TimeSpan.FromMilliseconds( 230 ) );
     endTask = Scheduler.NewTask( t => Stop() ).RunOnce( TimeSpan.FromSeconds( 25 ) );
     player.PublicAuxStateObjects.Add( "bug", this );
 }
开发者ID:Jonty800,项目名称:Guilds,代码行数:12,代码来源:ExplodingBug.cs

示例14: StartPerk

 public void StartPerk()
 {
     if ( !Started ) {
         Started = true;
         if ( TimesToRepeat == -1 ) {
             task = Scheduler.NewTask( t => PerformAction() ).RunOnce( TimeSpan.FromMilliseconds( Delay ) );
         } else if ( TimesToRepeat == 0 ) {
             task = Scheduler.NewTask( t => PerformAction() ).RunForever( TimeSpan.FromMilliseconds( Delay ) );
         } else {
             task = Scheduler.NewTask( t => PerformAction() ).RunRepeating( TimeSpan.FromMilliseconds( Delay ), TimeSpan.FromMilliseconds( Delay ), TimesToRepeat );
         }
     }
 }
开发者ID:Jonty800,项目名称:Guilds,代码行数:13,代码来源:Perk.cs

示例15: Start

        /// <summary>
        /// Starts the game
        /// </summary>
        /// <param name="player">Player starting the game</param>
        public void Start( Player player )
        {
            if ( instance != null ) {
                player.Message( "Cannot start GuildGame: A game is already in progress" );
                return;
            }
            task = Scheduler.NewTask( t => Stop( Player.Console ) ).RunOnce( TimeSpan.FromMinutes( 5 ) );

            foreach ( Player p in Server.Players ) {
                if ( GuildManager.PlayersGuild( p.Info ) != null ) {
                    //they can play the game, so add them
                    p.PublicAuxStateObjects.Add( "GameEnabled", true );
                }
            }
        }
开发者ID:Jonty800,项目名称:Guilds,代码行数:19,代码来源:GuildGame.cs


注:本文中的fCraft.SchedulerTask类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。