Exemple #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CharacterInterceptor" />
        /// </summary>
        /// <param name="orgCharacter">The original <see cref="ICharacter" /> instance that should be intercepted.</param>
        /// <param name="parentClient">The the parent <see cref="ClientInterceptor" /> instance.</param>
        /// <param name="clientListInterceptor">reference to the <see cref="ClientListInterceptor" /></param>
        internal CharacterInterceptor(
            ICharacter orgCharacter,
            ClientInterceptor parentClient,
            ClientListInterceptor clientListInterceptor)
        {
            if (orgCharacter == null)
            {
                throw new ArgumentNullException(nameof(orgCharacter));
            }

            if (parentClient == null)
            {
                throw new ArgumentNullException(nameof(parentClient));
            }

            if (clientListInterceptor == null)
            {
                throw new ArgumentNullException(nameof(clientListInterceptor));
            }

            this.orgCharacter          = orgCharacter;
            this.parentClient          = parentClient;
            this.clientListInterceptor = clientListInterceptor;
            this.Inventory             = new InventoryInterceptor(orgCharacter.Inventory, this);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ClientInterceptor" /> class.
        /// </summary>
        /// <param name="orgClient">
        ///     The reference to the original <see cref="IClient" /> instance that is decorated by the new
        ///     <see cref="ClientInterceptor" /> object.
        /// </param>
        /// <param name="clientListInterceptor">Reference to the <see cref="ClientListInterceptor" /> object.</param>
        internal ClientInterceptor(IClient orgClient, ClientListInterceptor clientListInterceptor)
        {
            if (orgClient == null)
            {
                throw new ArgumentNullException(nameof(orgClient));
            }

            if (clientListInterceptor == null)
            {
                throw new ArgumentNullException(nameof(clientListInterceptor));
            }

            this.orgClient = orgClient;
            this.orgClient.CommandReceived += this.OrgClientCommandReceived;
            this.orgClient.Disconnect      +=
                (o, a) => this.Disconnect?.Invoke(this, new ClientDisconnectedEventArgs(this, a.Reason));
            this.orgClient.MessageReceived += (o, a) => this.MessageReceived?.Invoke(this, a);

            this.PlayerCharacter = new CharacterInterceptor(orgClient.PlayerCharacter, this, clientListInterceptor);
        }