public void Execute(IPlayer player) { if (String.IsNullOrEmpty(player.ReceivedInput)) { return; } string[] args = player.ReceivedInput.Split(' '); string direction = String.Empty; if (args.Length >= 2) //will always be at least 1, as the command itself is at index 0, making length 1 { direction = args[1]; //Assume Walk North, so [1] = North (or any other direction) } else { player.SendMessage("Please specify which direction you would like to walk."); return; } AvailableTravelDirections travelDirection = TravelDirections.GetTravelDirectionValue(direction); if (travelDirection == AvailableTravelDirections.None) { player.SendMessage("Invalid direction!"); return; } if (player.Location.DoorwayExists(travelDirection)) { IDoor door = player.Location.GetDoorway(travelDirection); player.Move(door.Arrival); //Make sure we have a valid save path var filePath = Path.Combine(Directory.GetCurrentDirectory(), EngineSettings.Default.PlayerSavePath, player.Username + ".char"); var path = Path.GetDirectoryName(filePath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } //Save the player using our serialization class FileIO fileSave = new FileIO(); fileSave.Save(player, filePath); } player.SwitchState(new LookingState()); }
private void mnuClearDoorway_Click(object sender, EventArgs e) { if (Editor.CurrentRoom == null) { MessageBox.Show("You need to load a room first!", this.Text); return; } ToolStripMenuItem menu = (ToolStripMenuItem)sender; ContextMenuStrip strip = (ContextMenuStrip)menu.Owner; Button doorButton = (Button)strip.SourceControl; string[] content = Regex.Split(doorButton.Text, "\n"); if (content.Length != 2) { MessageBox.Show("You need to load a room! If a room is loaded, please make sure it has a Name set.", this.Text); return; } if (content[1] == "Empty") { MessageBox.Show("There are no doorways for this direction.", this.Text); return; } else { AvailableTravelDirections direction = TravelDirections.GetTravelDirectionValue(content[0]); if (Editor.CurrentRoom.DoorwayExists(direction)) { Editor.CurrentRoom.RemoveDoorway(direction, true); RefreshDoorwayList(); } } }
private void Room_DragDrop(object sender, DragEventArgs e) { if (Editor.CurrentRoom == null) { return; //Don't do any drag & drop if we have no room loaded. } var data = e.Data.GetData(DataFormats.Text); IRoom room = (IRoom)Editor.CurrentZone.GetRoom(data.ToString()); Button btnDirection = (Button)sender; string[] values = btnDirection.Text.Split('\n'); //Trims out the trailing \r the editor button has. string direction = values[0]; AvailableTravelDirections travelDirection = TravelDirections.GetTravelDirectionValue(direction); Editor.CurrentRoom.AddDoorway(travelDirection, room, true, true); roomsLstExistingRooms.SelectedItem = Editor.CurrentRoom.Name; RefreshDoorwayList(); }
private void mnuLoadRoom_Click(object sender, EventArgs e) { if (Editor.CurrentRoom == null) { MessageBox.Show("You need to load a room first!", this.Text); return; } //Get the button text that we are over ToolStripMenuItem menu = (ToolStripMenuItem)sender; ContextMenuStrip strip = (ContextMenuStrip)menu.Owner; Button doorButton = (Button)strip.SourceControl; //Split the "North\nRoomName" text up string[] content = Regex.Split(doorButton.Text, "\n"); //Check if we have two entries. If not then the Button is just "North" meaning no room is loaded if (content.Length != 2) { MessageBox.Show("You need to load a room! If a room is loaded, please make sure it has a Name set.", this.Text); return; } //"North\nEmpty" meaning there is no doorway if (content[1] == "Empty") { MessageBox.Show("There are no doorways for this direction.", this.Text); return; } //Otherwise it will be "North\MyRoom" else { //Get the travel direction for the doorway selected AvailableTravelDirections direction = TravelDirections.GetTravelDirectionValue(content[0]); //Check if the room has a door for the selected travel direction if (Editor.CurrentRoom.DoorwayExists(direction)) { IRoom r = Editor.CurrentRoom.GetDoorway(direction).Arrival; Editor.CurrentRoom = r; //Select the Room for editing. roomsPropertiesRoom.SelectedObject = r; //Select the matching Realm, Zone and Room for the UI combobox and listbox if (roomsComRealms.SelectedItem.ToString() != r.Zone.Realm.Name) { if (roomsComRealms.Items.Contains(r.Zone.Realm.Name)) { roomsComRealms.SelectedItem = r.Zone.Realm.Name; } } if (roomsComZones.SelectedItem.ToString() != r.Zone.Name) { if (roomsComZones.Items.Contains(r.Zone.Name)) { roomsComZones.SelectedItem = r.Zone.Name; } } if (roomsLstExistingRooms.Items.Contains(r.Name)) { roomsLstExistingRooms.SelectedItem = r.Name; } Editor.CurrentRealm = r.Zone.Realm; Editor.CurrentZone = r.Zone; //Refresh the UI labels. RefreshRoomLabels(Editor.CurrentRealm, Editor.CurrentZone, Editor.CurrentRoom); RefreshDoorwayList(); } } }