Portal fix, mob ai adjustment
This commit is contained in:
@@ -62,29 +62,90 @@ public class DungeonSimulation
|
||||
|
||||
private void SpawnExitPortal()
|
||||
{
|
||||
// Spawn exit portal near the entrance room (but offset so players don't spawn on it)
|
||||
// Spawn exit portal in corner of entrance room (away from center and hallways)
|
||||
if (Layout.Rooms.Count == 0) return;
|
||||
|
||||
var entranceRoom = Layout.Rooms[0];
|
||||
|
||||
// Find a valid floor tile near the entrance that's not at the exact center
|
||||
// Try positions around the room center
|
||||
var offsets = new[] { (2, 0), (-2, 0), (0, 2), (0, -2), (2, 2), (-2, -2) };
|
||||
// Room uses X, Y as top-left corner
|
||||
int roomLeft = entranceRoom.X + 1;
|
||||
int roomRight = entranceRoom.X + entranceRoom.Width - 2;
|
||||
int roomTop = entranceRoom.Y + 1;
|
||||
int roomBottom = entranceRoom.Y + entranceRoom.Height - 2;
|
||||
|
||||
// Try corners first (away from center where players spawn)
|
||||
var cornerPositions = new[]
|
||||
{
|
||||
(roomLeft + 1, roomTop + 1), // Top-left
|
||||
(roomRight - 1, roomTop + 1), // Top-right
|
||||
(roomLeft + 1, roomBottom - 1), // Bottom-left
|
||||
(roomRight - 1, roomBottom - 1), // Bottom-right
|
||||
};
|
||||
|
||||
foreach (var (tileX, tileY) in cornerPositions)
|
||||
{
|
||||
// Check if this is a valid floor tile
|
||||
if (tileX >= 0 && tileX < Layout.Width &&
|
||||
tileY >= 0 && tileY < Layout.Height &&
|
||||
Layout.Tiles[tileX, tileY] == 1) // 1 = floor
|
||||
{
|
||||
// Check surrounding tiles to avoid placing near hallways
|
||||
bool nearHallway = false;
|
||||
for (int dx = -1; dx <= 1 && !nearHallway; dx++)
|
||||
{
|
||||
for (int dy = -1; dy <= 1 && !nearHallway; dy++)
|
||||
{
|
||||
int checkX = tileX + dx;
|
||||
int checkY = tileY + dy;
|
||||
if (checkX >= 0 && checkX < Layout.Width && checkY >= 0 && checkY < Layout.Height)
|
||||
{
|
||||
// Check if this position is outside the room bounds (potential hallway)
|
||||
bool outsideRoom = checkX < entranceRoom.X ||
|
||||
checkX >= entranceRoom.X + entranceRoom.Width ||
|
||||
checkY < entranceRoom.Y ||
|
||||
checkY >= entranceRoom.Y + entranceRoom.Height;
|
||||
|
||||
if (outsideRoom && Layout.Tiles[checkX, checkY] == 1) // Floor outside room = hallway
|
||||
{
|
||||
nearHallway = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nearHallway)
|
||||
{
|
||||
var portal = new PortalInstance
|
||||
{
|
||||
Id = 1,
|
||||
X = tileX * 32 + 16, // Center of tile in world coords
|
||||
Y = tileY * 32 + 16,
|
||||
Type = PortalType.Exit,
|
||||
IsActive = true
|
||||
};
|
||||
|
||||
Portals[portal.Id] = portal;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: try any position in the room away from center
|
||||
var offsets = new[] { (-3, -3), (3, -3), (-3, 3), (3, 3), (-3, 0), (3, 0), (0, -3), (0, 3) };
|
||||
|
||||
foreach (var (dx, dy) in offsets)
|
||||
{
|
||||
int portalTileX = entranceRoom.CenterX + dx;
|
||||
int portalTileY = entranceRoom.CenterY + dy;
|
||||
|
||||
// Check if this is a valid floor tile
|
||||
if (portalTileX >= 0 && portalTileX < Layout.Width &&
|
||||
portalTileY >= 0 && portalTileY < Layout.Height &&
|
||||
Layout.Tiles[portalTileX, portalTileY] == 1) // 1 = floor
|
||||
Layout.Tiles[portalTileX, portalTileY] == 1)
|
||||
{
|
||||
var portal = new PortalInstance
|
||||
{
|
||||
Id = 1,
|
||||
X = portalTileX * 32 + 16, // Center of tile in world coords
|
||||
X = portalTileX * 32 + 16,
|
||||
Y = portalTileY * 32 + 16,
|
||||
Type = PortalType.Exit,
|
||||
IsActive = true
|
||||
@@ -95,7 +156,7 @@ public class DungeonSimulation
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: spawn at room center if no offset worked
|
||||
// Last fallback: spawn at room center
|
||||
var fallbackPortal = new PortalInstance
|
||||
{
|
||||
Id = 1,
|
||||
|
||||
Reference in New Issue
Block a user