Altering Escape
This commit is contained in:
@@ -64,8 +64,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
DungeonOpCodes.DUNGEON_INPUT_ATTACK,
|
||||
DungeonOpCodes.DUNGEON_INPUT_PICKUP,
|
||||
DungeonOpCodes.DUNGEON_INPUT_CHEST,
|
||||
DungeonOpCodes.ESCAPE_START,
|
||||
DungeonOpCodes.ESCAPE_CANCEL,
|
||||
DungeonOpCodes.DUNGEON_INPUT_PORTAL,
|
||||
DungeonOpCodes.INVENTORY_REQUEST,
|
||||
DungeonOpCodes.EQUIP_ITEM,
|
||||
DungeonOpCodes.UNEQUIP_ITEM,
|
||||
@@ -170,12 +169,8 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
HandleInputChest(session, payload);
|
||||
break;
|
||||
|
||||
case DungeonOpCodes.ESCAPE_START:
|
||||
HandleEscapeStart(session);
|
||||
break;
|
||||
|
||||
case DungeonOpCodes.ESCAPE_CANCEL:
|
||||
HandleEscapeCancel(session);
|
||||
case DungeonOpCodes.DUNGEON_INPUT_PORTAL:
|
||||
await HandlePortalUse(connection, session, payload, ct);
|
||||
break;
|
||||
|
||||
case DungeonOpCodes.INVENTORY_REQUEST:
|
||||
@@ -419,6 +414,13 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
y = c.Y,
|
||||
type = c.Type.ToString().ToLower(),
|
||||
opened = c.IsOpened
|
||||
}),
|
||||
portals = instance.Simulation.Portals.Values.Where(p => p.IsActive).Select(p => new
|
||||
{
|
||||
id = p.Id,
|
||||
x = p.X,
|
||||
y = p.Y,
|
||||
type = p.Type.ToString().ToLower()
|
||||
})
|
||||
}, ct);
|
||||
}
|
||||
@@ -522,33 +524,61 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEscapeStart(DungeonPlayerSession session)
|
||||
/// <summary>
|
||||
/// Handle portal use - instant extraction when player clicks/walks into portal
|
||||
/// </summary>
|
||||
private async Task HandlePortalUse(IConnection connection, DungeonPlayerSession session, ReadOnlyMemory<byte> payload, CancellationToken ct)
|
||||
{
|
||||
if (session.State != PlayerState.InDungeon || !session.CurrentDungeonId.HasValue) return;
|
||||
if (!_dungeons.TryGetValue(session.CurrentDungeonId.Value, out var dungeon)) return;
|
||||
|
||||
// Check if at exit
|
||||
var layout = dungeon.Simulation.Layout;
|
||||
if (layout.ExitPosition == null) return;
|
||||
var json = System.Text.Encoding.UTF8.GetString(payload.Span);
|
||||
var request = System.Text.Json.JsonSerializer.Deserialize<PortalUseRequest>(json);
|
||||
if (request == null) return;
|
||||
|
||||
// Find the portal
|
||||
if (!dungeon.Simulation.Portals.TryGetValue(request.PortalId, out var portal))
|
||||
{
|
||||
_log.LogWarning("Player {Name} tried to use non-existent portal {Id}", session.Character.Name, request.PortalId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!portal.IsActive)
|
||||
{
|
||||
_log.LogWarning("Player {Name} tried to use inactive portal {Id}", session.Character.Name, request.PortalId);
|
||||
return;
|
||||
}
|
||||
|
||||
var player = session.PlayerInstance;
|
||||
if (player == null) return;
|
||||
|
||||
float exitX = layout.ExitPosition.Value.X * 32 + 16;
|
||||
float exitY = layout.ExitPosition.Value.Y * 32 + 16;
|
||||
float dist = MathF.Sqrt((player.X - exitX) * (player.X - exitX) + (player.Y - exitY) * (player.Y - exitY));
|
||||
// Check distance to portal (must be within 64 pixels)
|
||||
float dx = player.X - portal.X;
|
||||
float dy = player.Y - portal.Y;
|
||||
float dist = MathF.Sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < 48) // Within range
|
||||
if (dist > 64)
|
||||
{
|
||||
session.IsEscaping = true;
|
||||
session.EscapeStartTick = _currentTick;
|
||||
_log.LogDebug("Player {Name} too far from portal ({Dist})", session.Character.Name, dist);
|
||||
return;
|
||||
}
|
||||
|
||||
_log.LogInformation("Player {Name} using exit portal", session.Character.Name);
|
||||
|
||||
// Send portal used confirmation
|
||||
await SendAsync(connection, DungeonOpCodes.PORTAL_USED, new
|
||||
{
|
||||
portalId = portal.Id,
|
||||
type = portal.Type.ToString().ToLower()
|
||||
}, ct);
|
||||
|
||||
// Extract player (keep loot, save progress)
|
||||
await RemoveFromDungeonAsync(session, true, ct);
|
||||
|
||||
// Return to hub
|
||||
await SendAsync(connection, DungeonOpCodes.HUB_STATE, GetHubState(session.Character), ct);
|
||||
}
|
||||
|
||||
private void HandleEscapeCancel(DungeonPlayerSession session)
|
||||
{
|
||||
session.IsEscaping = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Handle hotbar slot assignment - links a hotbar slot to an inventory slot
|
||||
/// </summary>
|
||||
@@ -1159,6 +1189,14 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
y = i.Y
|
||||
}),
|
||||
|
||||
portals = sim.Portals.Values.Where(p => p.IsActive).Select(p => new
|
||||
{
|
||||
id = p.Id,
|
||||
x = p.X,
|
||||
y = p.Y,
|
||||
type = p.Type.ToString().ToLower()
|
||||
}),
|
||||
|
||||
events = tickResult == null ? null : new
|
||||
{
|
||||
damage = tickResult.DamageEvents.Select(e => new
|
||||
@@ -1489,3 +1527,8 @@ public class ChatSendRequest
|
||||
{
|
||||
public string Message { get; set; } = "";
|
||||
}
|
||||
|
||||
public class PortalUseRequest
|
||||
{
|
||||
public int PortalId { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user