59 lines
1.8 KiB
C#
59 lines
1.8 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? 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 targetChunkX,
|
|
out int targetChunkY,
|
|
out int targetTileX,
|
|
out int targetTileY)
|
|
{
|
|
targetRegionId = m.TargetRegionId ?? 0;
|
|
targetZoneX = m.TargetZoneX ?? 0;
|
|
targetZoneY = m.TargetZoneY ?? 0;
|
|
targetChunkX = m.TargetChunkX ?? 0;
|
|
targetChunkY = m.TargetChunkY ?? 0;
|
|
targetTileX = m.TargetTileX ?? 0;
|
|
targetTileY = m.TargetTileY ?? 0;
|
|
return targetRegionId > 0;
|
|
}
|
|
}
|