internal override bool TakeInput(GameClient invoker, string command, string rawCommand, string arguments) { if (invoker.shell != null && invoker.shell.location != null && invoker.shell.location.HasComponent(Text.CompRoom) && invoker.shell.HasComponent(Text.CompMobile)) { MobileComponent mob = (MobileComponent)invoker.shell.GetComponent(Text.CompMobile); if (mob.CanMove()) { string tmp = command; if (Text.shortExits.ContainsKey(tmp)) { tmp = Text.shortExits[tmp]; } RoomComponent room = (RoomComponent)invoker.shell.location.GetComponent(Text.CompRoom); if (room.exits.ContainsKey(tmp)) { GameObject destination = (GameObject)Game.Objects.Get(room.exits[tmp]); if (destination == null) { invoker.WriteLine($"Strangely, there is nothing to the {tmp}. You stay where you are."); } else { GameObject loc = invoker.shell.location; invoker.WriteLine($"You depart to the {tmp}."); destination.ShowToContents($"{mob.GetString(Text.FieldEnterMessage).Replace("$DIR", tmp)}"); invoker.shell.Move(destination); loc.ShowToContents($"{mob.GetString(Text.FieldLeaveMessage).Replace("$DIR", tmp)}"); } return(true); } } } return(InvokeCommand(invoker, command, arguments)); }
internal GameObject FindGameObjectInContents(string token, bool silent) { string checkToken = token.ToLower(); foreach (GameObject gameObj in contents) { if ($"{gameObj.id}" == checkToken || gameObj.name.ToLower() == checkToken || gameObj.aliases.Contains(checkToken) || $"{gameObj.name}#{gameObj.id}" == checkToken ) { return(gameObj); } } foreach (GameObject gameObj in contents) { if (gameObj.name.ToLower().Contains(checkToken)) { return(gameObj); } foreach (string alias in gameObj.aliases) { if (alias.ToLower().Contains(checkToken) || $"{alias}#{gameObj.id}" == checkToken) { return(gameObj); } } } if (HasComponent(Text.CompRoom)) { RoomComponent room = (RoomComponent)GetComponent(Text.CompRoom); string lookingFor = checkToken; if (Text.shortExits.ContainsKey(lookingFor)) { lookingFor = Text.shortExits[lookingFor]; } if (room.exits.ContainsKey(lookingFor)) { GameObject otherRoom = (GameObject)Game.Objects.Get(room.exits[lookingFor]); if (otherRoom != null) { return(otherRoom); } } } return(null); }
internal void CmdAddroom(GameObject invoker, CommandData cmd) { if (invoker.location == null || !invoker.location.HasComponent(Text.CompRoom)) { invoker.WriteLine("This command is only usable within a room."); } else { if (cmd.objTarget == null) { invoker.WriteLine("Which exit do you wish to add a room to?"); } else if (cmd.strArgs.Length < 1) { invoker.WriteLine("Please specify a valid room ID to link to, or 'new' to use a new room."); } else { string exitToAdd = cmd.objTarget; if (Text.shortExits.ContainsKey(exitToAdd)) { exitToAdd = Text.shortExits[exitToAdd]; } RoomComponent room = (RoomComponent)invoker.location.GetComponent(Text.CompRoom); if (room.exits.ContainsKey(exitToAdd)) { invoker.WriteLine($"There is already an exit to the {exitToAdd} in this room."); } else { long roomId = -1; Console.WriteLine(cmd.strArgs[1]); if (cmd.strArgs[1].ToLower() == "new") { roomId = Modules.Templates.Instantiate("room").id; } else { try { roomId = Int32.Parse(cmd.strArgs[0].ToLower()); } catch (Exception e) { Debug.WriteLine($"Room ID exception: {e.ToString()}."); } } if (roomId == -1 || Game.Objects.Get(roomId) == null) { invoker.WriteLine("Please specify a valid room ID to link to, or 'new' to use a new room."); } else { bool saveEditedRoom = true; GameObject linkingRoom = (GameObject)Game.Objects.Get(roomId); if ((cmd.strArgs.Length >= 2 && cmd.strArgs[1].ToLower() == "one-way") || !linkingRoom.HasComponent(Text.CompRoom) || !Text.reversedExits.ContainsKey(exitToAdd)) { room.exits.Add(exitToAdd, roomId); saveEditedRoom = true; invoker.WriteLine($"You have connected {room.parent.id} to {roomId} via a one-way exit to the {exitToAdd}."); } else { string otherExit = Text.reversedExits[exitToAdd]; RoomComponent otherRoom = (RoomComponent)linkingRoom.GetComponent(Text.CompRoom); if (otherRoom.exits.ContainsKey(otherExit)) { room.exits.Add(exitToAdd, roomId); saveEditedRoom = true; invoker.WriteLine($"Target room already has an exit to the {otherExit}.\nYou have connected {room.parent.id} to {roomId} via a one-way exit to the {exitToAdd}."); } else { room.exits.Add(exitToAdd, roomId); saveEditedRoom = true; otherRoom.exits.Add(otherExit, room.parent.id); Game.Objects.QueueForUpdate(otherRoom.parent); invoker.WriteLine($"You have connected {room.parent.id} to {roomId} via a bidirectional exit to the {exitToAdd}."); } } if (saveEditedRoom) { Game.Objects.QueueForUpdate(room.parent); } } } } } invoker.SendPrompt(); }
internal void ExaminedBy(GameObject viewer, bool fromInside) { string mainDesc = $"{Colours.Fg(Text.Capitalize(shortDescription),Colours.BoldWhite)}."; if (parent.HasComponent(Text.CompMobile)) { string startingToken; string theyAre; string their; if (parent == viewer) { startingToken = "You're"; theyAre = "You're"; their = "Your"; } else { startingToken = "That's"; theyAre = $"{Text.Capitalize(parent.gender.He)} {parent.gender.Is}"; their = Text.Capitalize(parent.gender.His); } MobileComponent mob = (MobileComponent)parent.GetComponent(Text.CompMobile); mainDesc = $"{startingToken} {mainDesc}\n{theyAre} a {mob.race}"; if (viewer == parent) { mainDesc += $". When people look at you, they see:\n{Text.Capitalize(parent.gender.He)} {parent.gender.Is} a {mob.race}"; } if (examinedDescription == null || examinedDescription.Length <= 0) { mainDesc += "."; } else if (examinedDescription[0] == '.' || examinedDescription[0] == '!' || examinedDescription[0] == '?') { mainDesc += examinedDescription; } else { mainDesc += $" {examinedDescription}"; } List <string> clothing = parent.GetVisibleContents(viewer, false); if (clothing.Count > 0) { mainDesc += $"\n{theyAre} carrying:"; foreach (string line in clothing) { mainDesc += $"\n{Text.Capitalize(line)}"; } } else { mainDesc += $"\n{theyAre} completely naked."; } foreach (KeyValuePair <string, GameObject> bp in mob.limbs) { if (bp.Value == null) { mainDesc += $"\n{their} {bp.Key} is missing!"; } else { mainDesc += $"\n{their} {bp.Key} is healthy."; } } } else { mainDesc += $"\n{Colours.Fg(examinedDescription, Colours.BoldBlack)}"; if (parent.contents.Count > 0) { List <string> roomAppearances = parent.GetVisibleContents(viewer, false); if (roomAppearances.Count > 0) { mainDesc = $"{mainDesc}\n{string.Join(" ", roomAppearances.ToArray())}"; } } } if (parent.HasComponent(Text.CompRoom)) { RoomComponent roomComp = (RoomComponent)parent.GetComponent(Text.CompRoom); mainDesc = $"{mainDesc}\n{Colours.Fg(roomComp.GetExitString(), Colours.BoldCyan)}"; } if (parent.HasComponent(Text.CompPhysics)) { PhysicsComponent phys = (PhysicsComponent)parent.GetComponent(Text.CompPhysics); mainDesc = $"{mainDesc}\n{phys.GetExaminedSummary(viewer)}"; } viewer.WriteLine(mainDesc); viewer.SendPrompt(); }