Exemplo n.º 1
0
        /// <summary>
        /// Try to parse the input as a command for this MOB to perform. If found, immediately executes the command.
        /// This method will probably end up being refactored in the future, some of this makes more sense in Command.cs and
        /// some of this will need to be smarter about context for commands before just running commands (e.g. 'order')
        /// </summary>
        /// <param name="input">Full input string to try to Execute.</param>
        /// <param name="currentMob">Current MOB to perform the action as, if there is a MOB associated with the input.</param>
        public void TryFindCommand(string input, MOB currentMob)
        {
            string[] words       = input.Split(' ');
            string   commandWord = words[0].ToLower();
            Command  command;

            if (Command.UniqueCommands.TryGetValue(commandWord, out command))
            {
                if (!command.CanUse(this, currentMob))
                {
                    sendMessage("You cannot ever use \"" + command.OriginalCommandName + "\".");
                    return;
                }
            }
            else
            {
                List <CommandEntry> options = Command.SortedAllCommands;
                int index = options.BinarySearch(new CommandEntry(commandWord, null));
                if (index < 0)
                {
                    index = -index - 1;
                }
                while (index > 0 && options[index - 1].Trigger.StartsWith(commandWord)) //In case of exact commandWord matches, backtrack to the first Command with that word.
                {
                    index--;
                }
                while (index < options.Count)
                {
                    CommandEntry next = options[index];
                    if (!next.Trigger.StartsWith(commandWord))
                    {
                        break; //No matches. command is default from TryGetValue
                    }
                    if (next.Command.CanUse(this, currentMob))
                    {
                        command = next.Command;
                        break;
                    }
                }
            }

            if (command != null)
            {
                QueuedCommand userCommand = command.GetQueuedCommand(input);
                if (currentMob != null)
                {
                    command.Execute(currentMob, userCommand);
                }
                else
                {
                    command.Execute(this, userCommand);
                }
            }
            else
            {
                sendMessage("No command available for \"" + words[0] + "\".");
            }
        }
Exemplo n.º 2
0
        public override void Execute(MOB mob, QueuedCommand command)
        {
            StringWords  input    = command.parsedCommand;
            int          distance = -1;
            MovementUnit unit;

            if (input.Segments.Length > 1)
            {
                TextParsing.ParseAsDistance(input, out distance, out unit, 1);
            }
            //TODO: finish this
        }
Exemplo n.º 3
0
        public override void Execute(MOB mob, QueuedCommand command)
        {
            /*
             * Form is always (optional direction/distance) (optional preposition) (optional target)
             *  direction/distance can work alone (implies 'from here')
             *  if direction/distance is missing, if preposition is not specific, 'in reach' is implied
             *  preposition requires a target
             *  target can work alone (depends on target. If target defaults to enterable, implies 'in'. Else 'near')
             * Search for prepositions, get a list of them.
             *  Validate prepositions. Need to have nothing or a valid direction/distance before preposition.
             *  How many can actually be possible? I think only zero or one preposition is really possible?
             *  TODO: Special user input to specify a preposition instead of parser guessing. Mostly goes in StringWords but
             *  matching prepositions/item names needs to respect that too (might work automatically).
             *      Some system similar to quotes probably. Quotes may be useful though, like book titles or something.
             * If no prepositions, attempt to parse full string as direction/distance. If successful, do that
             * //Search whole string for item/target matches and associated strings.
             *  In general, 'visible to MOB' items.
             *  Must match to end of string?
             *  Nevermind, this string will be identified but targets will not be searched for until a TryGoEvent is run.
             * //Find associated strings that line up with a preposition
             * Instead of above two major points:
             *  Identify all valid strings (start after preposition, go to end of string)
             *      TODO: Special user input to specify a string instead of parser guessing?
             *          This is basically implied by a preposition. However it maybe makes more sense to specify the target instead of the preposition.
             *  //Search all 'visible to MOB' items that exactly match any of the valid strings.
             * How to pick best match?
             *  Maybe just not go if more than one match found, request more info. prompt?
             */
            StringWords goToInput = command.parsedCommand;

            //See if there's a preposition
            int start = 1; //Skip command ("go")
            int prepValue;
            MovementPreposition prepEnum;
            MovementDirection   direction = null;
            TryGoEvent          moveEvent = new TryGoEvent();
            int index = TextParsing.FindAPreposition(goToInput, typeof(MovementPreposition), out prepValue, start);

            if (index != -1)
            {
                //Is this a valid preposition? Check if it starts correctly.
                prepEnum = (MovementPreposition)prepValue;
                if (!prepEnum.AllowDirection() && !prepEnum.AllowDistance())
                {
                    if (index != start + 1)
                    {
                        //Invalid preposition for this location, needs to be at start of command.
                        goto noPrepositionFound;
                    }
                }
                else if ((prepEnum.RequireDirection() || prepEnum.RequireDistance()) && index == start + 1)
                {
                    //Invalid preposition for this location, needs to come after a direction/distance.
                    goto noPrepositionFound;
                }
                else
                {
                    direction = TextParsing.ParseAsDirection(goToInput, start, ref index, prepEnum.RequireDirection(), prepEnum.RequireDistance(), prepEnum.AllowDirection(), prepEnum.AllowDistance());
                    if (direction == null) //Not a valid preposition. Ignore it.
                    {
                        goto noPrepositionFound;
                    }
                    else //Maybe valid preposition.
                    {
                        //Check if preposition matches direction more closely? I think the previous checks have finished that successfully at this point.

                        //Valid preposition. Parse the REST of the sentence as an object.
                        start = index;
                        goto startEvent;
                    }
                }
            }
            else
            {
                //Is the whole thing a direction?
                direction = TextParsing.ParseAsDirection(goToInput, start, ref index);
                if (direction != null)
                {
                    if (direction.direction != Directions.NoDirection && index == goToInput.Segments.Length)
                    {
                        //Mark it as ONLY a direction, no destination (goToInput has been completely parsed/consumed)
                        goToInput = null;
                        //goto startEvent;
                    }
                    else
                    {
                        //Can't go only a distance with NoDirection. Cancel this parsing.
                        direction = null;
                    }
                }
                //Else try to parse the whole thing as an object to go to
            }
            //Text parsing has decided what words go to what (i.e. direction vs. target).
            //Text parsing has NOT identified objects yet.
noPrepositionFound:
            moveEvent.targetDescription = goToInput;
            start    = 1;
            prepEnum = MovementPreposition.To; // null; ?

startEvent:                                    //foundPreposition
            moveEvent.targetDescriptionStart = start;
            moveEvent.direction = direction;
            moveEvent.relation  = prepEnum;
            moveEvent.SetMoveSource(mob, null);

            //Raw command parsing done, target parsing has not been done.
            //Run the event to try to find a path to the target.
            moveEvent.FullRunEvent();
        }
Exemplo n.º 4
0
 public override void Execute(Client user, QueuedCommand command)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command"></param>
 /// <param name="position"></param>
 /// <param name="vehicle"></param>
 /// <param name="targetData"></param>
 /// <returns></returns>
 public abstract bool CanReachFrom(QueuedCommand command, IRoomPosition position, ref object targetData);
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command">Action that is trying to be satisfied/accomplished.</param>
 /// <param name="surface">Surface this is on. If the obstacle is null, this is in air instead of on a surface.</param>
 /// <param name="targetData">Cached data for calculations from this mechanism for this command.</param>
 /// <returns>Null if there are no targets on the surface. Else a list of regions that might allow the acting MOB to
 /// satisfy the action - it doesn't have to be guaranteed that all spots in the region will satisfy the action, but
 /// all spots that satisfy the action must be in the region.</returns>
 public abstract List <TargetRegion> TargetsOnSurface(QueuedCommand command, ObstacleSurface surface, ref object targetData);
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command"></param>
 /// <returns>
 /// </returns>
 public abstract ValidToPerform CanPerform(QueuedCommand command);
Exemplo n.º 8
0
 /// <summary>
 /// Runs this command with the given user and arguments.
 /// </summary>
 /// <param name="user">Logged in user to perform the command.</param>
 /// <param name="command">Performed command data</param>
 public abstract void Execute(Client user, QueuedCommand command);
Exemplo n.º 9
0
 /// <summary>
 /// Runs this command with the given mob and arguments.
 /// </summary>
 /// <param name="mob">Mob to perform the command.</param>
 /// <param name="command">Performed command data</param>
 public abstract void Execute(MOB mob, QueuedCommand command);
Exemplo n.º 10
0
 public override List <TargetRegion> TargetsOnSurface(QueuedCommand command, ObstacleSurface surface, ref object targetData)
 {
     //TODO
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 public override bool CanReachFrom(QueuedCommand command, IRoomPosition position, ref object targetData)
 {
     //TODO
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 public override ValidToPerform CanPerform(QueuedCommand command)
 {
     //TODO
     throw new NotImplementedException();
 }