♻️ Better miner tile
This commit is contained in:
@@ -6,7 +6,7 @@ namespace AceFieldNewHorizon.Scripts.Tiles;
|
||||
public partial class MinerTile : BaseTile
|
||||
{
|
||||
[Export] public PackedScene ItemPickup { get; set; }
|
||||
[Export] public string ItemToMine { get; set; } = "OreIron";
|
||||
[Export] public string ItemToMine { get; set; }
|
||||
[Export] public int MiningRate = 1; // Items per second
|
||||
|
||||
private Vector2I _gridPosition;
|
||||
@@ -16,10 +16,29 @@ public partial class MinerTile : BaseTile
|
||||
{
|
||||
base._Ready();
|
||||
_gridPosition = GridUtils.WorldToGrid(Position);
|
||||
|
||||
var ground = Grid.GetTileAtCell(_gridPosition, GridLayer.Ground) as BaseTile;
|
||||
if (ground == null)
|
||||
{
|
||||
GD.Print($"[Miner] Miner {GetInstanceId()} not found available resource...");
|
||||
return;
|
||||
}
|
||||
|
||||
ItemToMine = (ground.TileId) switch
|
||||
{
|
||||
"stone" => "stone",
|
||||
"ore_iron" => "ore_iron",
|
||||
_ => null
|
||||
};
|
||||
if (ItemToMine == null)
|
||||
GD.Print($"[Miner] Miner {GetInstanceId()} not found available resource...");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (ItemToMine == null)
|
||||
return;
|
||||
|
||||
// Don't mine if building is not completed
|
||||
if (!IsConstructed || ItemPickup == null)
|
||||
return;
|
||||
|
Reference in New Issue
Block a user