Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travel Restrictions xml settings #1008

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions Distribution/Data/TravelRestrictions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="utf-8"?>
<TravelRestrictions>
<Region Name="FeluccaT2A" Delegate="IsFeluccaT2A">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="Khaldun" Delegate="IsKhaldun">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="Ilshenar" Delegate="IsIlshenar">
<RecallFrom>true</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="TrammelWind" Delegate="IsTrammelWind">
<RecallFrom>true</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="FeluccaWind" Delegate="IsFeluccaWind">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="FeluccaDungeon" Delegate="IsFeluccaDungeon">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="TrammelSolen" Delegate="IsTrammelSolenHive">
<RecallFrom>true</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="FeluccaSolen" Delegate="IsFeluccaSolenHive">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="MalasCrystalCave" Delegate="IsCrystalCave">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>false</TeleportFrom>
<TeleportTo>false</TeleportTo>
</Region>
<Region Name="MalasGauntlet" Delegate="IsDoomGauntlet">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="MalasGauntletFerry" Delegate="IsDoomFerry">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>false</TeleportTo>
</Region>
<Region Name="SafeZone" Delegate="IsSafeZone">
<RecallFrom>true</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>false</TeleportTo>
</Region>
<Region Name="FactionStronghold" Delegate="IsFactionStronghold">
<RecallFrom>true</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>false</TeleportFrom>
<TeleportTo>false</TeleportTo>
</Region>
<Region Name="ChampionSpawn" Delegate="IsChampionSpawn">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="TokunoMalasDungeon" Delegate="IsTokunoDungeon">
<RecallFrom>true</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="DoomLampRoom" Delegate="IsLampRoom">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="DoomGuardianRoom" Delegate="IsGuardianRoom">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>true</TeleportTo>
</Region>
<Region Name="Heartwood" Delegate="IsHeartwood">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>false</TeleportFrom>
<TeleportTo>false</TeleportTo>
</Region>
<Region Name="MLDungeon" Delegate="IsMLDungeon">
<RecallFrom>false</RecallFrom>
<RecallTo>false</RecallTo>
<GateFrom>false</GateFrom>
<GateTo>false</GateTo>
<Mark>false</Mark>
<TeleportFrom>true</TeleportFrom>
<TeleportTo>false</TeleportTo>
</Region>
</TravelRestrictions>
125 changes: 123 additions & 2 deletions Projects/UOContent/Spells/Base/SpellHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using Server.Engines.CannedEvil;
using Server.Engines.ConPVP;
using Server.Engines.PartySystem;
Expand Down Expand Up @@ -80,6 +83,116 @@ public static class SpellHelper
1, 1
};

public static void Configure()
{// Custom Travel Settings. Needs converted to Json in time.
Console.Write("SpellHelper: Loading TravelRestrictions...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to use logger.

if (LoadTravelRestrictions())
Console.WriteLine("done");
else
Console.WriteLine("failed");
}

public static bool LoadTravelRestrictions()
{
string filePath = Path.Combine("Data", "TravelRestrictions.xml");

if (!File.Exists(filePath))
return false;

XmlDocument x = new XmlDocument();
x.Load(filePath);

try
{
XmlElement e = x["TravelRestrictions"];

if (e == null)
return false;

foreach (XmlElement r in e.GetElementsByTagName("Region"))
{
if (!r.HasAttribute("Name"))
{
Console.WriteLine("Warning: Missing 'Name' attribute in TravelRestrictions.xml");
continue;
}

string name = r.GetAttribute("Name");

if (m_TravelRestrictions.ContainsKey(name))
{
Console.WriteLine("Warning: Duplicate name '{0}' in TravelRestrictions.xml", name);
continue;
}

if (!r.HasAttribute("Delegate"))
{
Console.WriteLine("Warning: Missing 'Delegate' attribute in TravelRestrictions.xml");
continue;
}

string d = r.GetAttribute("Delegate");

MethodInfo m = typeof(SpellHelper).GetMethod(d);
if (m == null)
{
Console.WriteLine("Warning: TravelRestrictions.xml Delegate '{0}' not found in SpellHelper", d);
continue;
}

TravelValidator v = (TravelValidator)Delegate.CreateDelegate(typeof(TravelValidator), m);
TravelRules t = new TravelRules();
t.Validator = v;
m_TravelRestrictions[name] = t;

foreach (XmlElement rule in r)
{
switch (rule.Name.ToLower())
{
case "recallfrom": t.RecallFrom = Utility.ToBoolean(rule.InnerText); break;
case "recallto": t.RecallTo = Utility.ToBoolean(rule.InnerText); break;
case "gatefrom": t.GateFrom = Utility.ToBoolean(rule.InnerText); break;
case "gateto": t.GateTo = Utility.ToBoolean(rule.InnerText); break;
case "mark": t.Mark = Utility.ToBoolean(rule.InnerText); break;
case "teleportfrom": t.TeleportFrom = Utility.ToBoolean(rule.InnerText); break;
case "teleportto": t.TeleportTo = Utility.ToBoolean(rule.InnerText); break;
default: Console.WriteLine("Warning: Unknown element '{0}' in TravelRestrictions.xml", rule.Name); break;
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
return false;
}

return true;
}

private struct TravelRules
{
public TravelValidator Validator;

public bool RecallFrom, RecallTo, GateFrom, GateTo, Mark, TeleportFrom, TeleportTo;

public bool Allow(TravelCheckType t) => t switch
{
TravelCheckType.RecallFrom => RecallFrom,
TravelCheckType.RecallTo => RecallTo,
TravelCheckType.GateFrom => GateFrom,
TravelCheckType.GateTo => GateTo,
TravelCheckType.Mark => Mark,
TravelCheckType.TeleportFrom => TeleportFrom,
TravelCheckType.TeleportTo => TeleportTo,
_ => false,
};
}

private static Dictionary<string, TravelRules> m_TravelRestrictions = new Dictionary<string, TravelRules>();

private delegate bool TravelValidator(Map map, Point3D loc);

private static readonly TravelValidator[] m_Validators =
{
IsFeluccaT2A,
Expand Down Expand Up @@ -675,9 +788,17 @@ public static bool CheckTravel(Mobile caster, Map map, Point3D loc, TravelCheckT
}
}

for (var i = 0; isValid && i < m_Validators.Length; ++i)
//for (var i = 0; isValid && i < m_Validators.Length; ++i)
//{
// isValid = m_Rules[v, i] || !m_Validators[i](map, loc);
// }
foreach (KeyValuePair<string, TravelRules> r in m_TravelRestrictions)
{
isValid = m_Rules[v, i] || !m_Validators[i](map, loc);
isValid = r.Value.Allow(type) || !r.Value.Validator(map, loc);
if (!isValid && caster != null)
{
break;
}
}

if (!isValid && caster != null)
Expand Down