internal static string FormatBlock(Dictionary <string, List <string> > formatLines, int wrapwidth) { string divider = Colours.Fg($"[{new String('=', wrapwidth-3)}]", Colours.Cyan); string emptyLine = $" {sideBar}{new String(' ', wrapwidth-7)}{sideBar}"; string result = ""; foreach (KeyValuePair <string, List <string> > subSection in formatLines) { result += $"\n{divider}"; string[] headerLines = Text.Wrap(subSection.Key, wrapwidth + Text.NestedWrapwidthModifier).Split('\n'); for (int i = 0; i < headerLines.Length; i++) { string headerLine = headerLines[i]; int padNeeded = wrapwidth - (StripColours(headerLine).Length + 7); int padLeft = padNeeded / 2; int padRight = padNeeded - padLeft; result += $"\n {sideBar}{new String(' ', padLeft)}{Colours.Fg(headerLine, Colours.BoldCyan)}{new String(' ', padRight)}{sideBar}"; } result += $"\n{divider}"; result += $"\n{emptyLine}"; foreach (string line in subSection.Value) { string[] subLines = Wrap(line, wrapwidth + Text.NestedWrapwidthModifier).Split("\n"); for (int i = 0; i < subLines.Length; i++) { string subLine = subLines[i]; result += $"\n {sideBar} {Colours.Fg(subLine, Colours.BoldWhite)}{new String(' ', wrapwidth - StripColours(subLine).Length - 10)}{sideBar}"; } } result += $"\n{emptyLine}"; } result += $"\n{divider}"; return(result); }
private void ShowSplashScreen(GameClient viewer) { viewer.SendLine(Text.FormatPopup( "Inspiral, Coalescence, Ringdown", $"{Colours.Fg("- Enter your character name to log in.", Colours.BoldWhite)}\n{Colours.Fg("- Enter ", Colours.BoldWhite)}{Colours.Fg("register [username]", Colours.BoldYellow)}{Colours.Fg(" to register a new account.", Colours.BoldWhite)}", viewer.config.wrapwidth )); }
internal override string GetPrompt() { string p = ""; foreach (KeyValuePair <string, Timer> bal in offBalanceTimers) { p += bal.Value.Enabled ? '-' : bal.Key[0]; } return($"{Colours.Fg("[", Colours.Yellow)}{Colours.Fg(p, Colours.BoldWhite)}{Colours.Fg("]", Colours.Yellow)}"); }
internal static string FormatPopup(string header, string boxContents, int wrapwidth) { string useHeader = Wrap(header, wrapwidth - 14).Split('\n')[0]; int padNeeded = wrapwidth - (StripColours(useHeader).Length + 7); string result = $"{Colours.Fg($"[{new String('=', padNeeded/2)}\\", Colours.Cyan)} {Colours.Fg(useHeader, Colours.BoldCyan)} {Colours.Fg($"/{new String('=', padNeeded-(padNeeded/2))}]",Colours.Cyan)}"; string emptyLine = $" {sideBar}{new String(' ', wrapwidth-7)}{sideBar}"; result += $"\n{emptyLine}"; string[] useContents = Wrap(boxContents, wrapwidth - 10).Split('\n'); for (int i = 0; i < useContents.Length; i++) { string useLine = useContents[i]; result += $"\n {sideBar} {Colours.Fg(useLine, Colours.BoldWhite)}{new String(' ', wrapwidth - StripColours(useLine).Length - 9)}{sideBar}"; } result += $"\n{emptyLine}"; result += $"\n{Colours.Fg($"[{new String('=', wrapwidth-3)}]", Colours.Cyan)}"; return(result); }
internal override string GetPrompt(GameClient viewer) { string p = ""; foreach (KeyValuePair <string, GameComponent> comp in viewer.shell.components) { string addP = comp.Value.GetPrompt(); if (addP != null && addP != "") { p += $" {addP}"; } } p = p.Trim(); string final = Colours.Fg("> ", Colours.Yellow); if (p == null || p == "" || p == viewer.lastPrompt) { return(final); } viewer.lastPrompt = p; return($"{p}{final}"); }
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(); }
internal override string GetPrompt() { return($"{Colours.Fg("Pain:",Colours.Yellow)}{Colours.Fg("0%",Colours.BoldYellow)} {Colours.Fg("Bleed:",Colours.Red)}{Colours.Fg("0%",Colours.BoldRed)}"); }
internal override bool TakeInput(GameClient invoker, string command, string rawCommand, string arguments) { if (command == "register") { string[] tokens = arguments.Split(" "); if (tokens.Length < 1) { invoker.WriteLine($"Please supply a desired username when registering."); } else { string newUser = tokens[0].ToLower(); if (Game.Accounts.GetAccountByUser(newUser) != null) { invoker.WriteLine($"An account already exists with that username."); } else if (!ValidateUsername(newUser)) { invoker.WriteLine($"Usernames must be 2 to 16 characters long and can only contain letters."); } else { invoker.id = newUser; loginState.Remove(invoker); loginState.Add(invoker, "registering_entering_password"); invoker.WriteLine("Enter a new password of at least 6 characters, including at least one number or symbol. Remember that Telnet is not secure; do not reuse an important personal password."); } } } else { switch (loginState[invoker]) { case "connected": PlayerAccount acct = Game.Accounts.GetAccountByUser(command); if (acct == null) { invoker.WriteLine($"No account exists for '{command}'. Use {Colours.Fg("register [username]", Colours.BoldWhite)} to create one."); } else { invoker.account = acct; invoker.WriteLine("Enter your password."); loginState.Remove(invoker); loginState.Add(invoker, "entering_password"); } break; case "entering_password": bool correctPass = invoker.account.CheckPassword(rawCommand); if (correctPass) { invoker.WriteLine("Password correct."); HandleLogin(invoker); } else { invoker.WriteLine("Incorrect password."); invoker.account = null; loginState.Remove(invoker); loginState.Add(invoker, "connected"); ShowSplashScreen(invoker); } break; case "registering_entering_password": if (!ValidatePassword(rawCommand)) { invoker.WriteLine($"Passwords must be 6 to 30 characters long and must contain at least one symbol or number."); } else { passwordConfirmations.Remove(invoker); passwordConfirmations.Add(invoker, rawCommand); loginState.Remove(invoker); loginState.Add(invoker, "registering_confirming_password"); invoker.WriteLine("Please reenter your password to confirm."); } break; case "registering_confirming_password": if (passwordConfirmations.ContainsKey(invoker) && passwordConfirmations[invoker] == rawCommand) { invoker.account = Game.Accounts.CreateAccount(invoker.id, BCrypt.Net.BCrypt.HashPassword(passwordConfirmations[invoker], 10)); invoker.WriteLine("Account created."); HandleLogin(invoker); } else { invoker.WriteLine("Passwords do not match."); passwordConfirmations.Remove(invoker); loginState.Remove(invoker); loginState.Add(invoker, "connected"); ShowSplashScreen(invoker); } break; } } invoker.SendPrompt(); return(true); }