Esempio n. 1
0
            /// <summary>
            /// Handles updating this <see cref="Entity"/>.
            /// </summary>
            /// <param name="imap">The map the <see cref="Entity"/> is on.</param>
            /// <param name="deltaTime">The amount of time (in milliseconds) that has elapsed since the last update.</param>
            protected override void HandleUpdate(IMap imap, int deltaTime)
            {
                // Check if they have requested a new spawn position
                if (_reqNewPositionStartTime != TickCount.MinValue)
                {
                    // Check if enough time has elapsed to try and find the new position
                    if (TickCount.Now - _reqNewPositionStartTime > _findNewPositionTimeout)
                    {
                        Vector2?pos = _spawner.RandomSpawnPosition(BodyInfo);
                        if (!pos.HasValue)
                        {
                            return;
                        }

                        _reqNewPositionStartTime = TickCount.MinValue;

                        RespawnMapID    = _spawner.Map.ID;
                        RespawnPosition = pos.Value;

                        Teleport(_spawner.Map, RespawnPosition);

                        // Check that our attempt to teleport actually succeeded, not just put them at another invalid position
                        if (_reqNewPositionStartTime != TickCount.MinValue)
                        {
                            return;
                        }
                    }
                    else
                    {
                        // Not enough time has elapsed...
                        return;
                    }

                    // They managed to teleport to a valid position - bring to life and clear the timer
                    _reqNewPositionStartTime = TickCount.MinValue;
                    IsAlive = true;

                    EventCounterManager.Map.Increment(_spawner.Map.ID, MapEventCounterType.NPCSpawned);
                }

                base.HandleUpdate(imap, deltaTime);
            }