Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeItemEvent"/> class.
        /// </summary>
        /// <param name="logger">A reference to the logger in use.</param>
        /// <param name="game">A reference to the game instance.</param>
        /// <param name="connectionManager">A reference to the connection manager in use.</param>
        /// <param name="tileAccessor">A reference to the tile accessor in use.</param>
        /// <param name="creatureFinder">A reference to the creature finder in use.</param>
        /// <param name="requestorId">The id of the creature requesting the use.</param>
        /// <param name="typeId">The type id of the item being used.</param>
        /// <param name="fromLocation">The location from which the item is being used.</param>
        /// <param name="toTypeId">The type id of the item to change to.</param>
        /// <param name="fromStackPos">The position in the stack from which the item is being used.</param>
        /// <param name="index">The index of the item being used.</param>
        /// <param name="evaluationTime">The time to evaluate the movement.</param>
        public ChangeItemEvent(
            ILogger logger,
            IGame game,
            IConnectionManager connectionManager,
            ITileAccessor tileAccessor,
            ICreatureFinder creatureFinder,
            uint requestorId,
            ushort typeId,
            Location fromLocation,
            ushort toTypeId,
            byte fromStackPos             = byte.MaxValue,
            byte index                    = 1,
            EvaluationTime evaluationTime = EvaluationTime.OnBoth)
            : base(logger, requestorId, evaluationTime)
        {
            game.ThrowIfNull(nameof(game));
            tileAccessor.ThrowIfNull(nameof(tileAccessor));
            connectionManager.ThrowIfNull(nameof(connectionManager));
            creatureFinder.ThrowIfNull(nameof(creatureFinder));

            this.ConnectionManager = connectionManager;
            this.CreatureFinder    = creatureFinder;
            this.Game = game;

            this.ActionsOnFail.Add(new GenericEventAction(this.NotifyOfFailure));

            var onPassAction = new GenericEventAction(() =>
            {
                var fromCylinder = this.Game.GetCyclinder(fromLocation, ref fromStackPos, ref index, this.Requestor);
                var item         = this.Game.FindItemByIdAtLocation(typeId, fromLocation, this.Requestor);

                bool successfulUse = this.Game.PerformItemChange(item, toTypeId, fromCylinder, index, this.Requestor);

                if (!successfulUse)
                {
                    // handles check for isPlayer.
                    this.NotifyOfFailure();

                    return;
                }
            });

            this.ActionsOnPass.Add(onPassAction);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeleteItemEvent"/> class.
        /// </summary>
        /// <param name="logger">A reference to the logger in use.</param>
        /// <param name="game">A reference to the game instance.</param>
        /// <param name="connectionManager">A reference to the connection manager in use.</param>
        /// <param name="tileAccessor">A reference to the tile accessor in use.</param>
        /// <param name="creatureFinder">A reference to the creature finder in use.</param>
        /// <param name="requestorId">The id of the creature requesting the deletion.</param>
        /// <param name="typeId">The type id of the item being deleted.</param>
        /// <param name="atLocation">The location from which the item is being deleted.</param>
        /// <param name="evaluationTime">The time to evaluate the event.</param>
        public DeleteItemEvent(
            ILogger logger,
            IGame game,
            IConnectionManager connectionManager,
            ITileAccessor tileAccessor,
            ICreatureFinder creatureFinder,
            uint requestorId,
            ushort typeId,
            Location atLocation,
            EvaluationTime evaluationTime = EvaluationTime.OnBoth)
            : base(logger, requestorId, evaluationTime)
        {
            game.ThrowIfNull(nameof(game));
            tileAccessor.ThrowIfNull(nameof(tileAccessor));
            connectionManager.ThrowIfNull(nameof(connectionManager));
            creatureFinder.ThrowIfNull(nameof(creatureFinder));

            this.ConnectionManager = connectionManager;
            this.CreatureFinder    = creatureFinder;
            this.Game = game;

            this.ActionsOnFail.Add(new GenericEventAction(this.NotifyOfFailure));

            var onPassAction = new GenericEventAction(() =>
            {
                byte index = 0, subIndex = 0;

                var fromCylinder = this.Game.GetCyclinder(atLocation, ref index, ref subIndex, this.Requestor);
                var item         = this.Game.FindItemByIdAtLocation(typeId, atLocation, this.Requestor);

                bool successfulDeletion = this.Game.PerformItemDeletion(item, fromCylinder, subIndex, this.Requestor);

                if (!successfulDeletion)
                {
                    // handles check for isPlayer.
                    this.NotifyOfFailure();

                    return;
                }
            });

            this.ActionsOnPass.Add(onPassAction);
        }