示例#1
0
        protected virtual bool DoLock(string rawParameters, params CommandParameter[] parameters)
        {
            if (parameters.Length == 0)
            {
                Send("Lock what?");
                return(true);
            }

            // TODO: search item

            // No item found, search door
            ExitDirections exitDirection;
            IExit          exit = VerboseFindDoor(parameters[0], out exitDirection);

            if (exit == null)
            {
                return(true);
            }
            if (!exit.IsClosed)
            {
                Send("It's not closed.");
                return(true);
            }
            if (exit.Blueprint.Key <= 0)
            {
                Send("It can't be locked.");
                return(true);
            }
            // search key
            bool keyFound = Content.OfType <IItemKey>().Any(x => x.Blueprint.Id == exit.Blueprint.Key);

            if (!keyFound)
            {
                Send("You lack the key.");
                return(true);
            }
            if (exit.IsLocked)
            {
                Send("It's already locked.");
                return(true);
            }
            // Unlock this side
            exit.Lock();
            Send("*Click*");
            Act(ActOptions.ToRoom, "{0:N} locks the {1}.", this, exit);

            // Unlock other side
            IExit otherSideExit = exit.Destination.Exit(ExitHelpers.ReverseDirection(exitDirection));

            if (otherSideExit != null)
            {
                otherSideExit.Lock();
            }
            else
            {
                Log.Default.WriteLine(LogLevels.Warning, $"Non bidirectional exit in room {Room.Blueprint.Id} direction {exitDirection}");
            }

            return(true);
        }
示例#2
0
        protected virtual bool DoOpen(string rawParameters, params CommandParameter[] parameters)
        {
            if (parameters.Length == 0)
            {
                Send("Open what?");
                return(true);
            }
            // TODO: search item

            // No item found, search door
            ExitDirections exitDirection;
            IExit          exit = VerboseFindDoor(parameters[0], out exitDirection);

            if (exit == null)
            {
                return(true);
            }
            if (!exit.IsClosed)
            {
                Send("It's already open.");
                return(true);
            }
            if (exit.IsLocked)
            {
                Send("It's locked.");
                return(true);
            }

            // Open this side side
            exit.Open();
            Act(ActOptions.ToRoom, "{0:N} opens the {1}.", this, exit);
            Send("Ok.");

            // Open the other side
            IExit otherSideExit = exit.Destination.Exit(ExitHelpers.ReverseDirection(exitDirection));

            if (otherSideExit != null)
            {
                otherSideExit.Open();
                Act(exit.Destination.People, "The {0} opens.", otherSideExit);
            }
            else
            {
                Log.Default.WriteLine(LogLevels.Warning, $"Non bidirectional exit in room {Room.Blueprint.Id} direction {exitDirection}");
            }
            return(true);
        }
示例#3
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);
 }
示例#4
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);
        }