Traveller/scripts/map/ItemSpawn.cs
Cold-Mint d80c49ab02
Adjust the time of spawns of items and enemies in the map to when the player first enters the room.
将地图中物品,敌人生成的时机调整到玩家首次进入房间时。
2024-10-08 16:11:51 +08:00

42 lines
930 B
C#

using ColdMint.scripts.debug;
using ColdMint.scripts.inventory;
using ColdMint.scripts.map.room;
using Godot;
namespace ColdMint.scripts.map;
/// <summary>
/// <para>ItemSpawn</para>
/// <para>物品出生点</para>
/// </summary>
public partial class ItemSpawn : Marker2D, ISpawnMarker
{
[Export] private string? ItemId { get; set; }
public Node2D? Spawn()
{
if (string.IsNullOrEmpty(ItemId))
{
return null;
}
var item = ItemTypeManager.CreateItem(ItemId, this);
LogCat.LogWithFormat("generated_item_is_empty", LogCat.LogLabel.ItemSpawn, true, ItemId, item == null);
if (item is not Node2D node2D)
{
return null;
}
node2D.GlobalPosition = GlobalPosition;
return node2D;
}
public bool CanQueueFree()
{
return true;
}
public void DoQueueFree()
{
QueueFree();
}
}