Пример #1
0
        /// <summary>
        /// Retrieves a combined list of all entities in this room excluding shop items
        /// </summary>
        /// <returns>A list of entities</returns>
        public List <T> GetAllEntities <T>() where T : IEntity
        {
            var animates = Animates.GetAllEntities <EntityAnimate>().Cast <IEntity>();
            var items    = Items.GetAllEntities <EntityInanimate>().Cast <IEntity>();

            return(animates.Concat(items).Where(i => i.GetType() == typeof(T)).Cast <T>().ToList());
        }
Пример #2
0
            public void AddBytes(List <byte> bytes)
            {
                HasTreeBurned.AddByte(bytes);
                IsAnimateTriggered.AddByte(bytes);
                DoNext.AddByte(bytes);

                Configuration.AddSnapshotBytes(bytes);
                LocationCommandProcessor.AddSnapshotBytes(bytes);
                Items.AddSnapshotsBytes(bytes);
                Flashlight.AddSnapshotBytes(bytes);
                Animates.AddSnapshotsBytes(bytes);
                Player.AddSnapshotBytes(bytes);
            }
Пример #3
0
        /// <summary>
        /// Handles the ObjectDestroyed event. Only DataAccess should call this directly.
        /// </summary>
        /// <param name="source">The object raising the event</param>
        /// <param name="args">The generic event args</param>
        override protected void OnObjectDestroyed(object source, CacheObjectEventArgs args)
        {
            // Safely remove players without deleting/disconnecting them
            var players = Animates.GetAllEntitiesAsObjects <Player>();

            foreach (var player in players)
            {
                Animates.RemoveEntity(player?.Instance, player);
            }

            DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? Animates.Instance : Animates.Prototype, args.CacheType);
            DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? Items.Instance : Items.Prototype, args.CacheType);
            DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? ShopItems.Instance : ShopItems.Prototype, args.CacheType);
            DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? StorageItems.Instance : StorageItems.Prototype, args.CacheType);
        }
Пример #4
0
        /// <summary>
        /// Initialize a new instance of the FixedMetaPanelBase class.
        /// </summary>
        public FixedMetaPanelBase()
        {
            NewPositionAnimate newPos = new NewPositionAnimate();

            newPos.SetBinding(NewPositionAnimate.DurationProperty, ThisBinding("Duration"));
            newPos.SetBinding(NewPositionAnimate.EasingProperty, ThisBinding("Easing"));
            newPos.SetBinding(NewPositionAnimate.LocationProperty, ThisBinding("NewLocation"));
            newPos.SetBinding(NewPositionAnimate.SizeProperty, ThisBinding("NewSize"));
            Animates.Add(newPos);

            NewOpacityAnimate newOpacity = new NewOpacityAnimate();

            newOpacity.SetBinding(NewOpacityAnimate.DurationProperty, ThisBinding("Duration"));
            newOpacity.SetBinding(NewOpacityAnimate.EasingProperty, ThisBinding("Easing"));
            newOpacity.SetBinding(NewOpacityAnimate.StartProperty, ThisBinding("StartOpacity"));
            Animates.Add(newOpacity);

            MovePositionAnimate movePos = new MovePositionAnimate();

            movePos.SetBinding(MovePositionAnimate.DurationProperty, ThisBinding("Duration"));
            movePos.SetBinding(MovePositionAnimate.EasingProperty, ThisBinding("Easing"));
            Animates.Add(movePos);

            RemovePositionAnimate removePos = new RemovePositionAnimate();

            removePos.SetBinding(RemovePositionAnimate.DurationProperty, ThisBinding("Duration"));
            removePos.SetBinding(RemovePositionAnimate.EasingProperty, ThisBinding("Easing"));
            removePos.SetBinding(RemovePositionAnimate.LocationProperty, ThisBinding("RemoveLocation"));
            removePos.SetBinding(RemovePositionAnimate.SizeProperty, ThisBinding("RemoveSize"));
            Animates.Add(removePos);

            RemoveOpacityAnimate removeOpacity = new RemoveOpacityAnimate();

            removeOpacity.SetBinding(RemoveOpacityAnimate.DurationProperty, ThisBinding("Duration"));
            removeOpacity.SetBinding(RemoveOpacityAnimate.EasingProperty, ThisBinding("Easing"));
            removeOpacity.SetBinding(RemoveOpacityAnimate.EndProperty, ThisBinding("EndOpacity"));
            Animates.Add(removeOpacity);
        }
Пример #5
0
        /// <summary>
        /// Spawns an instance of the room from prototype and adds it to the cache.
        /// </summary>
        /// <param name="withEntities">Whether to also spawn contained entities</param>
        /// <param name="parent">The parent area instance ID</param>
        /// <returns>The instance ID of the spawned room. Will return null if the method is called from an instanced object.</returns>
        /// <remarks>Exits will all be null and must be fixed from prototype. Parent cannot be null. Adds new room to instanced area.</remarks>
        public override uint?Spawn(bool withEntities, uint parent)
        {
            if (CacheType != CacheType.Prototype)
            {
                return(null);
            }

            var parentContainer = DataAccess.Get <EntityContainer>(parent, CacheType.Instance);
            var parentArea      = DataAccess.Get <Area>(parentContainer.InstanceParent, CacheType.Instance);

            if (parentContainer == null || parentArea == null)
            {
                throw new LocaleException("Parent cannot be null when spawning a room.");
            }

            Logger.Info(nameof(Room), nameof(Spawn), "Spawning room: " + Name + ": ProtoID=" + Prototype.ToString());

            // Create new instance room and add to parent area
            var newRoom = DataAccess.Get <Room>(DataAccess.Add <Room>(new Room(), CacheType.Instance), CacheType.Instance);

            parentArea.Rooms.AddEntity(newRoom.Instance, newRoom, false);

            // Set remaining properties
            newRoom.Prototype = Prototype;
            CopyTo(newRoom);

            // Spawn contained entities
            if (withEntities)
            {
                newRoom.Animates = Animates.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
                foreach (var animate in Animates.GetAllEntitiesAsObjects <EntityAnimate>())
                {
                    animate.Spawn(withEntities, (uint)newRoom.Animates.Instance);
                }

                newRoom.Items = Items.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
                foreach (var item in Items.GetAllEntitiesAsObjects <EntityInanimate>())
                {
                    item.Spawn(withEntities, (uint)newRoom.Items.Instance);
                }

                newRoom.ShopItems = ShopItems.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
                foreach (var item in ShopItems.GetAllEntitiesAsObjects <EntityInanimate>())
                {
                    item.Spawn(withEntities, (uint)newRoom.ShopItems.Instance);
                }

                newRoom.StorageItems = StorageItems.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
                foreach (var item in StorageItems.GetAllEntitiesAsObjects <EntityInanimate>())
                {
                    item.Spawn(withEntities, (uint)newRoom.StorageItems.Instance);
                }
            }
            else
            {
                newRoom.Animates     = Animates.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
                newRoom.Items        = Items.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
                newRoom.ShopItems    = ShopItems.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
                newRoom.StorageItems = StorageItems.SpawnAsObject <EntityContainer>(!withEntities, (uint)newRoom.Instance);
            }

            Logger.Info(nameof(Room), nameof(Spawn), "Finished spawning room.");

            return(newRoom.Instance);
        }
Пример #6
0
        private bool AnimateChildren(MetaElementStateDict stateDict, ICollection elements)
        {
            // Find number of milliseconds elapsed since last animation calculation, note that if not
            // currently animating then the elapsed time since the last animation cycle must be 0.
            double elapsedMilliseconds = (!IsAnimating || (_lastTicks == -1) ? 0 : (_nextTicks - _lastTicks) / (double)(10000));

            if (IsAnimationAllowed)
            {
                // Ask the chain of animation classes to apply any required movement changes
                Animates.ApplyAnimation(AnimateId, this, stateDict, elements, elapsedMilliseconds);
            }

            // Post-process on animation state
            bool moreAnimation = false;

            foreach (MetaElementState elementState in stateDict.Values)
            {
                // At end of animation cycle the new/remove values must have been calculated
                elementState.NewCalculating = false;
                if (elementState.Status == MetaElementStatus.Removing)
                {
                    elementState.RemoveCalculated = true;
                }

                // Has the element finished being removed?
                if (elementState.AnimateComplete && (elementState.Status == MetaElementStatus.Removing))
                {
                    _removeList.Add(elementState);
                }
                else
                {
                    // If the element has not finished being animated
                    if (!elementState.AnimateComplete)
                    {
                        // Always reset to being completed, ready for next cycle
                        elementState.AnimateComplete = true;
                        moreAnimation = true;
                    }
                    else
                    {
                        // Has element finished being 'new'?
                        if (elementState.Status == MetaElementStatus.New)
                        {
                            elementState.Status = MetaElementStatus.Existing;
                        }

                        // Animation is completed so ensure the current rect is same as the target
                        // rect. This ensures that if there are no animation classes actually doing
                        // size/position animation then the child elements actually do get positioned.
                        elementState.CurrentRect = elementState.TargetRect;
                    }
                }

                // Reset the target changed flag
                elementState.TargetChanged = false;

                // Never allow the current rect to be empty
                if (elementState.CurrentRect.IsEmpty)
                {
                    elementState.CurrentRect = elementState.TargetRect;
                }
            }

            // Process the removal list
            foreach (MetaElementState elementState in _removeList)
            {
                RemoveChildElement(elementState.Element);
                stateDict.Remove(elementState.Element);
                moreAnimation = true;
            }

            // Must clear list to prevent dangling references to the removed UIElement instances
            _removeList.Clear();

            return(moreAnimation);
        }