2024-06-03 14:58:59 +00:00
|
|
|
|
using ColdMint.scripts.character;
|
|
|
|
|
using ColdMint.scripts.map.events;
|
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>
|
|
|
|
|
public partial class AiCharacterSpawn : Marker2D
|
|
|
|
|
{
|
|
|
|
|
private PackedScene? _packedScene;
|
|
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
|
|
|
|
base._Ready();
|
|
|
|
|
var resPath = GetMeta("ResPath", Name).AsString();
|
|
|
|
|
if (!string.IsNullOrEmpty(resPath))
|
|
|
|
|
{
|
|
|
|
|
_packedScene = GD.Load<PackedScene>(resPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventManager.AiCharacterGenerateEvent += OnAiCharacterGenerateEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>When an event is triggered</para>
|
|
|
|
|
/// <para>当触发事件时</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="aiCharacterGenerateEvent"></param>
|
|
|
|
|
public void OnAiCharacterGenerateEvent(AiCharacterGenerateEvent aiCharacterGenerateEvent)
|
|
|
|
|
{
|
2024-06-24 14:19:12 +00:00
|
|
|
|
if (GameSceneNodeHolder.AiCharacterContainer == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 13:05:18 +00:00
|
|
|
|
if (_packedScene == null)
|
2024-06-03 14:58:59 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 14:19:12 +00:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-24 14:19:12 +00:00
|
|
|
|
|
|
|
|
|
NodeUtils.CallDeferredAddChild(NodeUtils.FindContainerNode(aiCharacter, this), aiCharacter);
|
2024-06-03 14:58:59 +00:00
|
|
|
|
aiCharacter.Position = GlobalPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _ExitTree()
|
|
|
|
|
{
|
|
|
|
|
EventManager.AiCharacterGenerateEvent -= OnAiCharacterGenerateEvent;
|
|
|
|
|
}
|
|
|
|
|
}
|