示例#1
0
        //Room MainLocation { get; }

        public bool CanRecognize(Item item, StringWords input, int start, int end)
        {
            //TODO eventually: Features like sight flags and ignore color codes and so on. For now...

            if (TextParsing.CheckAutoCompleteText(input, item.Name, start, end) || TextParsing.CheckAutoCompleteText(input, item.Description, start, end))
            {
                return(true);
            }
            return(false);
        }
示例#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
        }
示例#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();
        }