Example #1
0
        /// <summary>
        /// Handles the contents of a network message.
        /// </summary>
        /// <param name="message">The message to handle.</param>
        /// <param name="connection">A reference to the connection from where this message is comming from, for context.</param>
        /// <returns>A value tuple with a value indicating whether the handler intends to respond, and a collection of <see cref="IOutgoingPacket"/>s that compose that response.</returns>
        public override (bool IntendsToRespond, IEnumerable <IOutgoingPacket> ResponsePackets) HandleRequest(INetworkMessage message, IConnection connection)
        {
            var automovementInfo = message.ReadAutomovementInfo();

            if (!(this.CreatureFinder.FindCreatureById(connection.PlayerId) is IPlayer player))
            {
                return(false, null);
            }

            var responsePackets = new List <IOutgoingPacket>();

            if (!this.Game.PlayerRequest_AutoWalk(player, automovementInfo.Directions))
            {
                responsePackets.Add(new PlayerWalkCancelPacket(automovementInfo.Directions[0]));

                responsePackets.Add(new TextMessagePacket(MessageType.StatusSmall, "Sorry, not possible."));
            }

            return(responsePackets.Count > 0, responsePackets);
        }