85 lines
2.7 KiB
C#
85 lines
2.7 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 void SpawnEnemies(DungeonFloorNode floorNode)
|
|
{
|
|
var enemyOdds = new Godot.Collections.Dictionary<EnemyType, float>
|
|
{
|
|
{ EnemyType.Sproingy, floorNode.Sproingy },
|
|
{ EnemyType.Michael, floorNode.Michael },
|
|
{ EnemyType.FilthEater, floorNode.FilthEater },
|
|
{ EnemyType.Sara, floorNode.Sara },
|
|
{ EnemyType.Ballos, floorNode.Ballos },
|
|
{ EnemyType.Chariot, floorNode.Chariot },
|
|
{ EnemyType.Chinthe, floorNode.Chinthe },
|
|
{ EnemyType.AmbassadorGreen, floorNode.GreenAmbassador },
|
|
{ EnemyType.AmbassadorRed, floorNode.RedAmbassador },
|
|
{ EnemyType.AmbassadorSteel, floorNode.SteelAmbassador },
|
|
{ EnemyType.AgniDemon, floorNode.AgniDemon },
|
|
{ EnemyType.AqueousDemon, floorNode.AqueosDemon },
|
|
{ EnemyType.Palan, floorNode.Palan },
|
|
{ EnemyType.ShieldOfHeaven, floorNode.ShieldOfHeaven },
|
|
{ EnemyType.GoldSproingy, floorNode.GoldSproingy },
|
|
};
|
|
var monsterRooms = Rooms.OfType<MonsterRoom>();
|
|
foreach (var room in monsterRooms)
|
|
room.SpawnEnemies(enemyOdds);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|