70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using System.Text.Json;
|
|
|
|
namespace GameServer.World;
|
|
|
|
public sealed class WorldPortalMetadata
|
|
{
|
|
public string PortalType { get; set; } = "";
|
|
public int? TargetRegionId { get; set; }
|
|
public int? TargetZoneX { get; set; }
|
|
public int? TargetZoneY { get; set; }
|
|
public int? TargetZoneZ { get; set; }
|
|
public int? TargetChunkX { get; set; }
|
|
public int? TargetChunkY { get; set; }
|
|
public int? TargetTileX { get; set; }
|
|
public int? TargetTileY { get; set; }
|
|
public int? DungeonTemplateId { get; set; }
|
|
public int? RandomTier { get; set; }
|
|
public int? LevelBracketMin { get; set; }
|
|
public int? LevelBracketMax { get; set; }
|
|
|
|
private static readonly JsonSerializerOptions JsonOpts = new() { PropertyNameCaseInsensitive = true };
|
|
|
|
public static bool TryParse(string metadataJson, out WorldPortalMetadata metadata)
|
|
{
|
|
metadata = new WorldPortalMetadata();
|
|
try
|
|
{
|
|
var parsed = JsonSerializer.Deserialize<WorldPortalMetadata>(metadataJson, JsonOpts);
|
|
if (parsed == null || string.IsNullOrWhiteSpace(parsed.PortalType))
|
|
return false;
|
|
metadata = parsed;
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool TryResolveWorldTarget(
|
|
WorldPortalMetadata m,
|
|
out int targetRegionId,
|
|
out int targetZoneX,
|
|
out int targetZoneY,
|
|
out int targetZoneZ,
|
|
out int targetChunkX,
|
|
out int targetChunkY,
|
|
out int targetTileX,
|
|
out int targetTileY)
|
|
{
|
|
targetRegionId = m.TargetRegionId ?? 0;
|
|
targetZoneX = m.TargetZoneX ?? 0;
|
|
targetZoneY = m.TargetZoneY ?? 0;
|
|
targetZoneZ = m.TargetZoneZ ?? 0;
|
|
targetChunkX = m.TargetChunkX ?? 0;
|
|
targetChunkY = m.TargetChunkY ?? 0;
|
|
targetTileX = m.TargetTileX ?? 0;
|
|
targetTileY = m.TargetTileY ?? 0;
|
|
return targetRegionId > 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns true if this is a building portal (Z-level change within same zone).
|
|
/// Building portals may omit TargetRegionId/ZoneX/ZoneY and only specify TargetZoneZ.
|
|
/// </summary>
|
|
public bool IsBuildingPortal =>
|
|
PortalType.Equals("building", StringComparison.OrdinalIgnoreCase) ||
|
|
PortalType.Equals("building_exit", StringComparison.OrdinalIgnoreCase);
|
|
}
|