mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 14:15:55 +00:00
Fixed enemy spawns
This commit is contained in:
parent
c00d298443
commit
7a62f6a8cd
19 changed files with 263 additions and 147 deletions
|
|
@ -1,4 +1,8 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Components.FSM.Enemy;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Resources.Loot;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
|
@ -22,16 +26,20 @@ public partial class RogueliteEnemySpawner : Marker2D
|
|||
}
|
||||
}
|
||||
|
||||
[Export] public int Wave { get; private set; } = 0;
|
||||
|
||||
public bool Spawned { get; private set; } = false;
|
||||
|
||||
[ExportToolButton("Update Icon")] public Callable RedrawButton => Callable.From(Redraw);
|
||||
|
||||
private EnemyFSMProxy _spawnedEnemy;
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
if (!Engine.IsEditorHint()) return;
|
||||
if (Enemy is null) return;
|
||||
if (Enemy.IconSprite is null) return;
|
||||
|
||||
|
||||
|
||||
DrawTexture(Enemy.IconSprite, - new Vector2(_enemy.IconSprite.GetWidth() / 2f, _enemy.IconSprite.GetHeight() / 2f));
|
||||
}
|
||||
|
||||
|
|
@ -39,4 +47,38 @@ public partial class RogueliteEnemySpawner : Marker2D
|
|||
{
|
||||
QueueRedraw();
|
||||
}
|
||||
|
||||
public EnemyFSMProxy Spawn(RogueliteMapTheme mapTheme)
|
||||
{
|
||||
if (Engine.IsEditorHint()) return null;
|
||||
if (Spawned) return _spawnedEnemy;
|
||||
|
||||
var enemyScene = GD.Load<PackedScene>(Enemy.PrefabPath);
|
||||
_spawnedEnemy = this.CreateSibling<EnemyFSMProxy>(enemyScene);
|
||||
|
||||
_spawnedEnemy.OverrideLoot = true;
|
||||
_spawnedEnemy.ExtraLoot.Add(new LootDrop()
|
||||
{
|
||||
Item = mapTheme.EnemiesLootTable.Items.ToList().Shuffle().First(),
|
||||
Chance = mapTheme.EnemyDropChance
|
||||
});
|
||||
_spawnedEnemy.ExtraLoot.Add(new LootDrop()
|
||||
{
|
||||
Item = mapTheme.PointItemResource,
|
||||
Chance = 100
|
||||
});
|
||||
|
||||
Spawned = true;
|
||||
|
||||
_spawnedEnemy.Death += SpawnedEnemyOnDeath;
|
||||
|
||||
return _spawnedEnemy;
|
||||
}
|
||||
|
||||
private void SpawnedEnemyOnDeath(EnemyFSMProxy enemy)
|
||||
{
|
||||
_spawnedEnemy.Death -= SpawnedEnemyOnDeath;
|
||||
_spawnedEnemy = null;
|
||||
Spawned = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,12 @@ public partial class AlarmManager : Node2D
|
|||
_player?.Play();
|
||||
}
|
||||
|
||||
public void SoundSilentAlarm(Vector2 location)
|
||||
{
|
||||
if (IsAlarmOn) return;
|
||||
EmitSignal(nameof(AlarmEnabled), location);
|
||||
}
|
||||
|
||||
public void DisableAlarm()
|
||||
{
|
||||
IsAlarmOn = false;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ public partial class EnemyFSMProxy : CharacterBody2D, IActivable
|
|||
{
|
||||
EmitSignalDeath(this);
|
||||
}
|
||||
|
||||
public void RequestAlert(Vector2 destination)
|
||||
{
|
||||
//EnemyFSM.SetState(EnemyState.Alert);
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Activables;
|
||||
using Cirno.Scripts.Actors;
|
||||
using Cirno.Scripts.Components.FSM.Enemy;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Cirno.Scripts.Interactables;
|
||||
|
|
@ -61,10 +63,13 @@ public partial class RogueliteRoom : Node2D
|
|||
private List<EnemyFSMProxy> _enemies = [];
|
||||
|
||||
private Array<EnemyResource> SpawnableEnemies => RoomResource.SpawnableEnemies;
|
||||
|
||||
private BlackCover _shroud;
|
||||
private bool _firstEnter = true;
|
||||
|
||||
public RogueliteRoom Spawn()
|
||||
{
|
||||
SpawnEnemies();
|
||||
//SpawnEnemies();
|
||||
SpawnFeatures();
|
||||
SpawnFixedWeapons();
|
||||
SpawnShroud();
|
||||
|
|
@ -222,28 +227,13 @@ public partial class RogueliteRoom : Node2D
|
|||
{
|
||||
if (SpawnableEnemies is null || !SpawnableEnemies.Any()) return;
|
||||
|
||||
var enemySpawners = this.GetNode("EnemySpawners").GetChildren().Cast<Marker2D>();
|
||||
var enemySpawnerMarkers = this.GetNode("EnemySpawners").GetChildren();
|
||||
|
||||
foreach (var spawner in enemySpawners)
|
||||
foreach (var marker in enemySpawnerMarkers)
|
||||
{
|
||||
var index = GD.RandRange(0, SpawnableEnemies.Count - 1);
|
||||
if (marker is not RogueliteEnemySpawner spawner) continue;
|
||||
|
||||
var e = SpawnableEnemies[index];
|
||||
|
||||
var enemyScene = GD.Load<PackedScene>(e.PrefabPath);
|
||||
var spawnedEnemy = spawner.CreateChild<EnemyFSMProxy>(enemyScene);
|
||||
|
||||
spawnedEnemy.OverrideLoot = true;
|
||||
spawnedEnemy.ExtraLoot.Add(new LootDrop()
|
||||
{
|
||||
Item = MapTheme.EnemiesLootTable.Items.ToList().Shuffle().First(),
|
||||
Chance = MapTheme.EnemyDropChance
|
||||
});
|
||||
spawnedEnemy.ExtraLoot.Add(new LootDrop()
|
||||
{
|
||||
Item = MapTheme.PointItemResource,
|
||||
Chance = 100
|
||||
});
|
||||
var spawnedEnemy = spawner.Spawn(MapTheme);
|
||||
|
||||
_enemies.Add(spawnedEnemy);
|
||||
|
||||
|
|
@ -377,6 +367,16 @@ public partial class RogueliteRoom : Node2D
|
|||
{
|
||||
if (area is not InteractionController player) return;
|
||||
|
||||
if (_firstEnter)
|
||||
{
|
||||
SpawnEnemies();
|
||||
_firstEnter = false;
|
||||
_shroud?.Activate(ActivationType.Disable);
|
||||
|
||||
_ = AlarmTriggerAsync(area.GlobalPosition, 1f);
|
||||
}
|
||||
|
||||
// This might cause problems later if I delay enemy spawns
|
||||
if (_enemies.Count <= 0)
|
||||
{
|
||||
OpenDoors();
|
||||
|
|
@ -387,6 +387,12 @@ public partial class RogueliteRoom : Node2D
|
|||
}
|
||||
}
|
||||
|
||||
private async Task AlarmTriggerAsync(Vector2 position, float secondsDelay)
|
||||
{
|
||||
await Task.Delay((int)(secondsDelay * 1000));
|
||||
AlarmManager.Instance.SoundSilentAlarm(position);
|
||||
}
|
||||
|
||||
private void OnRoomExited(Area2D area)
|
||||
{
|
||||
if (area is not InteractionController player) return;
|
||||
|
|
@ -456,6 +462,8 @@ public partial class RogueliteRoom : Node2D
|
|||
shroud.Position = new Vector2(RoomSize.X / 2, RoomSize.Y / 2);
|
||||
shroud.Scale = RoomSize;
|
||||
|
||||
_shroud = shroud;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue