using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace RynthCore.Plugin.RynthNav;
// Where a character's personal recalls land. The client is never told (the server keeps
// a character's lifestone, ties, last portal and house), so RynthNav learns them from what
// it sees: the server's messages ("You have attuned your spirit to this Lifestone.", "X is
// recalling home.") and the teleport that follows, and a teleport right after your own spell
// words (a recall cast by hand: RecallPlanner.GuessHandCast). ACE sends a character neither
// its tie positions (PlayerDescription carries only LastOutsideDeath) nor the tied portals'
// data ids (LinkedPortalOne/Two aren't SendOnLogin and change silently), so a tie made
// before RynthNav was there is learned on the first cast of its recall. Saved per character in
// NavData\recalls.txt. No host calls: the offline tests compile this file.
// (GoArrow kept the same kind of per-character recall list; Digero 2006, Virindi 2011, MIT.)
internal enum RecallSlot
{
/// Where @lifestone (the recall everyone has) lands: the last lifestone you used.
Sanctuary,
/// Where the Lifestone Recall spell lands: the lifestone you cast Lifestone Tie on.
Lifestone,
/// Where Portal Recall lands: the last portal you walked through.
LastPortal,
/// Primary Portal Tie Recall.
Tie1,
/// Secondary Portal Tie Recall.
Tie2,
/// House recall.
House,
/// Allegiance mansion (housing) recall.
Mansion,
/// Allegiance hometown recall.
Hometown,
}
internal sealed class RecallSpot
{
public bool OnMap;
public double Ns, Ew;
public string Label = "";
/// The chat command that does this recall, when it's a command (@lifestone, @house recall).
public string Command = "";
}
/// What a chat line tells RynthNav about recalls.
internal enum RecallEvent
{
None,
/// "You have attuned your spirit to this Lifestone." (used a lifestone: @lifestone lands here).
AttunedLifestone,
/// "You have successfully linked with the life stone." (Lifestone Tie).
LinkedLifestone,
/// "You have successfully linked with the portal." (a Portal Tie; which one isn't said).
LinkedPortal,
/// "Name is recalling to the lifestone." (@lifestone under way).
RecallingLifestone,
/// "Name is recalling home."
RecallingHome,
/// "Name is recalling to the Allegiance housing."
RecallingMansion,
/// "Name is going to the Allegiance hometown."
RecallingHometown,
/// "Name is recalling to the marketplace." (lands in a dungeon: never used for routes).
RecallingMarketplace,
/// "You say, "Zojak Ququ"" on the spellcasting channel: you started casting a spell
/// (a recall cast by hand teleports a few seconds later).
OwnSpellWords,
}
internal sealed class RecallMemory
{
private readonly Dictionary> _byChar = new(StringComparer.OrdinalIgnoreCase);
/// Bumped on every change (the plugin saves when it moves).
public int Version { get; private set; }
public RecallSpot? Get(string charKey, RecallSlot slot) =>
_byChar.TryGetValue(charKey, out var d) && d.TryGetValue(slot, out var s) ? s : null;
public void Set(string charKey, RecallSlot slot, RecallSpot spot)
{
if (!_byChar.TryGetValue(charKey, out var d)) _byChar[charKey] = d = new Dictionary();
d[slot] = spot;
Version++;
}
public void Clear(string charKey, RecallSlot slot)
{
if (_byChar.TryGetValue(charKey, out var d) && d.Remove(slot)) Version++;
}
/// The command for a command recall, as the retail client's own help spells it.
public static string DefaultCommand(RecallSlot slot) => slot switch
{
RecallSlot.Sanctuary => "@lifestone",
RecallSlot.House => "@house recall",
RecallSlot.Mansion => "@house mansion_recall",
RecallSlot.Hometown => "@allegiance hometown",
_ => "",
};
/// The recall a "... is recalling ..." line announces, if any.
public static bool SlotFor(RecallEvent e, out RecallSlot slot)
{
switch (e)
{
case RecallEvent.RecallingLifestone: slot = RecallSlot.Sanctuary; return true;
case RecallEvent.RecallingHome: slot = RecallSlot.House; return true;
case RecallEvent.RecallingMansion: slot = RecallSlot.Mansion; return true;
case RecallEvent.RecallingHometown: slot = RecallSlot.Hometown; return true;
default: slot = RecallSlot.Sanctuary; return false;
}
}
/// ChatMessageType.Spellcasting: the words a caster speaks (yours: "You say, "...").
public const int ChatTypeSpellcasting = 17;
///
/// Reads a chat line (the server's own wording, ACE's Player_Location / Lifestone /
/// WorldObject_Magic). picks out your own "is recalling"
/// lines from other players' nearby. tells your spell words
/// (Spellcasting, 17) from something you typed in local chat (Speech, 2).
///
public static RecallEvent Classify(string? text, string? playerName, int chatType = -1)
{
if (string.IsNullOrEmpty(text)) return RecallEvent.None;
string t = text.Trim();
if (chatType == ChatTypeSpellcasting && t.StartsWith("You say, \"", StringComparison.Ordinal))
return RecallEvent.OwnSpellWords;
if (t.StartsWith("You have attuned your spirit to this Lifestone", StringComparison.OrdinalIgnoreCase))
return RecallEvent.AttunedLifestone;
if (t.StartsWith("You have successfully linked with the life stone", StringComparison.OrdinalIgnoreCase))
return RecallEvent.LinkedLifestone;
if (t.StartsWith("You have successfully linked with the portal", StringComparison.OrdinalIgnoreCase))
return RecallEvent.LinkedPortal;
if (string.IsNullOrEmpty(playerName) || !t.StartsWith(playerName + " ", StringComparison.Ordinal))
return RecallEvent.None;
string rest = t.Substring(playerName.Length + 1);
if (rest.StartsWith("is recalling to the lifestone", StringComparison.OrdinalIgnoreCase)) return RecallEvent.RecallingLifestone;
if (rest.StartsWith("is recalling home", StringComparison.OrdinalIgnoreCase)) return RecallEvent.RecallingHome;
if (rest.StartsWith("is recalling to the Allegiance housing", StringComparison.OrdinalIgnoreCase)) return RecallEvent.RecallingMansion;
if (rest.StartsWith("is going to the Allegiance hometown", StringComparison.OrdinalIgnoreCase)) return RecallEvent.RecallingHometown;
if (rest.StartsWith("is recalling to the marketplace", StringComparison.OrdinalIgnoreCase)) return RecallEvent.RecallingMarketplace;
return RecallEvent.None;
}
// ── recalls.txt ──────────────────────────────────────────────────────────
// # comment
// \t\t\t\t