Files
GameJamDungeon/Zennysoft.Game.Ma/src/map/dungeon/code/DungeonFloor.cs
T
2026-06-11 20:53:16 -07:00

66 lines
1.8 KiB
C#

using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace Zennysoft.Game.Ma;
[Meta(typeof(IAutoNode))]
public partial class DungeonFloor : Node3D, IDungeonFloor
{
public override void _Notification(int what) => this.Notify(what);
private Marker3D _playerSpawnPoint;
public ImmutableList<IDungeonRoom> Rooms { get; private set; }
public bool FloorIsLoaded { get; set; }
public void InitializeDungeon()
{
Rooms = [];
Rooms = FindAllDungeonRooms([.. GetChildren()], Rooms);
_playerSpawnPoint = RandomizePlayerSpawnPoint();
}
public void FadeOutAudio()
{
}
public (Vector3 Rotation, Vector3 Position) GetPlayerSpawnPoint() { return (_playerSpawnPoint.Rotation, new Vector3(_playerSpawnPoint.GlobalPosition.X, 0, _playerSpawnPoint.GlobalPosition.Z)); }
private Marker3D RandomizePlayerSpawnPoint()
{
var randomSpawnLocations = Rooms
.OfType<MonsterRoom>()
.Select(x => x.PlayerSpawn);
var godotCollection = new Godot.Collections.Array<Marker3D>(randomSpawnLocations);
var result = godotCollection.PickRandom();
return result;
}
private static ImmutableList<IDungeonRoom> FindAllDungeonRooms(List<Node> nodesToSearch, ImmutableList<IDungeonRoom> roomsFound)
{
if (nodesToSearch.Count == 0)
return roomsFound;
foreach (var node in nodesToSearch)
{
if (node is IDungeonRoom dungeonRoom)
roomsFound = roomsFound.Add(dungeonRoom);
}
return FindAllDungeonRooms([.. nodesToSearch.SelectMany(x => x.GetChildren())], roomsFound);
}
public IDungeonRoom GetPlayersCurrentRoom()
{
var playersRoom = Rooms.SingleOrDefault(x => x.IsPlayerInRoom);
return playersRoom;
}
}