Add world portal editing/runtime handling and include tileSheets in WORLD_SPAWN
This commit is contained in:
+186
-1
@@ -19,12 +19,14 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
private const float MoveWalk = 120f;
|
||||
private const float MoveRun = 180f;
|
||||
private const float StepSec = 0.05f;
|
||||
private const long PortalCooldownTicks = 8; // 0.8s at 10hz
|
||||
|
||||
private readonly ILogger<WorldHandler> _log;
|
||||
private readonly ISessionRegistry _sessions;
|
||||
private readonly IMessageSerializer _ser;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly ConcurrentDictionary<Guid, SessionState> _players = new();
|
||||
private readonly ConcurrentDictionary<ulong, long> _portalCooldownByCharacter = new();
|
||||
private readonly JsonSerializerOptions _json = new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
private Task? _tickTask;
|
||||
@@ -161,11 +163,28 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
var initial = await ChunkUpdatesAsync(db, region, s, ct);
|
||||
var tileSheets = await db.TileMapSheets
|
||||
.AsNoTracking()
|
||||
.Where(ts => ts.IsEnabled)
|
||||
.OrderBy(ts => ts.Id)
|
||||
.Select(ts => new
|
||||
{
|
||||
id = ts.Id,
|
||||
name = ts.Name,
|
||||
path = ts.CdnPath,
|
||||
tileW = ts.TileWidth,
|
||||
tileH = ts.TileHeight,
|
||||
cols = ts.Columns,
|
||||
sheetW = ts.SheetWidth,
|
||||
sheetH = ts.SheetHeight
|
||||
})
|
||||
.ToArrayAsync(ct);
|
||||
await SendAsync(conn, OpCodes.WORLD_SPAWN, new
|
||||
{
|
||||
success = true,
|
||||
player = new { id = s.CharacterId, name = s.Name, x = s.X, y = s.Y, regionId = s.RegionId, zoneX = s.ZoneX, zoneY = s.ZoneY, chunkX = s.ChunkX, chunkY = s.ChunkY, isVip = s.IsVip },
|
||||
region = new { id = region.Id, name = region.Name, zonesX = region.ZonesPerRegionX, zonesY = region.ZonesPerRegionY, chunksPerZoneX = region.ChunksPerZoneX, chunksPerZoneY = region.ChunksPerZoneY, chunkWidthTiles = region.ChunkWidthTiles, chunkHeightTiles = region.ChunkHeightTiles },
|
||||
tileSheets,
|
||||
initialChunks = initial.Where(u => u.type == "chunk_full").Select(u => u.payload),
|
||||
nearbyPlayers = VisiblePlayers(s).Select(p => new { id = p.CharacterId, name = p.Name, x = p.X, y = p.Y, facing = p.Facing, speed = p.Speed, isMoving = p.IsMoving })
|
||||
}, ct);
|
||||
@@ -206,6 +225,7 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
s.ZoneX = zx; s.ZoneY = zy; s.ChunkX = cx; s.ChunkY = cy;
|
||||
s.VelX = dx * speed; s.VelY = dy * speed; s.Speed = speed; s.IsMoving = MathF.Abs(dx) > 0.001f || MathF.Abs(dy) > 0.001f;
|
||||
s.Facing = Facing(req.Facing, dx, dy, s.Facing); s.Seq = req.Seq;
|
||||
await TryTriggerPortalAsync(db, region, s, ct);
|
||||
}
|
||||
|
||||
private async Task TickLoopAsync(CancellationToken ct)
|
||||
@@ -245,8 +265,10 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
self = new { x = s.X, y = s.Y, velocityX = s.VelX, velocityY = s.VelY, regionId = s.RegionId, zoneX = s.ZoneX, zoneY = s.ZoneY, chunkX = s.ChunkX, chunkY = s.ChunkY },
|
||||
players = VisiblePlayers(s).Select(p => new { id = p.CharacterId, name = p.Name, x = p.X, y = p.Y, facing = p.Facing, speed = p.Speed, isMoving = p.IsMoving, regionId = p.RegionId, zoneX = p.ZoneX, zoneY = p.ZoneY, chunkX = p.ChunkX, chunkY = p.ChunkY }),
|
||||
chunkUpdates = updates.Select(u => u.payload),
|
||||
portalEvent = s.PendingPortalEvent,
|
||||
errors = errs
|
||||
}, ct);
|
||||
s.PendingPortalEvent = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +313,7 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
return (0, new { regionId = region.Id, zoneX, zoneY, chunkX, chunkY, version = 0, width = region.ChunkWidthTiles, height = region.ChunkHeightTiles }, Array.Empty<object>(), Array.Empty<object>(), Array.Empty<object>(), Array.Empty<object>());
|
||||
|
||||
var tiles = await db.WorldChunkTiles.AsNoTracking().Where(t => t.WorldChunkId == chunk.Id).OrderBy(t => t.TileY).ThenBy(t => t.TileX).Select(t => new { id = t.Id, x = t.TileX, y = t.TileY, sheetId = t.SheetId, frameIndex = t.FrameIndex, isWalkable = t.IsWalkable, isInvisiblePaywall = t.IsInvisiblePaywall }).ToArrayAsync(ct);
|
||||
var objects = await db.WorldChunkObjects.AsNoTracking().Include(o => o.ObjectDefinition).Where(o => o.WorldChunkId == chunk.Id).OrderBy(o => o.TileY).ThenBy(o => o.TileX).Select(o => new { id = o.Id, x = o.TileX, y = o.TileY, objectDefinitionId = o.ObjectDefinitionId, objectName = o.ObjectDefinition != null ? o.ObjectDefinition.Name : $"Object {o.ObjectDefinitionId}", rotation = o.Rotation, metadataJson = o.MetadataJson }).ToArrayAsync(ct);
|
||||
var objects = await db.WorldChunkObjects.AsNoTracking().Include(o => o.ObjectDefinition).Where(o => o.WorldChunkId == chunk.Id).OrderBy(o => o.TileY).ThenBy(o => o.TileX).Select(o => new { id = o.Id, x = o.TileX, y = o.TileY, objectDefinitionId = o.ObjectDefinitionId, objectName = o.ObjectDefinition != null ? o.ObjectDefinition.Name : $"Object {o.ObjectDefinitionId}", interactionType = o.ObjectDefinition != null ? o.ObjectDefinition.InteractionType.ToString() : null, rotation = o.Rotation, metadataJson = o.MetadataJson }).ToArrayAsync(ct);
|
||||
var npcs = await db.WorldChunkNpcSpawns.AsNoTracking().Include(n => n.NpcDefinition).Where(n => n.WorldChunkId == chunk.Id).OrderBy(n => n.TileY).ThenBy(n => n.TileX).Select(n => new { id = n.Id, x = n.TileX, y = n.TileY, npcDefinitionId = n.NpcDefinitionId, npcName = n.NpcDefinition != null ? n.NpcDefinition.Name : $"NPC {n.NpcDefinitionId}", rotation = n.Rotation, metadataJson = n.MetadataJson }).ToArrayAsync(ct);
|
||||
var mobs = await db.WorldChunkMobSpawns.AsNoTracking().Include(m => m.MobDefinition).Where(m => m.WorldChunkId == chunk.Id).OrderBy(m => m.TileY).ThenBy(m => m.TileX).Select(m => new { id = m.Id, x = m.TileX, y = m.TileY, mobDefinitionId = m.MobDefinitionId, mobName = m.MobDefinition != null ? m.MobDefinition.Name : $"Mob {m.MobDefinitionId}", rotation = m.Rotation, spawnCount = m.SpawnCount, respawnSeconds = m.RespawnSeconds, metadataJson = m.MetadataJson }).ToArrayAsync(ct);
|
||||
return (chunk.Version, new { id = chunk.Id, regionId = region.Id, zoneX, zoneY, chunkX, chunkY, version = chunk.Version, width = region.ChunkWidthTiles, height = region.ChunkHeightTiles }, tiles.Cast<object>().ToArray(), objects.Cast<object>().ToArray(), npcs.Cast<object>().ToArray(), mobs.Cast<object>().ToArray());
|
||||
@@ -310,6 +332,152 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task TryTriggerPortalAsync(GameDbContext db, WorldRegion region, SessionState s, CancellationToken ct)
|
||||
{
|
||||
var nowTick = Interlocked.Read(ref _tick);
|
||||
if (_portalCooldownByCharacter.TryGetValue(s.CharacterId, out var untilTick) && untilTick > nowTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var portalObject = await ResolvePortalObjectAtPositionAsync(db, region, s.X, s.Y, ct);
|
||||
if (portalObject == null || string.IsNullOrWhiteSpace(portalObject.MetadataJson))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryParsePortalMetadata(portalObject.MetadataJson, out var portalMeta))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_portalCooldownByCharacter[s.CharacterId] = nowTick + PortalCooldownTicks;
|
||||
|
||||
if (portalMeta.PortalType.Equals("world", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (TryResolveWorldPortalTarget(portalMeta, out var targetRegionId, out var targetZoneX, out var targetZoneY, out var targetChunkX, out var targetChunkY, out var targetTileX, out var targetTileY))
|
||||
{
|
||||
var targetRegion = await db.WorldRegions.AsNoTracking().FirstOrDefaultAsync(r => r.Id == targetRegionId && r.IsEnabled, ct);
|
||||
if (targetRegion != null)
|
||||
{
|
||||
var nx = WorldPxX(targetRegion, targetZoneX, targetChunkX, targetTileX);
|
||||
var ny = WorldPxY(targetRegion, targetZoneY, targetChunkY, targetTileY);
|
||||
s.RegionId = targetRegion.Id;
|
||||
s.X = nx;
|
||||
s.Y = ny;
|
||||
var (zx, zy, cx, cy) = ToChunkPos(targetRegion, s.X, s.Y);
|
||||
s.ZoneX = zx; s.ZoneY = zy; s.ChunkX = cx; s.ChunkY = cy;
|
||||
s.PendingPortalEvent = new
|
||||
{
|
||||
type = "world_teleport",
|
||||
sourceObjectId = portalObject.Id,
|
||||
regionId = s.RegionId,
|
||||
zoneX = s.ZoneX,
|
||||
zoneY = s.ZoneY,
|
||||
chunkX = s.ChunkX,
|
||||
chunkY = s.ChunkY,
|
||||
x = s.X,
|
||||
y = s.Y
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
s.Errors.Add("portal_world_target_invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
s.PendingPortalEvent = new
|
||||
{
|
||||
type = "dungeon_request",
|
||||
sourceObjectId = portalObject.Id,
|
||||
portalType = portalMeta.PortalType,
|
||||
dungeonTemplateId = portalMeta.DungeonTemplateId,
|
||||
randomTier = portalMeta.RandomTier,
|
||||
levelBracketMin = portalMeta.LevelBracketMin,
|
||||
levelBracketMax = portalMeta.LevelBracketMax
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<WorldChunkObject?> ResolvePortalObjectAtPositionAsync(GameDbContext db, WorldRegion region, float wx, float wy, CancellationToken ct)
|
||||
{
|
||||
var gx = (int)MathF.Floor(wx / TileSize);
|
||||
var gy = (int)MathF.Floor(wy / TileSize);
|
||||
if (gx < 0 || gy < 0) return null;
|
||||
var zoneW = region.ChunksPerZoneX * region.ChunkWidthTiles;
|
||||
var zoneH = region.ChunksPerZoneY * region.ChunkHeightTiles;
|
||||
if (zoneW <= 0 || zoneH <= 0) return null;
|
||||
var zx = gx / zoneW;
|
||||
var zy = gy / zoneH;
|
||||
if (zx < 0 || zy < 0 || zx >= region.ZonesPerRegionX || zy >= region.ZonesPerRegionY) return null;
|
||||
var lzx = gx - (zx * zoneW);
|
||||
var lzy = gy - (zy * zoneH);
|
||||
var cx = lzx / region.ChunkWidthTiles;
|
||||
var cy = lzy / region.ChunkHeightTiles;
|
||||
var tx = lzx % region.ChunkWidthTiles;
|
||||
var ty = lzy % region.ChunkHeightTiles;
|
||||
|
||||
var zone = await db.WorldZones.AsNoTracking().FirstOrDefaultAsync(z => z.RegionId == region.Id && z.ZoneX == zx && z.ZoneY == zy && z.IsEnabled, ct);
|
||||
if (zone == null) return null;
|
||||
var chunk = await db.WorldChunks.AsNoTracking().FirstOrDefaultAsync(c => c.WorldZoneId == zone.Id && c.ChunkX == cx && c.ChunkY == cy, ct);
|
||||
if (chunk == null) return null;
|
||||
|
||||
var objects = await db.WorldChunkObjects
|
||||
.AsNoTracking()
|
||||
.Include(o => o.ObjectDefinition)
|
||||
.Where(o => o.WorldChunkId == chunk.Id)
|
||||
.ToListAsync(ct);
|
||||
|
||||
return objects.FirstOrDefault(o =>
|
||||
{
|
||||
var w = Math.Max(1, o.ObjectDefinition?.Width ?? 1);
|
||||
var h = Math.Max(1, o.ObjectDefinition?.Height ?? 1);
|
||||
var isTeleport = o.ObjectDefinition?.InteractionType == ObjectInteractionType.Teleport ||
|
||||
(o.MetadataJson?.Contains("portalType", StringComparison.OrdinalIgnoreCase) ?? false);
|
||||
if (!isTeleport) return false;
|
||||
return tx >= o.TileX && ty >= o.TileY && tx < (o.TileX + w) && ty < (o.TileY + h);
|
||||
});
|
||||
}
|
||||
|
||||
private static bool TryParsePortalMetadata(string metadataJson, out WorldPortalMetadata metadata)
|
||||
{
|
||||
metadata = new WorldPortalMetadata();
|
||||
try
|
||||
{
|
||||
var parsed = JsonSerializer.Deserialize<WorldPortalMetadata>(metadataJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
if (parsed == null || string.IsNullOrWhiteSpace(parsed.PortalType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
metadata = parsed;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryResolveWorldPortalTarget(
|
||||
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;
|
||||
}
|
||||
|
||||
private async Task<WorldChunkTile?> ResolveTileAsync(GameDbContext db, WorldRegion region, float wx, float wy, CancellationToken ct)
|
||||
{
|
||||
var gx = (int)MathF.Floor(wx / TileSize);
|
||||
@@ -491,6 +659,7 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
public uint Seq { get; set; }
|
||||
public Dictionary<string, long> ChunkVersions { get; } = new(StringComparer.Ordinal);
|
||||
public List<string> Errors { get; } = new();
|
||||
public object? PendingPortalEvent { get; set; }
|
||||
}
|
||||
|
||||
private sealed class SpawnReq
|
||||
@@ -519,4 +688,20 @@ public sealed class WorldHandler : IClientMessageHandler
|
||||
public bool IsRunning { get; set; }
|
||||
public string? Facing { get; set; }
|
||||
}
|
||||
|
||||
private 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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
sheetH = s.SheetHeight
|
||||
}));
|
||||
|
||||
var objectsJson = JsonSerializer.Serialize(Model.ObjectDefinitions.Select(o => new { id = o.Id, name = o.Name }));
|
||||
var objectsJson = JsonSerializer.Serialize(Model.ObjectDefinitions.Select(o => new { id = o.Id, name = o.Name, interactionType = o.InteractionType.ToString() }));
|
||||
var npcsJson = JsonSerializer.Serialize(Model.NpcDefinitions.Select(n => new { id = n.Id, name = n.Name }));
|
||||
var mobsJson = JsonSerializer.Serialize(Model.MobDefinitions.Select(m => new { id = m.Id, name = m.Name }));
|
||||
var tileDefsJson = JsonSerializer.Serialize(Model.TileDefinitions.Select(t => new
|
||||
@@ -132,6 +132,7 @@
|
||||
<select id="paintMode" class="input" onchange="renderChunk()">
|
||||
<option value="tile">Tile</option>
|
||||
<option value="object">Object</option>
|
||||
<option value="portal">Portal</option>
|
||||
<option value="npc">NPC</option>
|
||||
<option value="mob">Mob</option>
|
||||
<option value="erase">Erase</option>
|
||||
@@ -184,6 +185,35 @@
|
||||
<select id="objectDefinitionId" class="input"></select>
|
||||
</div>
|
||||
|
||||
<div class="card p-4 space-y-3">
|
||||
<h2 class="text-lg font-semibold text-white">Portal Tool</h2>
|
||||
<label class="label">Portal Object</label>
|
||||
<select id="portalObjectDefinitionId" class="input"></select>
|
||||
<label class="label">Destination Type</label>
|
||||
<select id="portalDestinationType" class="input" onchange="onPortalDestinationTypeChanged()">
|
||||
<option value="world">World Coords</option>
|
||||
<option value="dungeon_random">Random Dungeon</option>
|
||||
<option value="dungeon_specific">Specific Dungeon</option>
|
||||
</select>
|
||||
<div id="portalWorldCoords" class="grid grid-cols-2 gap-2">
|
||||
<div><label class="label">Target Region</label><input id="portalTargetRegionId" type="number" class="input" min="1" value="@Model.SelectedRegionId" /></div>
|
||||
<div><label class="label">Target Zone X</label><input id="portalTargetZoneX" type="number" class="input" min="0" value="@Model.SelectedZoneX" /></div>
|
||||
<div><label class="label">Target Zone Y</label><input id="portalTargetZoneY" type="number" class="input" min="0" value="@Model.SelectedZoneY" /></div>
|
||||
<div><label class="label">Target Chunk X</label><input id="portalTargetChunkX" type="number" class="input" min="0" value="@Model.SelectedChunkX" /></div>
|
||||
<div><label class="label">Target Chunk Y</label><input id="portalTargetChunkY" type="number" class="input" min="0" value="@Model.SelectedChunkY" /></div>
|
||||
<div><label class="label">Target Tile X</label><input id="portalTargetTileX" type="number" class="input" min="0" value="0" /></div>
|
||||
<div><label class="label">Target Tile Y</label><input id="portalTargetTileY" type="number" class="input" min="0" value="0" /></div>
|
||||
</div>
|
||||
<div id="portalDungeonRandom" class="grid grid-cols-2 gap-2 hidden">
|
||||
<div><label class="label">Tier</label><input id="portalRandomTier" type="number" class="input" min="1" value="1" /></div>
|
||||
<div><label class="label">Bracket Min</label><input id="portalBracketMin" type="number" class="input" min="1" value="1" /></div>
|
||||
<div><label class="label">Bracket Max</label><input id="portalBracketMax" type="number" class="input" min="1" value="10" /></div>
|
||||
</div>
|
||||
<div id="portalDungeonSpecific" class="grid grid-cols-1 gap-2 hidden">
|
||||
<div><label class="label">Dungeon Template Id</label><input id="portalDungeonTemplateId" type="number" class="input" min="1" value="1" /></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4 space-y-3">
|
||||
<h2 class="text-lg font-semibold text-white">NPC Tool</h2>
|
||||
<label class="label">NPC</label>
|
||||
@@ -293,8 +323,11 @@
|
||||
onSheetChanged();
|
||||
|
||||
document.getElementById('objectDefinitionId').innerHTML = objectDefs.map(o => `<option value="${o.id}">${o.name}</option>`).join('');
|
||||
const portalDefs = objectDefs.filter(o => (o.interactionType || '').toLowerCase() === 'teleport');
|
||||
document.getElementById('portalObjectDefinitionId').innerHTML = (portalDefs.length ? portalDefs : objectDefs).map(o => `<option value="${o.id}">${o.name}</option>`).join('');
|
||||
document.getElementById('npcDefinitionId').innerHTML = npcDefs.map(n => `<option value="${n.id}">${n.name}</option>`).join('');
|
||||
document.getElementById('mobDefinitionId').innerHTML = mobDefs.map(m => `<option value="${m.id}">${m.name}</option>`).join('');
|
||||
onPortalDestinationTypeChanged();
|
||||
}
|
||||
|
||||
function refreshRegionSelect(selectedId) {
|
||||
@@ -572,7 +605,8 @@
|
||||
for (const o of currentObjects) {
|
||||
const px = o.x * tileSize + tileSize / 2;
|
||||
const py = o.y * tileSize + tileSize / 2;
|
||||
chunkCtx.fillStyle = '#f59e0b';
|
||||
const isPortal = (o.interactionType || '').toLowerCase() === 'teleport' || (o.metadataJson || '').includes('portalType');
|
||||
chunkCtx.fillStyle = isPortal ? '#a855f7' : '#f59e0b';
|
||||
chunkCtx.beginPath();
|
||||
chunkCtx.arc(px, py, Math.max(2, tileSize * 0.25), 0, Math.PI * 2);
|
||||
chunkCtx.fill();
|
||||
@@ -601,6 +635,41 @@
|
||||
document.getElementById('eraseTargetWrap').classList.toggle('hidden', mode !== 'erase');
|
||||
}
|
||||
|
||||
function onPortalDestinationTypeChanged() {
|
||||
const mode = document.getElementById('portalDestinationType').value;
|
||||
document.getElementById('portalWorldCoords').classList.toggle('hidden', mode !== 'world');
|
||||
document.getElementById('portalDungeonRandom').classList.toggle('hidden', mode !== 'dungeon_random');
|
||||
document.getElementById('portalDungeonSpecific').classList.toggle('hidden', mode !== 'dungeon_specific');
|
||||
}
|
||||
|
||||
function buildPortalMetadata() {
|
||||
const destinationType = document.getElementById('portalDestinationType').value;
|
||||
if (destinationType === 'world') {
|
||||
return JSON.stringify({
|
||||
portalType: 'world',
|
||||
targetRegionId: parseInt(document.getElementById('portalTargetRegionId').value, 10) || 1,
|
||||
targetZoneX: parseInt(document.getElementById('portalTargetZoneX').value, 10) || 0,
|
||||
targetZoneY: parseInt(document.getElementById('portalTargetZoneY').value, 10) || 0,
|
||||
targetChunkX: parseInt(document.getElementById('portalTargetChunkX').value, 10) || 0,
|
||||
targetChunkY: parseInt(document.getElementById('portalTargetChunkY').value, 10) || 0,
|
||||
targetTileX: parseInt(document.getElementById('portalTargetTileX').value, 10) || 0,
|
||||
targetTileY: parseInt(document.getElementById('portalTargetTileY').value, 10) || 0
|
||||
});
|
||||
}
|
||||
if (destinationType === 'dungeon_random') {
|
||||
return JSON.stringify({
|
||||
portalType: 'dungeon_random',
|
||||
randomTier: parseInt(document.getElementById('portalRandomTier').value, 10) || 1,
|
||||
levelBracketMin: parseInt(document.getElementById('portalBracketMin').value, 10) || 1,
|
||||
levelBracketMax: parseInt(document.getElementById('portalBracketMax').value, 10) || 10
|
||||
});
|
||||
}
|
||||
return JSON.stringify({
|
||||
portalType: 'dungeon_specific',
|
||||
dungeonTemplateId: parseInt(document.getElementById('portalDungeonTemplateId').value, 10) || 1
|
||||
});
|
||||
}
|
||||
|
||||
function canvasTile(e) {
|
||||
if (!currentChunk) return null;
|
||||
const rect = chunkCanvas.getBoundingClientRect();
|
||||
@@ -663,6 +732,23 @@
|
||||
if (idx >= 0) currentObjects[idx] = { ...currentObjects[idx], ...data.op };
|
||||
else currentObjects.push(data.op);
|
||||
}
|
||||
} else if (mode === 'portal') {
|
||||
const objectDefinitionId = parseInt(document.getElementById('portalObjectDefinitionId').value, 10) || 0;
|
||||
const metadataJson = buildPortalMetadata();
|
||||
const data = await postJson('/admin/worldeditor?handler=UpsertObject', {
|
||||
...s,
|
||||
objectDefinitionId,
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
rotation: 0,
|
||||
metadataJson
|
||||
});
|
||||
if (data.success) {
|
||||
currentChunk.version = data.chunkVersion;
|
||||
const idx = currentObjects.findIndex(o => o.id === data.op.id);
|
||||
if (idx >= 0) currentObjects[idx] = { ...currentObjects[idx], ...data.op };
|
||||
else currentObjects.push(data.op);
|
||||
}
|
||||
} else if (mode === 'npc') {
|
||||
const npcDefinitionId = parseInt(document.getElementById('npcDefinitionId').value, 10) || 0;
|
||||
const data = await postJson('/admin/worldeditor?handler=UpsertNpc', {
|
||||
|
||||
@@ -267,6 +267,7 @@ public class IndexModel : AdminPageModel
|
||||
y = o.TileY,
|
||||
objectDefinitionId = o.ObjectDefinitionId,
|
||||
objectName = o.ObjectDefinition != null ? o.ObjectDefinition.Name : $"Object {o.ObjectDefinitionId}",
|
||||
interactionType = o.ObjectDefinition != null ? o.ObjectDefinition.InteractionType.ToString() : null,
|
||||
rotation = o.Rotation,
|
||||
metadataJson = o.MetadataJson
|
||||
})
|
||||
@@ -608,6 +609,7 @@ public class IndexModel : AdminPageModel
|
||||
y = obj.TileY,
|
||||
objectDefinitionId = obj.ObjectDefinitionId,
|
||||
objectName = objectDef.Name,
|
||||
interactionType = objectDef.InteractionType.ToString(),
|
||||
rotation = obj.Rotation,
|
||||
metadataJson = obj.MetadataJson
|
||||
};
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
- `op`:
|
||||
- `tile_upsert`: `{ x, y, sheetId, frameIndex, isWalkable, isInvisiblePaywall }`
|
||||
- `tile_remove`: `{ x, y }`
|
||||
- `object_upsert`: `{ id, x, y, objectDefinitionId, objectName, rotation, metadataJson }`
|
||||
- `object_upsert`: `{ id, x, y, objectDefinitionId, objectName, interactionType, rotation, metadataJson }`
|
||||
- `object_remove`: `{ id }`
|
||||
- `npc_upsert`: `{ id, x, y, npcDefinitionId, npcName, rotation, metadataJson }`
|
||||
- `npc_remove`: `{ id }`
|
||||
@@ -168,6 +168,7 @@
|
||||
- `success`
|
||||
- `player`: `{ id, name, x, y, regionId, zoneX, zoneY, chunkX, chunkY, isVip }`
|
||||
- `region`: `{ id, name, zonesX, zonesY, chunksPerZoneX, chunksPerZoneY, chunkWidthTiles, chunkHeightTiles }`
|
||||
- `tileSheets[]`: `{ id, name, path, tileW, tileH, cols, sheetW, sheetH }`
|
||||
- `initialChunks[]`: subset of `chunkUpdates` entries where `type = "chunk_full"`:
|
||||
- `{ type: "chunk_full", chunk, tiles[], objects[], npcs[], mobs[] }`
|
||||
- `nearbyPlayers[]`: `{ id, name, x, y, facing, speed, isMoving }`
|
||||
@@ -180,7 +181,11 @@
|
||||
- `players[]`: `{ id, name, x, y, facing, speed, isMoving, regionId, zoneX, zoneY, chunkX, chunkY }`
|
||||
- `chunkUpdates[]`:
|
||||
- `chunk_full`: `{ type, chunk, tiles[], objects[], npcs[], mobs[] }`
|
||||
- `objects[]` now includes `interactionType` string.
|
||||
- `chunk_unload`: `{ type, regionId, zoneX, zoneY, chunkX, chunkY }`
|
||||
- `portalEvent` optional:
|
||||
- world teleport: `{ type: "world_teleport", sourceObjectId, regionId, zoneX, zoneY, chunkX, chunkY, x, y }`
|
||||
- dungeon transfer request: `{ type: "dungeon_request", sourceObjectId, portalType, dungeonTemplateId?, randomTier?, levelBracketMin?, levelBracketMax? }`
|
||||
- `errors[]` optional: e.g. `["blocked_non_walkable"]`, `["blocked_paywall"]`.
|
||||
- `WORLD_DESPAWN` (`302`) response:
|
||||
- `{ playerId, reason }`.
|
||||
@@ -207,6 +212,19 @@
|
||||
- server blocks movement against `isWalkable == false` tiles.
|
||||
- server blocks movement against `isInvisiblePaywall == true` when `player.isVip == false`.
|
||||
|
||||
### World portal metadata contract (object `metadataJson`)
|
||||
|
||||
- Portal objects are world chunk objects whose definition has `interactionType = Teleport` (or metadata includes `portalType`).
|
||||
- `portalType: "world"`:
|
||||
- `{ "portalType":"world","targetRegionId":1,"targetZoneX":0,"targetZoneY":0,"targetChunkX":0,"targetChunkY":0,"targetTileX":5,"targetTileY":5 }`
|
||||
- server teleports immediately on collision.
|
||||
- `portalType: "dungeon_random"`:
|
||||
- `{ "portalType":"dungeon_random","randomTier":3,"levelBracketMin":11,"levelBracketMax":20 }`
|
||||
- server emits `portalEvent.type = "dungeon_request"` for client-driven dungeon entry flow.
|
||||
- `portalType: "dungeon_specific"`:
|
||||
- `{ "portalType":"dungeon_specific","dungeonTemplateId":42 }`
|
||||
- server emits `portalEvent.type = "dungeon_request"` for client-driven dungeon entry flow.
|
||||
|
||||
## Dungeon Portals and Ledge-Safe Movement
|
||||
|
||||
- Movement collision now uses entity radius checks against tile walkability.
|
||||
|
||||
Reference in New Issue
Block a user