TownHall.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. public class TownHall : Building
  3. {
  4. [Header("TownHall Specific")]
  5. public bool isMainStorage = true;
  6. void Start()
  7. {
  8. buildingType = BuildingType.TownHall;
  9. buildingName = "Town Hall";
  10. storageCapacity = 1000; // Large storage capacity
  11. maxWorkers = 0; // TownHall doesn't need workers assigned
  12. // Call base Start
  13. base.Start();
  14. // Set tag for easy finding
  15. gameObject.tag = "TownHall";
  16. // Initialize with starting resources if this is the main storage
  17. if (isMainStorage)
  18. {
  19. InitializeStartingResources();
  20. }
  21. }
  22. void InitializeStartingResources()
  23. {
  24. // Add starting resources to both the TownHall and the global resource manager
  25. StoreResource(ResourceType.Wood, 50);
  26. StoreResource(ResourceType.Stone, 30);
  27. StoreResource(ResourceType.Food, 100);
  28. }
  29. public override bool StoreResource(ResourceType resourceType, int amount)
  30. {
  31. // For TownHall, always store in both local storage and global resource manager
  32. bool storedLocally = base.StoreResource(resourceType, amount);
  33. if (storedLocally && GameManager.Instance != null)
  34. {
  35. // Also add to global resources (this represents the town's total resources)
  36. GameManager.Instance.resourceManager.AddResource(resourceType, amount);
  37. }
  38. return storedLocally;
  39. }
  40. public override bool WithdrawResource(ResourceType resourceType, int amount)
  41. {
  42. // For TownHall, withdraw from both local and global
  43. bool withdrawnLocally = base.WithdrawResource(resourceType, amount);
  44. if (withdrawnLocally && GameManager.Instance != null)
  45. {
  46. // Also spend from global resources
  47. GameManager.Instance.resourceManager.SpendResource(resourceType, amount);
  48. }
  49. return withdrawnLocally;
  50. }
  51. public void AcceptDelivery(ResourceType resourceType, int amount)
  52. {
  53. // This method is called when villagers deliver resources
  54. StoreResource(resourceType, amount);
  55. Debug.Log($"TownHall received {amount} {resourceType}");
  56. }
  57. // Override to provide more detailed info for TownHall
  58. public override string GetBuildingInfo()
  59. {
  60. string info = base.GetBuildingInfo();
  61. info += "\n--- Global Resources ---";
  62. if (GameManager.Instance != null)
  63. {
  64. var globalResources = GameManager.Instance.resourceManager.GetAllResources();
  65. foreach (var resource in globalResources)
  66. {
  67. info += $"\n{resource.Key}: {resource.Value}";
  68. }
  69. }
  70. return info;
  71. }
  72. }