Move files and folders to new repo format to enable multi-project format
This commit is contained in:
65
Zennysoft.Game.Ma/src/map/dungeon/code/DungeonRoom.cs
Normal file
65
Zennysoft.Game.Ma/src/map/dungeon/code/DungeonRoom.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user