public static IDictionary <char, string> GetAllCraftingStations() { IDictionary <char, string> stations = new Dictionary <char, string> { { 'a', "none" } }; char c = 'b'; foreach (var e in ResourceMasterList.GetAllEntities()) { Logger.Log($"Attempting to check if {e.Name} is craftable with a station"); var station = e.GetTag("craftable.station"); if (station != null) { Logger.Log($"{e.Name} found to be craftable at {station.Value.GetString()}"); if (stations.Values.Contains(station.Value.GetString())) { continue; } stations.Add(c++, station.Value.GetString()); } } return(stations); }
private void GenerateStartingResources() { for (var i = 0; i < 100; i++) { ActiveMap.AddEntity(ResourceMasterList.GetDefaultClone("wood"), new Point(12, 12)); } }
public static IDictionary <char, string> GetAllBuildableEntities() { IDictionary <char, string> buildables = new Dictionary <char, string>(); char c = 'a'; foreach (var e in ResourceMasterList.GetAllEntities()) { var buildable = e.GetTag("buildable"); if (buildable != null) { buildables.Add(c++, e.Name); } } return(buildables); }
private void HandleBuildAction(string selectedObject) { Info = $"Please select where you want to build {selectedObject}"; var buildable = ResourceMasterList.GetDefault(selectedObject).GetTag("buildable"); if (buildable.GetTag("resources") != null) { var resources = buildable.GetTag("resources"); foreach (var r in resources.SubTags) { Info += r.ToString() + '\n'; } } CurrentMenuContext = new Dictionary <char, string>(); State = 1; StoredValue = selectedObject; SetPointAction = FinishBuildAction; }
public static IDictionary <char, string> GetItemsCraftableAt(string stationName) { IDictionary <char, string> items = new Dictionary <char, string>(); char c = 'a'; foreach (var e in ResourceMasterList.GetAllEntities()) { var station = e.GetTag("craftable.station"); if (station != null) { if (station.Value.GetString() == stationName) { items.Add(c++, e.Name); } } } return(items); }
public static Map GenerateMap(Point size) { var m = new Map(size); var r = new Random(); for (var i = r.Next(20) + 5; i >= 0; i--) { var pos = new Point(r.Next(size.X), r.Next(size.Y)); var treeClone = ResourceMasterList.GetDefaultClone("tree"); treeClone.Pos = pos; m.AddEntity(treeClone); } for (var i = r.Next(20) + 5; i >= 0; i--) { var pos = new Point(r.Next(size.X), r.Next(size.Y)); var ironVeinClone = ResourceMasterList.GetDefaultClone("ironvein"); ironVeinClone.Pos = pos; m.AddEntity(ironVeinClone); } for (var i = r.Next(20) + 5; i >= 0; i--) { var pos = new Point(r.Next(size.X), r.Next(size.Y)); var bigstoneClone = ResourceMasterList.GetDefaultClone("bigstone"); bigstoneClone.Pos = pos; m.AddEntity(bigstoneClone); } for (var i = r.Next(20) + 5; i >= 0; i--) { var pos = new Point(r.Next(size.X), r.Next(size.Y)); var coalVeinClone = ResourceMasterList.GetDefaultClone("coalvein"); coalVeinClone.Pos = pos; m.AddEntity(coalVeinClone); } var remaining = 6; var attempts = 0; var mapCenter = new Point(m.Size.X / 2, m.Size.Y / 2); while (remaining > 0) { for (var i = -attempts; i < attempts + 1; i++) { for (var j = -attempts; j < attempts + 1 && remaining != 0; j++) { if (m.Impassables[mapCenter.X + i, mapCenter.Y + j]) { continue; } var pos = new Point(mapCenter.X + i, mapCenter.Y + j); var dwarfClone = ResourceMasterList.GetDefaultClone("dwarf"); if (dwarfClone is Actor) { ((Actor)dwarfClone).Map = m; } dwarfClone.Pos = pos; m.AddEntity(dwarfClone); remaining--; if (remaining == 0) { break; } } } attempts++; } return(m); }
private static Entity BuildFromJSON(IDictionary <string, object> json) { Entity e; var Attributes = (IDictionary <string, object>)json["attributes"]; Logger.Log($"Found base Object in file with subobjects of {string.Join(",", json.Keys)}"); Logger.Log("Found Attributes in file: " + string.Join(", ", Attributes.Keys)); switch (Attributes.TryGetValue("class", out var output) ? output : "") { case "entity": Logger.Log("Found class to be Entity"); e = new Entity(); break; case "actor": Logger.Log("Found class to be Actor"); e = new Actor(); break; default: Logger.Log("Could not find class definition in attributes, using entity as default"); e = new Entity(); break; } if (json.TryGetValue("inheritance", out var inheritanceOut)) { Logger.Log(inheritanceOut.GetType().ToString()); var InheritanceArray = (List <object>)inheritanceOut; Logger.Log($"Entering inheritance with {InheritanceArray.Count} elements"); foreach (var o in InheritanceArray) { var s = (string)o; var defaultE = ResourceMasterList.GetDefault(s); if (defaultE == null) { return(new Entity { Name = "Inheritance Missing" }); } e.Inherit(defaultE); } } if (Attributes["name"] != null) { e.Name = (string)Attributes["name"]; } if (Attributes["ascii"] != null) { e.Ascii = ((string)Attributes["Ascii"])[0]; } if (Attributes["display"] != null) { e.Display = (string)Attributes["display"]; } Enum.TryParse((string)Attributes["backgroundcolor"], true, out ConsoleColor c); e.BackgroundColor = c; Enum.TryParse((string)Attributes["foregroundcolor"], true, out c); e.ForegroundColor = c; // Set up all tags, regardless of their use in fields foreach (var o in json) { Logger.Log($"Trying ParseTag on tag {o.Key}"); e.AddTag(ParseTag(o)); } Logger.Log(e.ToString()); return(e); }
public static void Main() { ResourceMasterList.LoadAllResources(); var game = new GameManager(MapGenerator.GenerateMap(new Point(25, 25)), new Gui()); }