Beispiel #1
0
 private bool FindDoor(CommandParameter parameter, out ExitDirections exitDirection, out bool wasAskingForDirection)
 {
     if (ExitHelpers.FindDirection(parameter.Value, out exitDirection))
     {
         wasAskingForDirection = true;
         return(true);
     }
     wasAskingForDirection = false;
     //exit = Room.Exits.FirstOrDefault(x => x?.Destination != null && x.IsDoor && x.Keywords.Any(k => FindHelpers.StringStartsWith(k, parameter.Value)));
     foreach (ExitDirections direction in EnumHelpers.GetValues <ExitDirections>())
     {
         IExit exit = Room.Exit(direction);
         if (exit?.Destination != null && exit.IsDoor && exit.Keywords.Any(k => FindHelpers.StringStartsWith(k, parameter.Value)))
         {
             exitDirection = direction;
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
        protected virtual bool DoLook(string rawParameters, params CommandParameter[] parameters)
        {
            // TODO: 0/ sleeping/blind/dark room (see act_info.C:1413 -> 1436)

            // 1: room+exits+chars+items
            if (string.IsNullOrWhiteSpace(rawParameters))
            {
                Log.Default.WriteLine(LogLevels.Debug, "DoLook(1): room");
                DisplayRoom();
                return(true);
            }
            // 2: container in room then inventory then equipment
            if (parameters[0].Value == "in" || parameters[0].Value == "on" || parameters[0].Value == "into")
            {
                Log.Default.WriteLine(LogLevels.Debug, "DoLook(2): container in room, inventory, equipment");
                // look in container
                if (parameters.Length == 1)
                {
                    Send("Look in what?");
                }
                else
                {
                    // search in room, then in inventory(unequiped), then in equipement
                    IItem containerItem = FindHelpers.FindItemHere(this, parameters[1]);
                    if (containerItem == null)
                    {
                        Send(StringHelpers.ItemNotFound);
                    }
                    else
                    {
                        Log.Default.WriteLine(LogLevels.Debug, "DoLook(2): found in {0}", containerItem.ContainedInto.DebugName);
                        IContainer container = containerItem as IContainer;
                        if (container != null)
                        {
                            DisplayContainerContent(container);
                        }
                        // TODO: drink container
                        else
                        {
                            Send("This is not a container.");
                        }
                    }
                }
                return(true);
            }
            // 3: character in room
            ICharacter victim = FindHelpers.FindByName(Room.People.Where(CanSee), parameters[0]);

            if (victim != null)
            {
                Log.Default.WriteLine(LogLevels.Debug, "DoLook(3): character in room");
                DisplayCharacter(victim, true); // TODO: always peeking ???
                return(true);
            }
            // 4:search among inventory/equipment/room.content if an item has extra description or name equals to parameters
            string itemDescription;
            bool   itemFound = FindItemByExtraDescriptionOrName(parameters[0], out itemDescription);

            if (itemFound)
            {
                Log.Default.WriteLine(LogLevels.Debug, "DoLook(4): item in inventory+equipment+room -> {0}", itemDescription);
                Send(itemDescription, false);
                return(true);
            }
            // 5: extra description in room
            if (Room.ExtraDescriptions != null && Room.ExtraDescriptions.Any())
            {
                // TODO: try to use ElementAtOrDefault
                int count = 0;
                foreach (KeyValuePair <string, string> extraDescription in Room.ExtraDescriptions)
                {
                    if (parameters[0].Tokens.All(x => FindHelpers.StringStartsWith(extraDescription.Key, x)) &&
                        ++count == parameters[0].Count)
                    {
                        Send(extraDescription.Value, false);
                        return(true);
                    }
                }
            }
            // 6: direction
            ExitDirections direction;

            if (ExitHelpers.FindDirection(parameters[0].Value, out direction))
            {
                Log.Default.WriteLine(LogLevels.Debug, "DoLook(6): direction");
                IExit exit = Room.Exit(direction);
                if (exit?.Destination == null)
                {
                    Send("Nothing special there.");
                }
                else
                {
                    Send(exit.Description ?? "Nothing special there.");
                    if (exit.Keywords.Any())
                    {
                        if (exit.IsClosed)
                        {
                            Act(ActOptions.ToCharacter, "The {0} is closed.", exit);
                        }
                        else if (exit.IsDoor)
                        {
                            Act(ActOptions.ToCharacter, "The {0} is open.", exit);
                        }
                    }
                }
            }
            else
            {
                Send(StringHelpers.ItemNotFound);
            }
            return(true);
        }