67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using Godot;
|
|
using System.Collections.Immutable;
|
|
using Zennysoft.Ma.Adapter;
|
|
|
|
namespace Zennysoft.Game.Ma;
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public abstract partial class DungeonRoom : Node3D, IDungeonRoom
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
[Node] public Marker3D PlayerSpawn { get; set; } = default!;
|
|
|
|
[Node] private MeshInstance3D _minimap { get; set; } = default!;
|
|
|
|
public bool IsPlayerInRoom => _isPlayerInRoom;
|
|
|
|
public bool PlayerDiscoveredRoom => _playerDiscoveredRoom;
|
|
|
|
public ImmutableList<IEnemy> EnemiesInRoom => _enemiesInRoom;
|
|
|
|
[Node] private Area3D _room { get; set; } = default!;
|
|
|
|
private ImmutableList<IEnemy> _enemiesInRoom;
|
|
private bool _isPlayerInRoom = false;
|
|
private bool _playerDiscoveredRoom = false;
|
|
|
|
public void Setup()
|
|
{
|
|
_enemiesInRoom = [];
|
|
_room.BodyEntered += Room_BodyEntered;
|
|
_room.BodyExited += Room_BodyExited;
|
|
}
|
|
|
|
private void Room_BodyExited(Node3D body)
|
|
{
|
|
if (body is IEnemy enemy)
|
|
_enemiesInRoom = _enemiesInRoom.Remove(enemy);
|
|
if (body is IPlayer)
|
|
_isPlayerInRoom = false;
|
|
}
|
|
private void Room_BodyEntered(Node3D body)
|
|
{
|
|
if (body is IEnemy enemy)
|
|
_enemiesInRoom = _enemiesInRoom.Add(enemy);
|
|
if (body is IPlayer)
|
|
if (_playerDiscoveredRoom)
|
|
_isPlayerInRoom = true;
|
|
else
|
|
OnPlayerDiscoveringRoom();
|
|
}
|
|
|
|
public ImmutableList<IEnemy> GetEnemiesInCurrentRoom()
|
|
{
|
|
return _enemiesInRoom;
|
|
}
|
|
|
|
private void OnPlayerDiscoveringRoom()
|
|
{
|
|
_isPlayerInRoom = true;
|
|
_playerDiscoveredRoom = true;
|
|
_minimap.Show();
|
|
}
|
|
}
|