public static bool TryIdentifyStructure(Husk husk, HuskBrain brain, Structure structure) { if (structure != null) { if (brain.HasDiscoveredRegion(structure.Id)) { return(false); } brain.IdentifyRegion(structure.Id); return(true); } return(false); }
public static string WriteVisibleLocations(Husk husk, HuskBrain brain) { Location location = husk.Location.GetLocation(); var locations = new StringBuilder(); switch (location.Type) { case LocationType.Area: var area = location as Area; locations.AppendLine($"**Available Locations** ({area.Name}):"); if (area.Constructs?.Count > 0) { locations.AppendLine($"**Available Locations** ({area.Name}):"); locations.AppendJoin("\n", area.Constructs.Select(x => $"> `{x.Id}` • {x.Name}")); return(locations.ToString()); } return("There isn't anything close by. Maybe try going to a different area?"); case LocationType.Sector: var sector = location as Sector; var structures = GetVisibleStructures(husk, sector); if (sector.Areas?.Count == 0 && structures?.Count() == 0) { return("There isn't anything close by. Try looking around!"); } if (sector.Areas?.Count > 0) { locations.AppendLine($"**Available Areas** ({sector.Name}):"); locations.AppendJoin("\n", sector.Areas.Select(x => $"> `{x.Id} • {x.Name}`")); } if (structures?.Count() > 0) { locations.AppendLine(); locations.AppendLine($"**Points of Interest**:"); var summaries = structures.Select(x => brain.HasDiscoveredRegion(x.Id) ? $"> `{x.Id}` • {x.Name}" : $"> `({x.Shape.Position.X}, {x.Shape.Position.Y})` • Unknown Structure"); locations.AppendJoin("\n", summaries); } if (brain.Memorials?.Where(x => x.Location.Id == sector.Id).Count() > 0) { locations.Append("\n"); var summaries = brain.Memorials.Select(x => $">` ({x.Location.X}, {x.Location.Y})` • Memorial"); locations.AppendJoin("\n", summaries); } return(locations.ToString()); default: throw new Exception("The specified Husk is currently at an invalid location."); } }
// see if this can be simplified public static TravelResult TryGoToInSector(Husk husk, HuskBrain brain, string id, out Region attempted) { attempted = null; if (husk.Location.GetInnerType() != LocationType.Sector) { throw new ArgumentException("The specified Husk is not within a sector."); } Sector sector = husk.Location.GetLocation() as Sector; if (husk.Destination != null) { if (!husk.Destination.Complete) { throw new ArgumentException("Husk is currently in transit."); } else { UpdateLocation(husk, husk.Destination); } } foreach (Area area in sector.Areas) { if (area.Id == id) { attempted = area; Route route = CreateRoute(husk.Location.X, husk.Location.Y, area.Shape); var now = DateTime.UtcNow; Destination info = new Destination(area.GetLocator(), now, now.Add(route.Time)); // if the travel time is short enough, just instantly go to the location. if (route.GetTime().TotalSeconds <= 1f) { UpdateLocation(husk, info); return(TravelResult.Instant); } husk.Destination = info; return(TravelResult.Start); } } foreach (Structure structure in sector.Structures.Where(x => brain.HasDiscoveredRegion(x.Id))) { if (structure.Id == id) { attempted = structure; Route route = CreateRoute(husk.Location.X, husk.Location.Y, structure.Shape); var now = DateTime.UtcNow; Destination info = new Destination(husk.Location.WorldId, husk.Location.Id, structure.Shape.Midpoint.X, structure.Shape.Midpoint.Y, now, now.Add(route.Time)); // if the travel time is short enough, just instantly go to the location. if (route.GetTime().TotalSeconds <= 1f) { UpdateLocation(husk, info); return(TravelResult.Instant); } husk.Destination = info; return(TravelResult.Start); } } return(TravelResult.Invalid); }