Пример #1
0
        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender        = actionInput.Controller;
            string      commonFailure = VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            string targetName = actionInput.Tail.Trim().ToLower();

            // Rule: if 2 params
            if (actionInput.Params.Length == 2)
            {
                int.TryParse(actionInput.Params[0], out numberToDrop);

                if (numberToDrop == 0)
                {
                    targetName = actionInput.Tail.ToLower();
                }
                else
                {
                    targetName = actionInput.Tail.Remove(0, actionInput.Params[0].Length).Trim().ToLower();
                }
            }

            // Rule: Did the initiator look to drop something?
            if (targetName == string.Empty)
            {
                return("What did you want to drop?");
            }

            dropLocation = sender.Thing.Parent;

            // Rule: Is the target an item in the entity's inventory?
            thingToDrop = sender.Thing.Children.Find(t => t.Name.Equals(targetName, StringComparison.CurrentCultureIgnoreCase));
            if (thingToDrop == null)
            {
                return("You do not hold " + targetName + ".");
            }

            // Rule: The target thing must be movable.
            movableBehavior = thingToDrop.Behaviors.FindFirst <MovableBehavior>();
            if (movableBehavior == null)
            {
                return(thingToDrop.Name + " does not appear to be movable.");
            }

            return(null);
        }
Пример #2
0
        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            var commonFailure = VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            var targetName = actionInput.Tail.Trim().ToLower();

            // Rule: if 2 params
            if (actionInput.Params.Length == 2)
            {
                int.TryParse(actionInput.Params[0], out numberToDrop);

                targetName = numberToDrop == 0 ? actionInput.Tail.ToLower() :
                             actionInput.Tail.Remove(0, actionInput.Params[0].Length).Trim().ToLower();
            }

            // Rule: Did the initiator look to drop something?
            if (targetName == string.Empty)
            {
                return("What did you want to drop?");
            }

            dropLocation = actionInput.Actor.Parent;

            // Rule: Is the target an item in the entity's inventory?
            thingToDrop = actionInput.Actor.Children.Find(t => t.Name.Equals(targetName, StringComparison.CurrentCultureIgnoreCase));
            if (thingToDrop == null)
            {
                return($"You do not hold {targetName}.");
            }

            // Rule: The target thing must be movable.
            movableBehavior = thingToDrop.FindBehavior <MovableBehavior>();
            return(movableBehavior == null ? $"{thingToDrop.Name} does not appear to be movable." : null);
        }
Пример #3
0
        /// <summary>Prepare for, and determine if the command's prerequisites have been met.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender        = actionInput.Controller;
            string      commonFailure = VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            // Check to see if the first word is a number.
            // @@@ Is TryParse meant to be used this way? Character analysis may be better. I worry that
            //     this might be throwing a caught exception upon each fail, which is a typical case here.
            int.TryParse(actionInput.Params[0], out this.numberToGet);

            int    itemParam = 0;
            string itemName  = string.Empty;

            // Rule: If we have to get a number of something, shunt up the positions of our other params.
            if (this.numberToGet > 0)
            {
                itemParam = 1;
            }

            // Rule: is the player using the command to get something from a container
            //       or to get something from the room?
            Thing targetParent = sender.Thing.Parent;

            if (actionInput.Tail.ToLower().Contains("from"))
            {
                // Find the from keyword in the params.
                int itemMarker = 0;
                for (int i = 0; i < actionInput.Params.Length; i++)
                {
                    if (actionInput.Params[i].ToLower() == "from")
                    {
                        itemMarker = i;
                    }
                }

                // Item name is everything from number (if present) to the from marker.
                for (int j = itemParam; j < itemMarker; j++)
                {
                    itemName += actionInput.Params[j] + ' ';
                }

                itemName = itemName.Trim();

                // Container name is everything from the marker to the end.
                string targetFromName = string.Empty;
                for (int i = itemMarker + 1; i < actionInput.Params.Length; i++)
                {
                    targetFromName += actionInput.Params[i] + ' ';
                }

                targetFromName = targetFromName.Trim();

                // Rule: Do we have an item matching the one specified in our inventory?
                // If not then does the room have a container with the name.
                Thing foundContainer = sender.Thing.FindChild(targetFromName.ToLower());
                if (foundContainer == null)
                {
                    foundContainer = targetParent.FindChild(targetFromName.ToLower());

                    if (foundContainer == null)
                    {
                        return(string.Format("You cannot see {0}.", targetFromName));
                    }
                }

                // Rule: Is the 'from' thing specified as a container actually a container?
                ContainerBehavior containerBehavior = foundContainer.Behaviors.FindFirst <ContainerBehavior>();
                if (containerBehavior == null)
                {
                    return(string.Format("{0} is not able to hold {1}.", foundContainer.Name, itemName));
                }

                // @@@ Removed OpensClosesBehavior check here... Test to ensure that 'get' is blocked by the
                //     OpensClosesBehavior receiving and cancelling the relevant events and message is good...

                targetParent = foundContainer;
            }
            else
            {
                // From the room.
                // Item name is everything from number (if present) to the from marker.
                for (int j = itemParam; j < actionInput.Params.Length; j++)
                {
                    itemName += actionInput.Params[j] + ' ';
                }

                itemName = itemName.Trim();
            }

            // Rule: Do we have an item matching in the container?
            this.thingToGet = targetParent.FindChild(itemName.ToLower());
            if (this.thingToGet == null)
            {
                return(string.Format("{0} does not contain {1}.", targetParent.Name, itemName));
            }

            // Rule: The targeted thing must be movable.
            this.movableBehavior = this.thingToGet.Behaviors.FindFirst <MovableBehavior>();
            if (this.movableBehavior == null)
            {
                return(this.thingToGet.Name + " does not appear to be movable.");
            }

            // @@@ TODO: Rule: Is the thing allowed to be picked up? (CannotPickUpBehavior or needs CarryableBehavior or whatnot? hmm)

            return(null);
        }
Пример #4
0
        /// <summary>Prepare for, and determine if the command's prerequisites have been met.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender        = actionInput.Controller;
            string      commonFailure = this.VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            // Check to see if the first word is a number.
            // If so, shunt up the positions of our other params.
            int itemParam   = 0;
            int numberWords = actionInput.Params.Length;

            if (int.TryParse(actionInput.Params[0], out this.numberToGive))
            {
                itemParam = 1;

                // If the user specified a number, but it is less than 1, error!
                if (this.numberToGive < 1)
                {
                    return("You can't give less than 1 of something.");
                }

                // Rule: We should now have at least 3 items in our words array.
                // (IE "give 10 coins to Karak" or "give 10 coins Karak")
                if (numberWords < 3)
                {
                    return("You must specify something to give, and a target.");
                }
            }

            // The next parameter should be the item name (possibly pluralized).
            string itemName = actionInput.Params[itemParam];

            // Do we have an item matching the name in our inventory?
            this.thing = sender.Thing.FindChild(itemName.ToLower());
            if (this.thing == null)
            {
                return("You do not hold " + itemName + ".");
            }

            // The final argument should be the target name.
            string targetName = actionInput.Params[actionInput.Params.Length - 1];

            // Rule: Do we have a target?
            if (string.IsNullOrEmpty(targetName))
            {
                return("You must specify someone to give that to.");
            }

            // TODO: Shared targeting code should be used, and this rule should be implemented like:
            //       if (this.target == sender.Thing) ...
            // Rule: The giver cannot also be the receiver.
            if (targetName == "me")
            {
                return("You can't give something to yourself.");
            }

            // Rule: Is the target an entity?
            this.target = GetPlayerOrMobile(targetName);
            if (this.target == null)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: Is the target in the same room?
            if (sender.Thing.Parent.Id != this.target.Parent.Id)
            {
                return("You cannot see " + targetName + ".");
            }

            // Rule: The thing being given must be movable.
            this.movableBehavior = this.thing.Behaviors.FindFirst <MovableBehavior>();

            return(null);
        }
Пример #5
0
 public SvgControlGlyph(ReportItem reportItem, SvgDesigner designer)
     : base(designer.BehaviorService, designer)
 {
     Behavior = new MovableBehavior(reportItem, this);
 }