using UnityEngine; public class TownHall : Building { [Header("TownHall Specific")] public bool isMainStorage = true; void Start() { buildingType = BuildingType.TownHall; buildingName = "Town Hall"; storageCapacity = 1000; // Large storage capacity maxWorkers = 0; // TownHall doesn't need workers assigned // Call base Start base.Start(); // Set tag for easy finding gameObject.tag = "TownHall"; // Initialize with starting resources if this is the main storage if (isMainStorage) { InitializeStartingResources(); } } void InitializeStartingResources() { // Add starting resources to both the TownHall and the global resource manager StoreResource(ResourceType.Wood, 50); StoreResource(ResourceType.Stone, 30); StoreResource(ResourceType.Food, 100); } public override bool StoreResource(ResourceType resourceType, int amount) { // For TownHall, always store in both local storage and global resource manager bool storedLocally = base.StoreResource(resourceType, amount); if (storedLocally && GameManager.Instance != null) { // Also add to global resources (this represents the town's total resources) GameManager.Instance.resourceManager.AddResource(resourceType, amount); } return storedLocally; } public override bool WithdrawResource(ResourceType resourceType, int amount) { // For TownHall, withdraw from both local and global bool withdrawnLocally = base.WithdrawResource(resourceType, amount); if (withdrawnLocally && GameManager.Instance != null) { // Also spend from global resources GameManager.Instance.resourceManager.SpendResource(resourceType, amount); } return withdrawnLocally; } public void AcceptDelivery(ResourceType resourceType, int amount) { // This method is called when villagers deliver resources StoreResource(resourceType, amount); Debug.Log($"TownHall received {amount} {resourceType}"); } // Override to provide more detailed info for TownHall public override string GetBuildingInfo() { string info = base.GetBuildingInfo(); info += "\n--- Global Resources ---"; if (GameManager.Instance != null) { var globalResources = GameManager.Instance.resourceManager.GetAllResources(); foreach (var resource in globalResources) { info += $"\n{resource.Key}: {resource.Value}"; } } return info; } }