mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:55:35 +00:00
85 lines
No EOL
2.1 KiB
C#
85 lines
No EOL
2.1 KiB
C#
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;
|
|
|
|
[Tool]
|
|
public partial class RogueliteEnemySpawner : Marker2D
|
|
{
|
|
private EnemyResource _enemy;
|
|
|
|
[Export]
|
|
public EnemyResource Enemy
|
|
{
|
|
get => _enemy;
|
|
set
|
|
{
|
|
_enemy = value;
|
|
if (Engine.IsEditorHint())
|
|
{
|
|
QueueRedraw();
|
|
}
|
|
}
|
|
}
|
|
|
|
[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));
|
|
}
|
|
|
|
private void Redraw()
|
|
{
|
|
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;
|
|
}
|
|
} |