/// <summary>
 /// Updates the current time on all processors.
 /// </summary>
 /// <param name="currentTime">The current time.</param>
 internal void UpdateCurrentTime(TickCount currentTime)
 {
     foreach (var modifier in this)
     {
         modifier.UpdateCurrentTime(currentTime);
     }
 }
Example #2
0
        /// <summary>
        /// Updates the <see cref="IRefractionEffect"/>.
        /// </summary>
        /// <param name="currentTime">The current game time in milliseconds.</param>
        public virtual void Update(TickCount currentTime)
        {
            if (IsExpired)
            {
                return;
            }

            _lastUpdateTime = currentTime;

            // Get the life of the effect
            var totalElapsedTime = (int)currentTime - _startTime;

            if (totalElapsedTime < 0)
            {
                totalElapsedTime = 0;
            }

            // Check if expired
            if (totalElapsedTime >= _lifeSpan)
            {
                Dispose();
                return;
            }

            // Update the size
            _size = ExpansionRate * totalElapsedTime;

            // Update the sprite
            ExplosionNoise.Update(currentTime);
        }
Example #3
0
        /// <summary>
        /// Updates the World.
        /// </summary>
        public virtual void Update()
        {
            // Get the current time
            var currentTime = GetTime();

            // Check if this is the very first update - if so, bring the timer up to date
            if (_isFirstUpdate)
            {
                _lastUpdateTime = currentTime;
                _isFirstUpdate  = false;
            }

            // Grab the update rate
            var updateRate = GameData.WorldPhysicsUpdateRate;

            // Check if we fell too far behind
            if (currentTime - _lastUpdateTime > _maxUpdateDeltaTime)
            {
                const string errmsg = "Fell too far behind in updates to catch up. Jumping ahead to current time.";
                if (log.IsWarnEnabled)
                {
                    log.Warn(errmsg);
                }

                // Push the time ahead to a bit before the current time
                _lastUpdateTime = (TickCount)(currentTime - updateRate - 1);
            }

            // Keep updating until there is not enough delta time to fit into the updateRate
            while (currentTime > _lastUpdateTime + updateRate)
            {
                UpdateMaps(updateRate);
                _lastUpdateTime += (uint)updateRate;
            }
        }
Example #4
0
        /// <summary>
        /// Handles drawing of the screen. The ScreenManager already provides a GraphicsDevice.Clear() so
        /// there is often no need to clear the screen. This will only be called while the screen is the
        /// active screen.
        /// </summary>
        /// <param name="gameTime">The current game time.</param>
        public override void Draw(TickCount gameTime)
        {
            var spriteBatch = DrawingManager.BeginDrawGUI(false);

            if (spriteBatch == null)
            {
                return;
            }

            // Draw an overlay on top of the old screen
            RenderRectangle.Draw(spriteBatch, _cScreen.GetScreenArea(), _overlayColor);

            // Draw the GUI
            GUIManager.Draw(spriteBatch);

            // Draw some extras
            const int yOff = 150;

            spriteBatch.DrawStringShaded(_txtOutput.Font, "FPS: " + ScreenManager.FPS,
                                         new Vector2(_cScreen.ClientSize.X - 100, yOff), Color.White, Color.Black);
            spriteBatch.DrawStringShaded(_txtOutput.Font,
                                         string.Format("Game Time: {0}:{1:00}", GameDateTime.Now.Hour, GameDateTime.Now.Minute),
                                         new Vector2(_cScreen.ClientSize.X - 150, _txtOutput.Font.GetLineSpacing() + yOff), Color.White, Color.Black);

            DrawingManager.EndDrawGUI();
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InfoBoxItem"/> struct.
 /// </summary>
 /// <param name="time">Current time.</param>
 /// <param name="msg">Message to display.</param>
 /// <param name="color">Color of the text.</param>
 /// <param name="font"><see cref="Font"/> that will be used to calculate the Width.</param>
 public InfoBoxItem(TickCount time, string msg, Color color, Font font)
 {
     CreatedTime = time;
     Message     = msg;
     Color       = color;
     Width       = font.MeasureString(msg).X;
 }
Example #6
0
        /// <summary>
        /// Accepts the invite to a <see cref="IGuild"/>. This method will also make sure that this member
        /// has an outstanding invite to the guild.
        /// </summary>
        /// <param name="guild">The guild to join.</param>
        /// <param name="currentTime">The current time.</param>
        /// <returns>
        /// True if this member successfully joined the <paramref name="guild"/>; otherwise false.
        /// </returns>
        public bool AcceptInvite(IGuild guild, TickCount currentTime)
        {
            if (Owner.Guild != null)
            {
                return(false);
            }

            if (guild == null)
            {
                return(false);
            }

            // Update the invites
            UpdateInvites(currentTime);

            // Make sure there is an invite to this guild
            if (!_invites.Any(x => x.Guild == guild))
            {
                return(false);
            }

            // Join the guild
            Owner.Guild = guild;

            // Remove all outstanding invites
            foreach (var current in _invites)
            {
                _guildInvitePool.Free(current);
            }

            _invites.Clear();

            return(true);
        }
        /// <summary>
        /// Removes the expired map items.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        /// <returns>The number of items that were removed. Will be zero if not enough time has elapsed since the last
        /// call to update, or if just no items were removed.</returns>
        public int Update(TickCount currentTime)
        {
            // Check if enough time has elapsed to update
            if (_lastUpdateTime + UpdateRate > currentTime)
            {
                return(0);
            }

            _lastUpdateTime = currentTime;

            // Get the items to remove
            var toRemove = _items.Where(x => x.Value <= currentTime).Select(x => x.Key).ToArray();

            if (toRemove == null || toRemove.Length == 0)
            {
                return(0);
            }

            // Start removing the items
            foreach (var item in toRemove)
            {
                // Remove from the collection
                _items.Remove(item);

                // Perform the expiration of the item
                ExpireItem(item);
            }

            return(toRemove.Length);
        }
Example #8
0
 /// <summary>
 /// Updates all of the <see cref="GameControl"/>s in this <see cref="GameControlCollection"/>.
 /// </summary>
 /// <param name="guiManager">The <see cref="IGUIManager"/> used to update the <see cref="GameControl"/>s.</param>
 /// <param name="currentTime">The current time in milliseconds.</param>
 public void Update(IGUIManager guiManager, TickCount currentTime)
 {
     foreach (var gc in this)
     {
         gc.Update(guiManager, currentTime);
     }
 }
Example #9
0
        /// <summary>
        /// Updates the <see cref="IParticleEffect"/> and all <see cref="IParticleEmitter"/>s inside it.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        public void Update(TickCount currentTime)
        {
            if (IsDisposed)
            {
                return;
            }

            // Check if we have expired due to the elapsed time
            if (RemainingLife == 0)
            {
                // Kill all the emitters
                foreach (var e in _emitters)
                {
                    e.Kill();
                }
            }

            // Update the emitters
            var emittersHaveExpired = true;

            foreach (var e in _emitters)
            {
                e.Update(currentTime);
                if (!e.IsExpired)
                {
                    emittersHaveExpired = false;
                }
            }

            // Check if we have expired because all the children have expired
            if (emittersHaveExpired)
            {
                _isExpired = true;
            }
        }
Example #10
0
        /// <summary>
        /// When overridden in the derived class, updates the AI. This is called at most once per frame, and only
        /// called whe the <see cref="Actor"/> is alive and active.
        /// </summary>
        public void Update()
        {
            // Ensure a valid actor
            if (!Actor.IsAlive || Actor.Map == null)
            {
                return;
            }

            // Check if AI is enabled
            if (AISettings.AIDisabled)
            {
                if (Actor.IsMoving)
                {
                    Actor.StopMoving();
                }
                _explicitHostiles.Clear();
                return;
            }

            // Check to update the explicit hostiles
            if (_explicitHostiles.Count > 0)
            {
                var time = GetTime();
                if (_expireExplicitHostilesTime < time)
                {
                    _expireExplicitHostilesTime = time + _expireExplicitHostilesRate;
                    _explicitHostiles.RemoveMany(x => x.Value < time || x.Key.IsDisposed);
                }
            }

            // Custom update
            DoUpdate();
        }
Example #11
0
        /// <summary>
        /// Updates the status.
        /// </summary>
        /// <param name="current">The current item count.</param>
        public void UpdateStatus(int current)
        {
            var currTime = TickCount.Now;
            var elapsed  = currTime - _lastUpdateTime;

            if (elapsed < _minSuggestUpdateRate)
            {
                return;
            }

            _lastUpdateTime = currTime;

            if (current > _total)
            {
                current = _total;
            }

            _current       = current;
            progBar.Value  = _current;
            lblStatus.Text = string.Format("{0} of {1} ({2}%)", _current, _total, Math.Round(((float)_current / _total) * 100f));
            UpdateTimeRemaining();

            Application.DoEvents();
            Update();
        }
Example #12
0
            /// <summary>
            /// Updates the <see cref="Control"/>. This is called for every <see cref="Control"/>, even if it is disabled or
            /// not visible.
            /// </summary>
            /// <param name="currentTime">The current time in milliseconds.</param>
            protected override void UpdateControl(TickCount currentTime)
            {
                base.UpdateControl(currentTime);

                // Check that enough time has elapsed since the last update
                if (_lastUpdateTextTime + _textUpdateRate > currentTime)
                {
                    return;
                }

                _lastUpdateTextTime = currentTime;

                // Get the stat values
                int baseValue = _statsForm.UserInfo.BaseStats[_statType];
                int modValue  = _statsForm.UserInfo.ModStats[_statType];

                // Check that they have changed before creating the new text
                if (_lastBaseValue == baseValue && _lastModValue == modValue)
                {
                    return;
                }

                _lastBaseValue = baseValue;
                _lastModValue  = modValue;

                Text = _statType + ": " + baseValue + " (" + modValue + ")";
            }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhEffectSeekPosition"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="target">The destination position.</param>
        /// <param name="speed">How fast this object moves towards the target in pixels per second.</param>
        public MapGrhEffectSeekPosition(Grh grh, Vector2 position, Vector2 target, float speed)
            : base(grh, position)
        {
            speed = speed / 1000f;

            _startTime      = TickCount.Now;
            _startPosition  = position;
            _targetPosition = target;

            // Calculate the angle between the position and target
            var diff  = position - target;
            var angle = Math.Atan2(diff.Y, diff.X);

            var cos = Math.Cos(angle);
            var sin = Math.Sin(angle);

            // Multiply the normalized direction vector (the cos and sine values) by the speed to get the velocity
            // to use for each elapsed millisecond
            _velocity = -new Vector2((float)(cos * speed), (float)(sin * speed));

            // Precalculate the amount of time it will take to hit the target. This way, we can check if we have reached
            // the destination simply by checking the current time.
            var dist    = Vector2.Distance(position, target);
            var reqTime = (int)Math.Ceiling(dist / speed);

            _endTime = (TickCount)(_startTime + reqTime);
        }
Example #14
0
        /// <summary>
        /// Updates the current frame.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        void UpdateFrameIndex(TickCount currentTime)
        {
            var elapsedTime = currentTime - _lastUpdated;

            Debug.Assert(elapsedTime >= 0, "How is the elapsed time negative? Did the computer fall into a wormhole?");
            if (elapsedTime <= 0)
            {
                return;
            }

            // Store the temporary new frame
            var tmpFrame = _frame + (elapsedTime * GrhData.Speed);

            // Check if the frame limit has been exceeded
            if (tmpFrame >= GrhData.FramesCount)
            {
                if (_anim == AnimType.LoopOnce)
                {
                    // The animation was only looping once, so end it and set at the first frame
                    _anim  = AnimType.None;
                    _frame = 0;
                    return;
                }
                else
                {
                    // Animation is looping so get the frame back into range
                    tmpFrame = tmpFrame % GrhData.FramesCount;
                }
            }

            // Set the new frame
            _frame = tmpFrame;
        }
Example #15
0
 /// <summary>
 /// Sets the Grh to a new index.
 /// </summary>
 /// <param name="grhData">New GrhData to use for the Grh.</param>
 /// <param name="anim">Type of animation.</param>
 /// <param name="currentTime">Current time.</param>
 public void SetGrh(GrhData grhData, AnimType anim, TickCount currentTime)
 {
     _grhData     = grhData;
     _frame       = 0;
     _anim        = anim;
     _lastUpdated = currentTime;
 }
Example #16
0
        /// <summary>
        /// Updates the World.
        /// </summary>
        public virtual void Update()
        {
            // Get the current time
            var currentTime = GetTime();

            // Check if this is the very first update - if so, bring the timer up to date
            if (_isFirstUpdate)
            {
                _lastUpdateTime = currentTime;
                _isFirstUpdate = false;
            }

            // Grab the update rate
            var updateRate = GameData.WorldPhysicsUpdateRate;

            // Check if we fell too far behind
            if (currentTime - _lastUpdateTime > _maxUpdateDeltaTime)
            {
                const string errmsg = "Fell too far behind in updates to catch up. Jumping ahead to current time.";
                if (log.IsWarnEnabled)
                    log.Warn(errmsg);

                // Push the time ahead to a bit before the current time
                _lastUpdateTime = (TickCount)(currentTime - updateRate - 1);
            }

            // Keep updating until there is not enough delta time to fit into the updateRate
            while (currentTime > _lastUpdateTime + updateRate)
            {
                UpdateMaps(updateRate);
                _lastUpdateTime += (uint)updateRate;
            }
        }
Example #17
0
                /// <summary>
                /// Updates the <see cref="Control"/>. This is called for every <see cref="Control"/>, even if it is disabled or
                /// not visible.
                /// </summary>
                /// <param name="currentTime">The current time in milliseconds.</param>
                protected override void UpdateControl(TickCount currentTime)
                {
                    base.UpdateControl(currentTime);

                    if (!IsVisible)
                    {
                        return;
                    }

                    // Get the current item info
                    var currItemInfo = ItemsCollection.GetItemInfo(Slot);

                    // Check if the item info has changed and, if so, re-initialize the sprite
                    if (currItemInfo != _lastItemInfo)
                    {
                        ItemsCollection.PeerTradeForm.InitializeItemInfoSprite(_sprite, currItemInfo);
                        _lastItemInfo = currItemInfo;
                    }

                    // Update the sprite
                    if (_sprite.GrhData != null)
                    {
                        _sprite.Update(currentTime);
                    }
                }
Example #18
0
        /// <summary>
        /// Updates the <see cref="MapGrh"/>.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        public override void Update(TickCount currentTime)
        {
            base.Update(currentTime);

            if (IsAlive)
                UpdateEffect(currentTime);
        }
Example #19
0
 /// <summary>
 /// Updates the <see cref="IDrawingManager"/> and all components inside of it.
 /// </summary>
 /// <param name="currentTime">The current game time in milliseconds.</param>
 public virtual void Update(TickCount currentTime)
 {
     foreach (var fx in this)
     {
         fx.Update(currentTime);
     }
 }
Example #20
0
        /// <summary>
        /// Updates the World.
        /// </summary>
        public override void Update()
        {
            ThreadAsserts.IsMainThread();

            // Process all of the stuff queued to be disposed
            ProcessDisposeStack();

            var currentTime = GetTime();

            // If enough time has elapsed, update stuff to be respawned
            if (_updateRespawnablesTime < currentTime)
            {
                _updateRespawnablesTime = currentTime + ServerSettings.Default.RespawnablesUpdateRate;
                _respawnTaskList.Process();
            }

            // If enough time has elapsed, update the extra user information
            if (_syncExtraUserInfoTime < currentTime)
            {
                _syncExtraUserInfoTime = currentTime + ServerSettings.Default.SyncExtraUserInformationRate;
                SyncExtraUserInformation();
            }

            base.Update();
        }
Example #21
0
 /// <summary>
 /// Updates the <see cref="SkeletonBody"/>.
 /// </summary>
 /// <param name="currentTime">The current time.</param>
 public void Update(TickCount currentTime)
 {
     foreach (var bodyItem in BodyItems)
     {
         bodyItem.Update(currentTime);
     }
 }
        /// <summary>
        /// When overridden in the derived class, draws the graphics to the control.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleDraw(TickCount currentTime)
        {
            base.HandleDraw(currentTime);

            if (DesignMode)
                return;

            if (_drawingManager.RenderWindow == null)
                return;

            if (Grh == null)
                return;

            Grh.Update(currentTime);

            m.Update(currentTime);

            _drawingManager.Update(currentTime);

            var sb = _drawingManager.BeginDrawWorld(_camera);
            if (sb == null)
                return;

            // Change the view
            var oldView = RenderWindow.GetView();
            _drawView.Reset(new FloatRect(Camera.Min.X, Camera.Min.Y, Camera.Size.X, Camera.Size.Y));
            RenderWindow.SetView(_drawView);

            try
            {
                try
                {
                    Grh.Draw(sb, Vector2.Zero, Color.White);
                }
                catch (LoadingFailedException)
                {
                    // A LoadingFailedException is generally fine here since it probably means the graphic file was invalid
                    // or does not exist
                }

                // Draw the walls
                if (Walls != null)
                {
                    foreach (var wall in Walls)
                    {
                        var rect = wall.ToRectangle();
                        RenderRectangle.Draw(sb, rect, _autoWallColor);
                    }
                }

                m.Draw(sb, Camera);
            }
            finally
            {
                _drawingManager.EndDrawWorld();

                // Restore the view
                RenderWindow.SetView(oldView);
            }
        }
Example #23
0
 /// <summary>
 /// Updates the map.
 /// </summary>
 /// <param name="currentTime">The current time.</param>
 /// <param name="deltaTime">The amount of time that has elapsed since the last update.</param>
 protected virtual void UpdateMap(TickCount currentTime, int deltaTime)
 {
     if (Map != null)
     {
         Map.Update(deltaTime);
     }
 }
 /// <summary>
 /// Gets the time stamp.
 /// </summary>
 /// <param name="currentTime">The time to get the time stamp for.</param>
 /// <returns>The time stamp for the given time.</returns>
 public static ushort GetTimeStamp(TickCount currentTime)
 {
     unchecked
     {
         return (ushort)((currentTime >> 3) % (MaxTimeStampSize + 1));
     }
 }
Example #25
0
 /// <summary>
 /// Updates the <see cref="TransBoxManager"/>.
 /// </summary>
 /// <param name="currentTime">The current time.</param>
 public void Update(TickCount currentTime)
 {
     foreach (var tb in _transBoxes)
     {
         tb.Update(currentTime);
     }
 }
 public void OnTimeElapsed(TickCount currentTick)
 {
     if (Server.Globals.ServerTime == Enums.Time.Day)
     {
         Server.Globals.ServerTime = Enums.Time.Dusk;
         SetInterval(currentTick, (int)new TimeSpan(2, 0, 0).TotalMilliseconds);
     }
     else if (Server.Globals.ServerTime == Enums.Time.Dusk)
     {
         Server.Globals.ServerTime = Enums.Time.Night;
         SetInterval(currentTick, (int)new TimeSpan(4, 0, 0).TotalMilliseconds);
     }
     else if (Server.Globals.ServerTime == Enums.Time.Night)
     {
         Server.Globals.ServerTime = Enums.Time.Dawn;
         SetInterval(currentTick, (int)new TimeSpan(2, 0, 0).TotalMilliseconds);
     }
     else if (Server.Globals.ServerTime == Enums.Time.Dawn)
     {
         Server.Globals.ServerTime = Enums.Time.Day;
         SetInterval(currentTick, (int)new TimeSpan(4, 0, 0).TotalMilliseconds);
     }
     storedTime = currentTick;
     Network.Messenger.SendGameTimeToAll();
     foreach (Network.Client client in Network.ClientManager.GetClients())
     {
         client.Player.MissionBoard.GenerateMission();
     }
 }
Example #27
0
            public int GetSecsLeft(TickCount currentTime)
            {
                var msRemaining   = _disableTime - currentTime;
                var secsRemaining = (int)Math.Round(msRemaining / 1000f);

                return(Math.Max(secsRemaining, 0));
            }
Example #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhEffectSeekPosition"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="target">The destination position.</param>
        /// <param name="speed">How fast this object moves towards the target in pixels per second.</param>
        public MapGrhEffectSeekPosition(Grh grh, Vector2 position, Vector2 target, float speed)
            : base(grh, position)
        {
            speed = speed / 1000f;

            _startTime = TickCount.Now;
            _startPosition = position;
            _targetPosition = target;

            // Calculate the angle between the position and target
            var diff = position - target;
            var angle = Math.Atan2(diff.Y, diff.X);

            var cos = Math.Cos(angle);
            var sin = Math.Sin(angle);

            // Multiply the normalized direction vector (the cos and sine values) by the speed to get the velocity
            // to use for each elapsed millisecond
            _velocity = -new Vector2((float)(cos * speed), (float)(sin * speed));

            // Precalculate the amount of time it will take to hit the target. This way, we can check if we have reached
            // the destination simply by checking the current time.
            var dist = Vector2.Distance(position, target);
            var reqTime = (int)Math.Ceiling(dist / speed);

            _endTime = (TickCount)(_startTime + reqTime);
        }
Example #29
0
        /// <summary>
        /// Updates the server time.
        /// </summary>
        /// <param name="currentTime">The current game time. Used to determine if enough time has elapsed since
        /// the last update.</param>
        public void Update(TickCount currentTime)
        {
            if (currentTime - _lastUpdateTime < UpdateRate)
                return;

            _lastUpdateTime = currentTime;
            _updateQuery.Execute();
        }
Example #30
0
 public bool TimeElapsed(TickCount currentTick)
 {
     if (currentTick.Elapsed(storedTime, this.interval)) {
         return true;
     } else {
         return false;
     }
 }
Example #31
0
        public ItemEntity(MapEntityIndex mapEntityIndex, Vector2 pos, Vector2 size, GrhIndex graphicIndex, TickCount currentTime)
            : base(pos, size)
        {
            Amount = 0;

            ((IDynamicEntitySetMapEntityIndex)this).SetMapEntityIndex(mapEntityIndex);
            _grh = new Grh(GrhInfo.GetData(graphicIndex), AnimType.Loop, currentTime);
        }
Example #32
0
        /// <summary>
        /// Updates the GUISettings.
        /// </summary>
        /// <param name="currentTime">Current time.</param>
        public void Update(TickCount currentTime)
        {
            if (_lastSaveTime + _saveFrequency > currentTime)
                return;

            _lastSaveTime = currentTime;
            AsyncSave();
        }
Example #33
0
            /// <summary>
            /// Updates the <see cref="Control"/>. This is called for every <see cref="Control"/>, even if it is disabled or
            /// not visible.
            /// </summary>
            /// <param name="currentTime">The current time in milliseconds.</param>
            protected override void UpdateControl(TickCount currentTime)
            {
                _isCoolingDown = _cooldownManager.IsCoolingDown(SkillInfo.CooldownGroup, currentTime);

                IsEnabled = _knownSkills.Knows(SkillInfo.Value);

                base.UpdateControl(currentTime);
            }
        /// <summary>
        /// Updates the <see cref="Control"/>. This is called for every <see cref="Control"/>, even if it is disabled or
        /// not visible.
        /// </summary>
        /// <param name="currentTime">The current time in milliseconds.</param>
        protected override void UpdateControl(TickCount currentTime)
        {
            base.UpdateControl(currentTime);

            // If there are no quests listed, close the form
            if (AvailableQuests.IsEmpty())
                IsVisible = false;
        }
Example #35
0
        /// <summary>
        /// When overridden in the derived class, handles updating the game.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleUpdate(TickCount currentTime)
        {
            // Update the sockets
            _sockets.Heartbeat();

            // Update everything else
            _screenManager.Update(TickCount.Now);
        }
Example #36
0
        /// <summary>
        /// Updates the <see cref="MapGrh"/>.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        public virtual void Update(TickCount currentTime)
        {
            _grh.Update(currentTime);

            var grhSize = Grh.Size;

            Vector2.Multiply(ref _scale, ref grhSize, out _scaledGrhSizeCache);
        }
Example #37
0
        /// <summary>
        /// Releases one or more particles.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        /// <param name="amount">The number of particles to release.</param>
        void ReleaseParticles(TickCount currentTime, int amount)
        {
            // Find how many we can actually release
            var lastIndex = Math.Min(Budget - 1, _lastAliveIndex + amount);

            // Ensure our particles array is large enough to fit the new particles.
            // When we resize the array, we use the "next power of two" sizing concept to reduce the
            // memory fragmentation (.NET internally does the same with most collections). To speed things up,
            // we just find the next power of two instead of looping until we have a large enough value.
            if (_particles.Length - 1 < lastIndex)
            {
                var newSize = BitOps.NextPowerOf2(lastIndex + 1);
                Debug.Assert(BitOps.IsPowerOf2(newSize),
                             "If this assert fails, something is probably wrong with BitOps.NextPowerOf2() or BitOps.IsPowerOf2().");
                Debug.Assert(newSize >= lastIndex + 1);
                Array.Resize(ref _particles, newSize);
            }

            // Start releasing the particles
            var hasReleaseModifiers = ParticleModifiers.HasReleaseModifiers;

            for (var i = _lastAliveIndex + 1; i <= lastIndex; i++)
            {
                var particle = _particles[i];
                if (particle == null)
                {
                    particle      = Particle.Create();
                    _particles[i] = particle;
                }

                // Set up the particle
                particle.Momentum  = Vector2.Zero;
                particle.LifeStart = currentTime;
                particle.LifeEnd   = (TickCount)(currentTime + ParticleLife.GetNext());
                particle.Rotation  = ReleaseRotation.GetNext();
                particle.Scale     = ReleaseScale.GetNext();
                ReleaseColor.GetNext(ref particle.Color);

                // Get the offset and force
                Vector2 offset;
                Vector2 force;
                GenerateParticleOffsetAndForce(particle, out offset, out force);

                // Set the position
                Vector2.Add(ref _origin, ref offset, out particle.Position);

                // Set the velocity
                Vector2.Multiply(ref force, ReleaseSpeed.GetNext(), out particle.Velocity);

                if (hasReleaseModifiers)
                {
                    ParticleModifiers.ProcessReleasedParticle(this, particle);
                }
            }

            // Increase the index of the last active particle
            _lastAliveIndex = lastIndex;
        }
Example #38
0
 public MapNpcBase(DataManager.Maps.MapNpc rawNpc)
 {
     this.rawNpc = rawNpc;
     Darkness = -2;
     Mobility = new bool[16];
     TimeMultiplier = 1000;
     AttackTimer = new TickCount(Core.GetTickCount().Tick);
     PauseTimer = new TickCount(Core.GetTickCount().Tick);
 }
 public void OnTimeElapsed(TickCount currentTick)
 {
     storedTime = currentTick;
     return;
     PMU.Sockets.IPacket packet = PMU.Sockets.TcpPacket.CreatePacket("keepalive");
     foreach (Network.Client client in Network.ClientManager.GetAllClients()) {
         Network.Messenger.SendDataTo(client, packet);
     }
 }
Example #40
0
        /// <summary>
        /// Updates the <see cref="MapGrh"/>.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        public override void Update(TickCount currentTime)
        {
            base.Update(currentTime);

            if (IsAlive)
            {
                UpdateEffect(currentTime);
            }
        }
Example #41
0
        /// <summary>
        /// Updates the <see cref="BackgroundImage"/>.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        public virtual void Update(TickCount currentTime)
        {
            if (!IsSpriteSet())
            {
                return;
            }

            Sprite.Update(currentTime);
        }
Example #42
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="reader">The reader to read the values from.</param>
        /// <param name="currentTime">The current time.</param>
        /// <exception cref="ArgumentNullException"><paramref name="reader" /> is <c>null</c>.</exception>
        public MapGrh(IValueReader reader, TickCount currentTime)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            _grh = new Grh(null, AnimType.Loop, currentTime);

            ReadState(reader);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GrhDataUpdaterProgressForm"/> class.
        /// </summary>
        /// <param name="total">The total number of items.</param>
        public GrhDataUpdaterProgressForm(int total)
        {
            InitializeComponent();

            _total = total;
            _startTime = TickCount.Now;

            progBar.Minimum = 0;
            progBar.Maximum = total;
            progBar.Value = 0;
        }
Example #44
0
        /// <summary>
        /// When overridden in the derived class, performs the additional updating that this <see cref="MapGrhEffect"/>
        /// needs to do such as checking if it is time to kill the effect. This method should be overridden instead of
        /// <see cref="MapGrh.Update"/>. This method will not be called after the effect has been killed.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        protected override void UpdateEffect(TickCount currentTime)
        {
            if (_terminateWhenDoneLooping && Grh.AnimType == AnimType.None)
            {
                Kill(true);
                return;
            }

            if (TickCount.Now >= _expireTime)
                Kill(true);
        }
Example #45
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IPSocket"/> class.
        /// </summary>
        /// <param name="conn">The <see cref="NetConnection"/> that this <see cref="IPSocket"/> is for.</param>
        IPSocket(NetConnection conn)
        {
            _timeCreated = TickCount.Now;

            _conn = conn;

            var addressBytes = _conn.RemoteEndPoint.Address.GetAddressBytes();
            _address = IPAddressHelper.IPv4AddressToUInt(addressBytes, 0);

            _addressStr = IPAddressHelper.ToIPv4Address(_address) + ":" + _conn.RemoteEndPoint.Port;
        }
Example #46
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhEffectLoopOnce"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="target">The <see cref="ISpatial"/> to seek out.</param>
        /// <param name="speed">How fast this object moves towards the target in pixels per second.</param>
        /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
        public MapGrhEffectSeekSpatial(Grh grh, Vector2 position, ISpatial target, float speed)
            : base(grh, position)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            _lastUpdate = TickCount.Now;

            _target = target;
            _speed = speed / 1000f;
        }
Example #47
0
        /// <summary>
        /// Starts the display of a skill being casted.
        /// </summary>
        /// <param name="skillType">Type of the skill.</param>
        /// <param name="castTime">The time it will take for the skill to be casted.</param>
        public void StartCasting(SkillType skillType, TickCount castTime)
        {
            _currentCastTime = castTime;
            _castStartTime = TickCount.Now;
            _skillType = skillType;

            Text = "Casting " + skillType;

            var textSize = Font.MeasureString(Text);
            _textOffset = (Size / 2f) - (textSize / 2f);

            IsVisible = true;
        }
Example #48
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonAnimation"/> class.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        /// <param name="skeletonSet"><see cref="SkeletonSet"/> to use for the keyframes.</param>
        /// <exception cref="ArgumentNullException"><paramref name="skeletonSet" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">skeletonSet contains no KeyFrames.</exception>
        public SkeletonAnimation(TickCount currentTime, SkeletonSet skeletonSet)
        {
            if (skeletonSet == null)
                throw new ArgumentNullException("skeletonSet");
            if (skeletonSet.KeyFrames.Length == 0)
                throw new ArgumentException("skeletonSet contains no KeyFrames.", "skeletonSet");

            _lastTime = currentTime;
            _skelSet = skeletonSet;
            _currFrame = _skelSet.KeyFrames[0];
            _nextFrame = _skelSet.KeyFrames.Length > 1 ? _skelSet.KeyFrames[1] : _skelSet.KeyFrames[0];
            _skel = CurrentFrame.Skeleton.DeepCopy();
        }
        /// <summary>
        /// Starts the display of a skill being casted.
        /// </summary>
        /// <param name="skillType">Type of the skill.</param>
        /// <param name="castTime">The time it will take for the skill to be casted.</param>
        public void StartCasting(SkillType skillType, TickCount castTime)
        {
            _currentCastTime = castTime;
            _castStartTime = TickCount.Now;
            _skillType = skillType;

            Text = GameMessageCollection.CurrentLanguage.GetMessage(GameMessage.CombatCastingBegin, skillType.ToString());

            var textSize = Font.MeasureString(Text);
            _textOffset = (Size / 2f) - (textSize / 2f);

            IsVisible = true;
        }
Example #50
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatBubble"/> class.
        /// </summary>
        /// <param name="parent">The parent <see cref="Control"/>.</param>
        /// <param name="owner">The <see cref="Entity"/> that this <see cref="ChatBubble"/> is for.</param>
        /// <param name="text">The text to display.</param>
        /// <exception cref="ArgumentNullException"><paramref name="owner" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="text" /> is <c>null</c>.</exception>
        public ChatBubble(Control parent, Entity owner, string text) : base(parent, Vector2.Zero, Vector2.Zero)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");
            if (string.IsNullOrEmpty(text))
                throw new ArgumentNullException("text");

            _owner = owner;
            _deathTime = (TickCount)(TickCount.Now + Lifespan);
            _textControl = new ChatBubbleText(this, text) { Font = Font };

            _owner.Disposed += ChatBubble_Owner_Disposed;
        }
Example #51
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="reader">The reader to read the values from.</param>
        /// <param name="currentTime">The current time.</param>
        /// <exception cref="ArgumentNullException"><paramref name="reader" /> is <c>null</c>.</exception>
        public MapGrh(IValueReader reader, TickCount currentTime)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            _grh = new Grh(null, AnimType.Loop, currentTime);

            ReadState(reader);

            // Set the initial size value
            var grhSize = Grh.Size;
            Vector2.Multiply(ref _scale, ref grhSize, out _scaledGrhSizeCache);
        }
Example #52
0
        /// <summary>
        /// When overridden in the derived class, draws the graphics to the control.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleDraw(TickCount currentTime)
        {
            // Clear the background
            RenderWindow.Clear(Color.Black);

            // Check for a valid camera
            var cam = Camera;
            if (cam == null)
                return;

            var map = Map;
            if (map == null)
                return;

            // Adjust the camera
            cam.Scale = 1;
            cam.Size = map.Size;
            cam.Min = Vector2.Zero;

            // Store the current map values
            var oldCameraMap = cam.Map;
            var oldDrawParticles = map.DrawParticles;
            var oldCamera = map.Camera;
            var oldDrawFilter = map.DrawFilter;

            try
            {
                // Set our custom map values
                cam.Map = _map;
                map.DrawParticles = false;
                map.Camera = _camera;
                map.DrawFilter = null;

                // Begin drawing
                _spriteBatch.Begin(BlendMode.Alpha, cam);

                // Draw the map
                map.Draw(_spriteBatch);
            }
            finally
            {
                // End drawing
                _spriteBatch.End();

                // Restore the old values
                cam.Map = oldCameraMap;
                map.DrawParticles = oldDrawParticles;
                map.Camera = oldCamera;
                map.DrawFilter = oldDrawFilter;
            }
        }
        /// <summary>
        /// Forces the list cache to update.
        /// </summary>
        public void UpdateCache()
        {
            _cacheUpdateTime = _currentTime + _cacheUpdateRate;

            _listItemsCache.Clear();

            if (GuildInfo != null && GuildInfo.InGuild)
            {
                _cacheStateInGuild = true;
                _listItemsCache.AddRange(GetListItems(GuildInfo));
            }
            else
                _cacheStateInGuild = false;
        }
Example #54
0
        /// <summary>
        /// Gets if a skill group is currently cooling down.
        /// </summary>
        /// <param name="group">The index of the skill group.</param>
        /// <param name="currentTime">The current game time in milliseconds.</param>
        /// <returns>True if the group is currently cooling down and cannot be used; false if the group is available
        /// for usage.</returns>
        public bool IsCoolingDown(byte group, TickCount currentTime)
        {
            if (!_cooldownGroups.ContainsKey(group))
                return false;

            var groupTime = _cooldownGroups[group];
            if (groupTime > currentTime)
                return true;
            else
            {
                _cooldownGroups.Remove(group);
                return false;
            }
        }
Example #55
0
        /// <summary>
        /// Updates all of the <see cref="DamageText"/>s in the pool.
        /// </summary>
        /// <param name="currentTime">Current time.</param>
        public void Update(TickCount currentTime)
        {
            var collectGarbage = false;

            _pool.Perform(delegate(DamageText x)
            {
                x.Update(currentTime);

                if (x.Alpha < 20)
                    collectGarbage = true;
            });

            if (collectGarbage)
                _pool.FreeAll(x => x.Alpha < 20);
        }
Example #56
0
        /// <summary>
        /// Sets the cooldown time for a group of skills.
        /// </summary>
        /// <param name="group">The index of the skill group.</param>
        /// <param name="time">The cooldown time in milliseconds.</param>
        /// <param name="currentTime">The current game time in milliseconds.</param>
        public void SetCooldown(byte group, int time, TickCount currentTime)
        {
            if (time <= 0)
            {
                _cooldownGroups.Remove(group);
                return;
            }

            var endTime = (TickCount)(time + currentTime);

            if (_cooldownGroups.ContainsKey(group))
                _cooldownGroups[group] = endTime;
            else
                _cooldownGroups.Add(group, endTime);
        }
Example #57
0
        /// <summary>
        /// When overridden in the derived class, performs the additional updating that this <see cref="MapGrhEffect"/>
        /// needs to do such as checking if it is time to kill the effect. This method should be overridden instead of
        /// <see cref="MapGrh.Update"/>. This method will not be called after the effect has been killed.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        protected override void UpdateEffect(TickCount currentTime)
        {
            var elapsed = currentTime - _lastUpdate;
            _lastUpdate = currentTime;

            // Get the amount to move, which is the product of the speed and elapsed time
            var modSpeed = elapsed * _speed;

            // Calculate and set the new position
            Position = Position.MoveTowards(_target.Center, modSpeed);

            // Check if we are close enough to the target
            if (Position.QuickDistance(_target.Center) < 8)
                Kill(true);
        }
Example #58
0
        /// <summary>
        /// When overridden in the derived class, performs the additional updating that this <see cref="MapGrhEffect"/>
        /// needs to do such as checking if it is time to kill the effect. This method should be overridden instead of
        /// <see cref="MapGrh.Update"/>. This method will not be called after the effect has been killed.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        protected override void UpdateEffect(TickCount currentTime)
        {
            // Check if enough time has elapsed for us to reach the target position
            if (currentTime >= _endTime)
            {
                Position = _targetPosition;
                Kill(true);
                return;
            }

            // Recalculate the position based on the elapsed time. Recalculate the complete position each time since the computational
            // cost is pretty much the same, and this way doesn't fall victim to accumulated rounding errors
            var elapsedTime = currentTime - _startTime;
            Position = _startPosition + (_velocity * elapsedTime);
        }
Example #59
0
        /// <summary>
        /// Updates the frame counter and the tick count.
        /// </summary>
        /// <param name="gameTime">The current time in milliseconds.</param>
        public void Update(TickCount gameTime)
        {
            // Increases the frame count
            _frameCounter++;

            // Check if the target time has elapsed
            if (_targetTime <= gameTime)
            {
                // Reduce the elapsed time, store the frame rate and reset the counter
                _targetTime += _targetElapseTime;
                if (_targetTime <= gameTime)
                    _targetTime = gameTime + _targetElapseTime;

                _frameRate = _frameCounter;
                _frameCounter = 0;
            }
        }
Example #60
0
        /// <summary>
        /// Handles the real updating of the AI.
        /// </summary>
        protected override void DoUpdate()
        {
            var time = GetTime();

            // Ensure the target is still valid, or enough time has elapsed to check for a better target
            if ((_target != null && !IsValidTarget(_target)) || (_lastTargetUpdateTime + _targetUpdateRate < time))
            {
                _lastTargetUpdateTime = time;
                _target = GetClosestHostile();
            }

            // Check if we have a target or not
            if (_target == null)
                UpdateNoTarget();
            else
                UpdateWithTarget();
        }