public bool Judge(HuskBrain brain, Dictionary <string, long> stats) { switch (Type) { case JudgeType.Flag: return(JudgeFlags(brain.Flags.ToArray(), Gate, Flags)); case JudgeType.Stat: foreach ((string id, LogicMatch logic, long expected) in Matches) { long actual = stats.ContainsKey(id) ? stats[id] : 0; if (!Compare(actual, logic, expected)) { return(false); } } return(true); default: throw new Exception("Invalid JudgeType specified."); } }
public static Map GetMap(string id, HuskBrain brain) { if (!(World.Id == id) && !World.Sectors.Any(x => x.Id == id)) { throw new ArgumentException("The specified ID does not exists for any Sector or World."); } if (!brain.Maps.ContainsKey(id)) { brain.Maps[id] = new byte[] { } } ; Grid <bool> progress = GetMapData(id, brain.Maps[id]); if (World.Id == id) { return(new Map(World.Map, progress)); } if (World.Sectors.Any(x => x.Id == id)) { Sector sector = World.GetSector(id); return(new Map(sector.Map, progress)); } throw new ArgumentException("The specified ID does not exists for any Sector or World."); }
public static bool CanAct(ref Husk husk, HuskBrain brain) { if (husk == null) { return(TryResync(ref husk, brain)); } return(true); }
public bool CanUse(Character npc, Husk husk, HuskBrain brain) { if (Criterion != null) { return(Criterion.Judge.Invoke(npc, husk, brain)); } return(true); }
public static Bitmap DrawMap(string id, HuskBrain brain, GammaPalette palette) { Map map = GetMap(id, brain); var result = new Drawable(map.Source.Width, map.Source.Height); Grid <Color> mask = CreateMapMask(map.Progression, Color.Transparent, GammaPalette.Default[Gamma.Min]); result.Palette = palette; result.AddLayer(new BitmapLayer(ImageHelper.CreateArgbBitmap(mask.Values))); return(result.BuildAndDispose()); }
// gets the best reply for a dialog based on the criteria met for an NPC. // and the current dialog given. public Dialog GetBestReply(Character character, Husk husk, HuskBrain brain, ChatLog log, Dialog dialog) { var bestReplys = GetAvailableReplys(character, husk, brain, log, dialog) .GroupBy(x => x.Criterion?.Priority ?? 0) .OrderByDescending(x => x.Key); if (bestReplys?.Count() > 0) { return(Randomizer.Choose(bestReplys.First())); } return(null); // there isn't a reply. }
public static void Recover(Husk husk, HuskBrain brain, Memorial memorial) { if (!brain.Memorials.Contains(memorial)) { return; } // TODO: create a system that allows you to selectively recover items husk.Backpack = memorial.Backpack; // MemorialHandler.StartAsync(); // You search through your past items. Most are missing, but you can take what you need. // (List out all of the available items, modules, and upgrades here) brain.Memorials.Remove(memorial); }
public static Husk Initialize(HuskBrain brain) { var location = World.Find("area0"); if (location == null) { throw new ArgumentException("The specified initial location ID does not point to a location."); } var husk = new Husk(location.GetLocator()); brain.SetFlag(DesyncFlags.Initialized); return(husk); }
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 bool Judge(Husk husk, HuskBrain brain) { if (brain.HasFlag(UnlockId)) { return(true); } foreach (string flag in RequiredFlags) { if (!brain.HasFlag(flag)) { return(false); } } brain.SetFlag(UnlockId); return(true); }
internal static bool TryResync(ref Husk husk, HuskBrain brain) { if (husk != null) { return(false); } if (!brain.ResyncAt.HasValue) { return(false); } if (DateTime.UtcNow - brain.ResyncAt.Value <= TimeSpan.Zero) { return(false); } husk = new Husk(World.Find("ctr0").GetLocator()); brain.ResyncAt = null; return(true); }
public static TravelResult TryGoTo(Husk husk, HuskBrain brain, string id, out Region attempted) { attempted = null; Location location = husk.Location.GetLocation(); switch (location.Type) { case LocationType.Area: foreach (Construct construct in (location as Area).Constructs) { if (construct.Id == id) { continue; } attempted = construct; if (construct is Market) { if (!(construct as Market).IsActive()) { return(TravelResult.Closed); } } husk.Location.Id = construct.Id; return(TravelResult.Instant); } return(TravelResult.Invalid); case LocationType.Sector: return(TryGoToInSector(husk, brain, id, out attempted)); default: throw new NotImplementedException("Travelling in this location has not been implemented yet"); } }
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); }
// gets a collection of available replies for the player to use based // on the criteria met. // Chat logs store all used dialog IDs already. If CanRepeat is false on the specified ID // it can no longer be referenced. public IEnumerable <Dialog> GetAvailableReplys(Character character, Husk husk, HuskBrain brain, ChatLog log, Dialog dialog) { foreach (string replyId in dialog.ReplyIds) { var reply = GetDialog(replyId); if (reply.Criterion?.Judge.Invoke(character, husk, brain) ?? true) { yield return(reply); } } }
// gets the list of starting dialogs to choose from based on the npc and player. public IEnumerable <Dialog> GetEntryDialogs(Character npc, Husk husk, HuskBrain brain, ChatLog log) { return(Values.Where(x => x.Type == DialogType.Initial)); }
// TODO: This method is meant for BindToRegion, as it will get all visible regions that a husk can currently see. public static IEnumerable <Region> GetVisibleRegions(Husk husk, HuskBrain brain) { throw new NotImplementedException(); }