Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ContextCommand"/> class.
 /// </summary>
 /// <param name="commandScript">The command script.</param>
 /// <param name="commandKey">The command key.</param>
 /// <param name="availability">The availability.</param>
 /// <param name="securityRole">The security role.</param>
 public ContextCommand(
     GameAction commandScript,
     string commandKey, 
     ContextAvailability availability, 
     SecurityRole securityRole)
 {
     this.CommandScript = commandScript;
     this.CommandKey = commandKey;
     this.Availability = availability;
     this.SecurityRole = securityRole;
 }
Exemplo n.º 2
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.
            // 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.");
            }

            // @@@ 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 = GameAction.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);
        }