2024-06-03 14:58:59 +00:00
|
|
|
|
using ColdMint.scripts.character;
|
2024-10-08 08:11:51 +00:00
|
|
|
|
using ColdMint.scripts.map.room;
|
2024-06-10 13:05:18 +00:00
|
|
|
|
using ColdMint.scripts.utils;
|
2024-06-03 14:58:59 +00:00
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.map;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Ai character generation point</para>
|
|
|
|
|
/// <para>Ai角色生成点</para>
|
|
|
|
|
/// </summary>
|
2024-10-08 08:11:51 +00:00
|
|
|
|
public partial class AiCharacterSpawn : Marker2D, ISpawnMarker
|
2024-06-03 14:58:59 +00:00
|
|
|
|
{
|
2024-10-08 14:04:37 +00:00
|
|
|
|
[Export] private string[]? _resPathArray;
|
2024-06-03 14:58:59 +00:00
|
|
|
|
|
2024-10-08 14:04:37 +00:00
|
|
|
|
public Node2D? Spawn(int waveNumber)
|
2024-06-03 14:58:59 +00:00
|
|
|
|
{
|
2024-10-08 14:04:37 +00:00
|
|
|
|
if (GameSceneDepend.AiCharacterContainer == null)
|
2024-06-03 14:58:59 +00:00
|
|
|
|
{
|
2024-10-08 14:04:37 +00:00
|
|
|
|
return null;
|
2024-06-03 14:58:59 +00:00
|
|
|
|
}
|
2024-10-08 14:04:37 +00:00
|
|
|
|
if (_resPathArray == null)
|
2024-06-03 14:58:59 +00:00
|
|
|
|
{
|
2024-10-08 08:11:51 +00:00
|
|
|
|
return null;
|
2024-06-03 14:58:59 +00:00
|
|
|
|
}
|
2024-10-08 14:04:37 +00:00
|
|
|
|
if (waveNumber < 0 || waveNumber >= _resPathArray.Length)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var resPath = _resPathArray[waveNumber];
|
|
|
|
|
if (string.IsNullOrEmpty(resPath))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var packedScene = GD.Load<PackedScene>(resPath);
|
|
|
|
|
if (packedScene == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var aiCharacter = NodeUtils.InstantiatePackedScene<AiCharacter>(packedScene);
|
2024-06-10 13:05:18 +00:00
|
|
|
|
if (aiCharacter == null)
|
2024-06-03 14:58:59 +00:00
|
|
|
|
{
|
2024-10-08 08:11:51 +00:00
|
|
|
|
return null;
|
2024-06-03 14:58:59 +00:00
|
|
|
|
}
|
2024-06-24 14:19:12 +00:00
|
|
|
|
|
2024-09-01 15:24:35 +00:00
|
|
|
|
NodeUtils.CallDeferredAddChild(GameSceneDepend.AiCharacterContainer, aiCharacter);
|
2024-06-25 14:11:19 +00:00
|
|
|
|
aiCharacter.GlobalPosition = GlobalPosition;
|
2024-10-08 08:11:51 +00:00
|
|
|
|
return aiCharacter;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 14:04:37 +00:00
|
|
|
|
public int GetMaxWaveNumber()
|
|
|
|
|
{
|
|
|
|
|
return _resPathArray?.Length ?? 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 08:11:51 +00:00
|
|
|
|
public bool CanQueueFree()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
2024-06-03 14:58:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 08:11:51 +00:00
|
|
|
|
public void DoQueueFree()
|
2024-06-03 14:58:59 +00:00
|
|
|
|
{
|
2024-10-08 08:11:51 +00:00
|
|
|
|
QueueFree();
|
2024-06-03 14:58:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|