示例#1
0
        /// <summary>
        /// Performs a container open action for a player.
        /// </summary>
        /// <param name="forCreatureId">The id of the creature for which the container is being opened.</param>
        /// <param name="container">The container to open.</param>
        /// <param name="atPosition">The position in which to open the container, for the player.</param>
        public void OpenContainer(uint forCreatureId, IContainerItem container, byte atPosition)
        {
            container.ThrowIfNull(nameof(container));

            // Check if this creature already has this container open at the specified position.
            // If so, we got nothing more to do.
            if (this.IsContainerOpen(container.UniqueId, forCreatureId, out IEnumerable <byte> openPositions) && openPositions.Contains(atPosition))
            {
                return;
            }

            // Otherwise, let's check if the player has something else open at the desired container position.
            var currentContainer = this.GetContainerAt(forCreatureId, atPosition);

            if (currentContainer != null)
            {
                // In this case, we need to close this container first.
                this.CloseContainerInternal(forCreatureId, currentContainer, atPosition);
            }

            // Now, actually open the container for this creature.
            byte containerId = this.OpenContainerInternal(forCreatureId, container, atPosition);

            if (this.creatureFinder.FindPlayerById(forCreatureId) is IPlayer player)
            {
                this.ContainerOpened?.Invoke(player, containerId, container);
            }
        }
示例#2
0
        /// <summary>
        /// Performs a container close action for a player.
        /// </summary>
        /// <param name="forCreatureId">The id of the creature for which the container is being closed.</param>
        /// <param name="container">The container being closed.</param>
        /// <param name="atPosition">The position of the container being closed, as seen by the player.</param>
        public void CloseContainer(uint forCreatureId, IContainerItem container, byte atPosition)
        {
            container.ThrowIfNull(nameof(container));

            // Check if this creature doesn't have this container open, or it's no longer at the position specified.
            if (!this.IsContainerOpen(container.UniqueId, forCreatureId, out IEnumerable <byte> openPositions) || !openPositions.Contains(atPosition))
            {
                return;
            }

            this.CloseContainerInternal(forCreatureId, container, atPosition);

            if (this.creatureFinder.FindPlayerById(forCreatureId) is IPlayer player)
            {
                this.scheduler.ScheduleEvent(new GenericNotification(() => player.YieldSingleItem(), new ContainerClosePacket(atPosition)));
            }
        }
        /// <summary>
        /// Performs a container open action for a player.
        /// </summary>
        /// <param name="forCreatureId">The id of the creature for which the container is being opened.</param>
        /// <param name="container">The container to open.</param>
        /// <param name="atPosition">The position in which to open the container, for the player.</param>
        public void OpenContainer(uint forCreatureId, IContainerItem container, byte atPosition)
        {
            container.ThrowIfNull(nameof(container));

            // Check if this creature already has this container open at the specified position.
            // If so, we got nothing more to do.
            if (this.IsContainerOpen(container.UniqueId, forCreatureId, out IEnumerable <byte> openPositions) && openPositions.Contains(atPosition))
            {
                return;
            }

            // Otherwise, let's check if the player has something else open at the desired container position.
            var currentContainer = this.GetContainerAt(forCreatureId, atPosition);

            if (currentContainer != null)
            {
                // In this case, we need to close this container first.
                this.CloseContainerInternal(forCreatureId, currentContainer, atPosition);
            }

            // Now, actually open the container for this creature.
            byte containerId = this.OpenContainerInternal(forCreatureId, container, atPosition);

            if (this.creatureFinder.FindPlayerById(forCreatureId) is IPlayer player)
            {
                var notification = new GenericNotification(
                    () => player.YieldSingleItem(),
                    new ContainerOpenPacket(
                        containerId,
                        container.TypeId,
                        container.Type.Name,
                        container.Capacity,
                        container.ParentContainer is IContainerItem parentContainer && parentContainer.Type.TypeId != 0,
                        container.Content));

                this.scheduler.ScheduleEvent(notification);
            }
        }
示例#4
0
        /// <summary>
        /// Opens a container for this player, which tracks it.
        /// </summary>
        /// <param name="container">The container being opened.</param>
        /// <returns>The id of the container as seen by this player.</returns>
        public byte OpenContainer(IContainerItem container)
        {
            container.ThrowIfNull(nameof(container));

            for (byte i = 0; i < this.openContainers.Length; i++)
            {
                if (this.openContainers[i] != null)
                {
                    continue;
                }

                this.openContainers[i] = container;
                this.openContainers[i].BeginTracking(this.Id, i);

                return(i);
            }

            var lastIdx = (byte)(this.openContainers.Length - 1);

            this.openContainers[lastIdx] = container;

            return(lastIdx);
        }