fix: Fixes travel restriction messages (#1263)

- [X] `BaseRegion.CheckTravel` now properly cascades through parent regions
- [X] `SpellHelper.CheckTravel` now returns a failure message instead of sending one internally.
- [X] Consolidates travel restriction messages so they aren't duplicated.
This commit is contained in:
Kamron Batman 2022-11-22 16:57:42 -08:00 • committed by GitHub
parent 2057fe74a2
commit 1d8e8ec0a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 121 additions and 69 deletions

View file

@ -617,42 +617,41 @@ namespace Server.Spells
return false;
}
public static void SendInvalidMessage(Mobile caster, TravelCheckType type)
private static TextDefinition _travelTo = 1019004; // You are not allowed to travel there.
private static TextDefinition _travelFrom = 502361; // You cannot teleport into that area from here.
private static TextDefinition _teleportTo = 501035; // You cannot teleport from here to the destination.
private static TextDefinition _genericSpell = 501802; // Thy spell doth not appear to work...
public static TextDefinition InvalidTravelMessage(TravelCheckType type)
{
if (type is TravelCheckType.RecallTo or TravelCheckType.GateTo)
return type switch
{
caster.SendLocalizedMessage(1019004); // You are not allowed to travel there.
}
else if (type == TravelCheckType.TeleportTo)
{
caster.SendLocalizedMessage(501035); // You cannot teleport from here to the destination.
}
else
{
caster.SendLocalizedMessage(501802); // Thy spell doth not appear to work...
}
TravelCheckType.RecallTo or TravelCheckType.GateTo => _travelTo,
TravelCheckType.RecallFrom or TravelCheckType.TeleportFrom => _travelFrom,
TravelCheckType.TeleportTo => _teleportTo,
_ => _genericSpell
};
}
public static bool CheckTravel(Mobile caster, TravelCheckType type) =>
CheckTravel(caster, caster.Map, caster.Location, type);
public static bool CheckTravel(Mobile caster, TravelCheckType type, out TextDefinition message) =>
CheckTravel(caster, caster.Map, caster.Location, type, out message);
public static bool CheckTravel(Map map, Point3D loc, TravelCheckType type) => CheckTravel(null, map, loc, type);
public static bool CheckTravel(Map map, Point3D loc, TravelCheckType type, out TextDefinition message) =>
CheckTravel(null, map, loc, type, out message);
public static bool CheckTravel(Mobile caster, Map map, Point3D loc, TravelCheckType type)
public static bool CheckTravel(Mobile caster, Map map, Point3D loc, TravelCheckType type, out TextDefinition message)
{
message = null;
if (IsInvalid(map, loc)) // null, internal, out of bounds
{
if (caster != null)
{
SendInvalidMessage(caster, type);
}
message = InvalidTravelMessage(type);
return false;
}
// Always allow monsters to teleport
if (caster is BaseCreature { Controlled: false, Summoned: false } &&
type is TravelCheckType.TeleportTo or TravelCheckType.TeleportFrom)
if (type is TravelCheckType.TeleportTo or TravelCheckType.TeleportFrom &&
caster is BaseCreature { Controlled: false, Summoned: false })
{
return true;
}
@ -668,7 +667,7 @@ namespace Server.Spells
var destination = Region.Find(loc, map) as BaseRegion;
var current = Region.Find(caster.Location, caster.Map) as BaseRegion;
if (destination?.CheckTravel(caster, loc, type) == false || current?.CheckTravel(caster, loc, type) == false)
if (destination?.CheckTravel(caster, loc, type, out message) == false || current?.CheckTravel(caster, loc, type, out message) == false)
{
isValid = false;
}
@ -679,12 +678,7 @@ namespace Server.Spells
isValid = m_Rules[v, i] || !m_Validators[i](map, loc);
}
if (!isValid && caster != null)
{
SendInvalidMessage(caster, type);
}
return isValid;
return !isValid;
}
public static bool IsWindLoc(Point3D loc)