using System; using System.Collections.Generic; using RynthNav.Routing; namespace RynthCore.Plugin.RynthNav; /// One recall the route planner may use: a spell to cast, or a command to type. internal sealed class RecallOption { public string Name = ""; /// The spell to cast (0 = a command). public int SpellId; /// The command to send (@lifestone, @house recall) when SpellId is 0. public string Command = ""; public double Ns, Ew; public double CastSeconds; /// Learned in game (RecallMemory), not fixed by the world data. public bool Learned; public RecallLink ToLink() => new(Ns, Ew, Name, PortalRoute.RecallCostUnits(CastSeconds)); } /// /// Which recalls this character can use, and where they land: the fixed recall spells /// from the Atlas (only the ones in the character's spellbook), plus the personal ones /// RynthNav has learned (RecallMemory). A recall whose landing isn't known, or is off the /// map (a dungeon), is left out with a note saying why. No host calls: the offline tests /// compile this file. /// internal static class RecallPlanner { public const int PrimaryPortalTieRecall = 48; public const int PrimaryPortalTie = 47; public const int LifestoneRecall = 1635; public const int LifestoneTie = 2644; public const int PortalRecall = 2645; public const int SecondaryPortalTie = 2646; public const int SecondaryPortalTieRecall = 2647; /// A recall spell: the magic stance (and a wand) plus the cast. Estimated. public const double SpellCastSeconds = 5.0; /// @lifestone, @house recall and the like: a long recall animation. Estimated. public const double CommandRecallSeconds = 14.0; /// The character's spellbook; null while it hasn't been read. public static List Build(Atlas atlas, ISet? known, RecallMemory memory, string charKey, List? notes) { var list = new List(); // Fixed-destination recall spells (Aerlinthe Recall, Lyceum Recall, ...). if (known == null) { notes?.Add("Spellbook not read yet: recall spells left out."); } else { var seen = new HashSet(); foreach (AtlasRecall r in atlas.Recalls) { if (!known.Contains(r.SpellId) || !seen.Add(r.SpellId)) continue; if (!r.OnMap) { notes?.Add(r.Name + " lands " + (r.In.Length > 0 ? "in " + r.In : "in a dungeon") + ": not used for routes."); continue; } list.Add(new RecallOption { Name = r.Name, SpellId = r.SpellId, Ns = r.Ns, Ew = r.Ew, CastSeconds = SpellCastSeconds }); } } // Personal recall spells: the landing is the character's own. if (known != null) { AddLearnedSpell(list, notes, known, memory, charKey, LifestoneRecall, "Lifestone Recall", RecallSlot.Lifestone, "cast Lifestone Tie on a lifestone"); AddLearnedSpell(list, notes, known, memory, charKey, PortalRecall, "Portal Recall", RecallSlot.LastPortal, "walk through a portal"); AddLearnedSpell(list, notes, known, memory, charKey, PrimaryPortalTieRecall, "Primary Portal Tie Recall", RecallSlot.Tie1, "cast Primary Portal Tie on a portal"); AddLearnedSpell(list, notes, known, memory, charKey, SecondaryPortalTieRecall, "Secondary Portal Tie Recall", RecallSlot.Tie2, "cast Secondary Portal Tie on a portal"); } // Command recalls (no spell): @lifestone always; house, mansion and hometown // once the character has used them (only then is it known that they have one). AddLearnedCommand(list, notes, memory, charKey, RecallSlot.Sanctuary, "Lifestone (@lifestone)", alwaysAvailable: true, "use a lifestone"); AddLearnedCommand(list, notes, memory, charKey, RecallSlot.House, "House recall", alwaysAvailable: false, ""); AddLearnedCommand(list, notes, memory, charKey, RecallSlot.Mansion, "Allegiance mansion recall", alwaysAvailable: false, ""); AddLearnedCommand(list, notes, memory, charKey, RecallSlot.Hometown, "Allegiance hometown recall", alwaysAvailable: false, ""); return list; } private static void AddLearnedSpell(List list, List? notes, ISet known, RecallMemory memory, string charKey, int spellId, string name, RecallSlot slot, string howToLearn) { if (!known.Contains(spellId)) return; RecallSpot? spot = memory.Get(charKey, slot); if (spot == null) { notes?.Add(name + ": where it lands isn't known yet (" + howToLearn + ")."); return; } if (!spot.OnMap) { notes?.Add(name + " lands " + Where(spot) + ": not used for routes."); return; } list.Add(new RecallOption { Name = name, SpellId = spellId, Ns = spot.Ns, Ew = spot.Ew, CastSeconds = SpellCastSeconds, Learned = true, }); } private static void AddLearnedCommand(List list, List? notes, RecallMemory memory, string charKey, RecallSlot slot, string name, bool alwaysAvailable, string howToLearn) { RecallSpot? spot = memory.Get(charKey, slot); if (spot == null) { if (alwaysAvailable) notes?.Add(name + ": where it lands isn't known yet (" + howToLearn + ")."); return; } if (!spot.OnMap) { notes?.Add(name + " lands " + Where(spot) + ": not used for routes."); return; } list.Add(new RecallOption { Name = name, Command = spot.Command.Length > 0 ? spot.Command : RecallMemory.DefaultCommand(slot), Ns = spot.Ns, Ew = spot.Ew, CastSeconds = CommandRecallSeconds, Learned = true, }); } private static string Where(RecallSpot s) => s.Label.Length > 0 ? "in " + s.Label : "in a dungeon"; public static List Links(List options) { var links = new List(options.Count); foreach (var o in options) links.Add(o.ToLink()); return links; } }