mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 23:05:53 +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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue