TownSetupHelper.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. using System.Collections.Generic;
  4. [System.Serializable]
  5. public class TownSetupHelper : MonoBehaviour
  6. {
  7. [Header("Auto-Setup Configuration")]
  8. public bool createSampleShops = true;
  9. public bool loadSampleItems = true;
  10. [Header("Generated Shops")]
  11. public TownShop weaponShop;
  12. public TownShop armorShop;
  13. public TownShop potionShop;
  14. public TownShop generalStore;
  15. [ContextMenu("Setup Sample Town")]
  16. public void SetupSampleTown()
  17. {
  18. if (createSampleShops)
  19. {
  20. CreateShopGameObjects();
  21. }
  22. if (loadSampleItems)
  23. {
  24. LoadSampleItemsToShops();
  25. }
  26. Debug.Log("Sample town setup complete!");
  27. }
  28. private void CreateShopGameObjects()
  29. {
  30. // Create Weapon Shop
  31. if (weaponShop == null)
  32. {
  33. var weaponShopGO = new GameObject("WeaponShop");
  34. weaponShopGO.transform.SetParent(transform);
  35. weaponShop = weaponShopGO.AddComponent<TownShop>();
  36. ConfigureWeaponShop();
  37. }
  38. // Create Armor Shop
  39. if (armorShop == null)
  40. {
  41. var armorShopGO = new GameObject("ArmorShop");
  42. armorShopGO.transform.SetParent(transform);
  43. armorShop = armorShopGO.AddComponent<TownShop>();
  44. ConfigureArmorShop();
  45. }
  46. // Create Potion Shop
  47. if (potionShop == null)
  48. {
  49. var potionShopGO = new GameObject("PotionShop");
  50. potionShopGO.transform.SetParent(transform);
  51. potionShop = potionShopGO.AddComponent<TownShop>();
  52. ConfigurePotionShop();
  53. }
  54. // Create General Store
  55. if (generalStore == null)
  56. {
  57. var generalStoreGO = new GameObject("GeneralStore");
  58. generalStoreGO.transform.SetParent(transform);
  59. generalStore = generalStoreGO.AddComponent<TownShop>();
  60. ConfigureGeneralStore();
  61. }
  62. }
  63. private void ConfigureWeaponShop()
  64. {
  65. weaponShop.buildingName = "The Forge";
  66. weaponShop.shopType = ShopType.Weapons;
  67. weaponShop.shopkeeperName = "Gareth the Smith";
  68. weaponShop.profitMargin = 1.3f; // 30% markup
  69. weaponShop.sellbackRate = 0.6f; // 60% when selling back
  70. weaponShop.description = "Fine weapons crafted by the town's master smith";
  71. weaponShop.isInteractable = true;
  72. weaponShop.buildingColor = new Color(0.8f, 0.2f, 0.2f); // Red
  73. }
  74. private void ConfigureArmorShop()
  75. {
  76. armorShop.buildingName = "Ironclad Armory";
  77. armorShop.shopType = ShopType.Armor;
  78. armorShop.shopkeeperName = "Miranda the Armorer";
  79. armorShop.profitMargin = 1.25f; // 25% markup
  80. armorShop.sellbackRate = 0.6f;
  81. armorShop.description = "Protective gear for the discerning adventurer";
  82. armorShop.isInteractable = true;
  83. armorShop.buildingColor = new Color(0.2f, 0.2f, 0.8f); // Blue
  84. }
  85. private void ConfigurePotionShop()
  86. {
  87. potionShop.buildingName = "The Bubbling Cauldron";
  88. potionShop.shopType = ShopType.Potions;
  89. potionShop.shopkeeperName = "Elias the Alchemist";
  90. potionShop.profitMargin = 1.4f; // 40% markup (potions are specialized)
  91. potionShop.sellbackRate = 0.5f; // Lower sellback for consumables
  92. potionShop.description = "Magical elixirs and healing draughts";
  93. potionShop.isInteractable = true;
  94. potionShop.buildingColor = new Color(0.2f, 0.8f, 0.2f); // Green
  95. }
  96. private void ConfigureGeneralStore()
  97. {
  98. generalStore.buildingName = "Pete's General Goods";
  99. generalStore.shopType = ShopType.General;
  100. generalStore.shopkeeperName = "Old Pete";
  101. generalStore.profitMargin = 1.2f; // 20% markup
  102. generalStore.sellbackRate = 0.65f; // Better sellback for general goods
  103. generalStore.description = "Everything an adventurer needs, and some things they don't";
  104. generalStore.isInteractable = true;
  105. generalStore.buildingColor = new Color(1f, 0.65f, 0f); // Orange
  106. }
  107. private void LoadSampleItemsToShops()
  108. {
  109. // Load all items from Resources
  110. var allWeapons = Resources.LoadAll<WeaponItem>("Items/Weapons");
  111. var allArmor = Resources.LoadAll<ArmorItem>("Items/Armor");
  112. var allMisc = Resources.LoadAll<MiscellaneousItem>("Items/Miscellaneous");
  113. Debug.Log($"Loaded {allWeapons.Length} weapons, {allArmor.Length} armor pieces, {allMisc.Length} misc items");
  114. // Add weapons to weapon shop
  115. if (weaponShop != null)
  116. {
  117. weaponShop.baseInventory.Clear();
  118. foreach (var weapon in allWeapons)
  119. {
  120. if (weapon != null)
  121. weaponShop.baseInventory.Add(weapon);
  122. }
  123. Debug.Log($"Added {allWeapons.Length} weapons to weapon shop");
  124. }
  125. // Add armor to armor shop
  126. if (armorShop != null)
  127. {
  128. armorShop.baseInventory.Clear();
  129. foreach (var armor in allArmor)
  130. {
  131. if (armor != null)
  132. armorShop.baseInventory.Add(armor);
  133. }
  134. Debug.Log($"Added {allArmor.Length} armor pieces to armor shop");
  135. }
  136. // Add consumables to potion shop
  137. if (potionShop != null)
  138. {
  139. potionShop.baseInventory.Clear();
  140. foreach (var misc in allMisc)
  141. {
  142. if (misc != null && misc.itemType == ItemType.Consumable)
  143. potionShop.baseInventory.Add(misc);
  144. }
  145. Debug.Log($"Added consumables to potion shop");
  146. }
  147. // Add everything to general store (smaller selection)
  148. if (generalStore != null)
  149. {
  150. generalStore.baseInventory.Clear();
  151. // Add a few basic weapons
  152. for (int i = 0; i < Mathf.Min(3, allWeapons.Length); i++)
  153. {
  154. if (allWeapons[i] != null)
  155. generalStore.baseInventory.Add(allWeapons[i]);
  156. }
  157. // Add a few basic armor pieces
  158. for (int i = 0; i < Mathf.Min(3, allArmor.Length); i++)
  159. {
  160. if (allArmor[i] != null)
  161. generalStore.baseInventory.Add(allArmor[i]);
  162. }
  163. // Add misc items
  164. foreach (var misc in allMisc)
  165. {
  166. if (misc != null && misc.itemType != ItemType.Consumable)
  167. generalStore.baseInventory.Add(misc);
  168. }
  169. Debug.Log($"Added mixed items to general store");
  170. }
  171. }
  172. [ContextMenu("Create Test Items")]
  173. public void CreateTestItems()
  174. {
  175. CreateTestWeapons();
  176. CreateTestArmor();
  177. CreateTestConsumables();
  178. CreateTestMiscItems();
  179. }
  180. private void CreateTestWeapons()
  181. {
  182. // This would create ScriptableObject assets - but that requires editor scripts
  183. // For now, just log what would be created
  184. Debug.Log("Test weapons that should be created:");
  185. Debug.Log("- Simple Sword (15g) - Basic iron blade");
  186. Debug.Log("- War Axe (22g) - Heavy two-handed axe");
  187. Debug.Log("- Hunting Bow (18g) - Reliable ranged weapon");
  188. Debug.Log("- Iron Dagger (8g) - Quick and light");
  189. Debug.Log("- Wooden Staff (12g) - For spellcasters");
  190. }
  191. private void CreateTestArmor()
  192. {
  193. Debug.Log("Test armor that should be created:");
  194. Debug.Log("- Leather Vest (10g) - Light chest protection");
  195. Debug.Log("- Iron Helmet (15g) - Sturdy head protection");
  196. Debug.Log("- Chainmail Shirt (35g) - Medium protection");
  197. Debug.Log("- Leather Boots (6g) - Basic foot protection");
  198. Debug.Log("- Iron Gauntlets (12g) - Hand protection");
  199. }
  200. private void CreateTestConsumables()
  201. {
  202. Debug.Log("Test consumables that should be created:");
  203. Debug.Log("- Health Potion (5g) - Restores 25 HP");
  204. Debug.Log("- Mana Potion (7g) - Restores 15 MP");
  205. Debug.Log("- Antidote (3g) - Cures poison");
  206. Debug.Log("- Stamina Elixir (4g) - Restores energy");
  207. }
  208. private void CreateTestMiscItems()
  209. {
  210. Debug.Log("Test misc items that should be created:");
  211. Debug.Log("- Hemp Rope (2g) - 50 feet of rope");
  212. Debug.Log("- Torch (1g) - Provides light");
  213. Debug.Log("- Lockpicks (8g) - For opening locks");
  214. Debug.Log("- Camping Kit (15g) - For resting outdoors");
  215. Debug.Log("- Waterskin (3g) - Holds water");
  216. }
  217. [ContextMenu("Setup Shop Manager")]
  218. public void SetupShopManager()
  219. {
  220. var shopManager = FindFirstObjectByType<TownShopManager>();
  221. if (shopManager == null)
  222. {
  223. var shopManagerGO = new GameObject("ShopManager");
  224. shopManagerGO.transform.SetParent(transform);
  225. shopManager = shopManagerGO.AddComponent<TownShopManager>();
  226. }
  227. // Create the shops array
  228. var shops = new List<TownShop>();
  229. if (weaponShop != null) shops.Add(weaponShop);
  230. if (armorShop != null) shops.Add(armorShop);
  231. if (potionShop != null) shops.Add(potionShop);
  232. if (generalStore != null) shops.Add(generalStore);
  233. shopManager.allShops = shops.ToArray();
  234. // Try to link UI
  235. var uiDocument = FindFirstObjectByType<UIDocument>();
  236. if (uiDocument != null)
  237. {
  238. shopManager.townUI = uiDocument;
  239. }
  240. Debug.Log($"Setup shop manager with {shops.Count} shops");
  241. }
  242. }