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); }
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); }