using MultiversalDiplomacy.Model; namespace MultiversalDiplomacy.Script; /// /// A script handler for interacting with a loaded game. /// public class GameScriptHandler : IScriptHandler { public GameScriptHandler(World world) { World = world; } public string Prompt => "5dp> "; public World World { get; set; } public IScriptHandler? HandleInput(string input) { var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (args.Length == 0) { return this; } var command = args[0]; switch (command) { case "help": case "?": Console.WriteLine("commands:"); Console.WriteLine(" adjudicate: adjudicate the current orders"); Console.WriteLine(" assert: assert about the state of the game"); Console.WriteLine(" list: list things in a game category"); Console.WriteLine(" orders: submit order sets"); Console.WriteLine(" status: overview of the state of the game"); break; case "adjudicate": World = GameController.AdjudicateOrders(World); break; case "assert" when args.Length == 1: Console.WriteLine("usage:"); Console.WriteLine(" assert timeline [timeline]@[turn]: timeline exists"); Console.WriteLine(" assert unit [unit spec]: unit exists"); break; case "assert" when args[1] == "timeline": // TODO: raise an error if the timeline doesn't exist Console.WriteLine("WIP"); break; case "assert" when args[1] == "unit": // TODO: raise an error if the unit doesn't exist Console.WriteLine("WIP"); break; case "list" when args.Length == 1: Console.WriteLine("usage:"); Console.WriteLine(" list ordersets: unadjudicated order sets"); Console.WriteLine(" list powers: the powers in the game"); break; case "list" when args[1] == "ordersets": foreach (OrderSet orderSet in World.OrderSets.Where(os => !os.Adjudicated)) { var lines = orderSet.Text.Split('\n'); var firstLine = lines[0].Trim(); Console.WriteLine($" {firstLine} ({lines.Length - 1} orders)"); } break; case "list" when args[1] == "powers": Console.WriteLine("Powers:"); foreach (Power power in World.Powers) { Console.WriteLine($" {power.Name}"); } break; case "orders" when args.Length == 1: Console.WriteLine("usage: orders [power]"); break; case "orders": if (World.Powers.Any(p => p.Name == args[1])) { var handler = new OrderSetScriptHandler(this, World, input); return handler; } Console.WriteLine("Unrecognized power"); break; case "status": foreach (Season season in World.Seasons) { Console.WriteLine($"{season}"); foreach (Unit unit in World.Units.Where(u => u.Season == season)) { Console.WriteLine($" {unit}"); } } break; default: Console.WriteLine("Unrecognized command"); break; } return this; } }