Shop.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. [CreateAssetMenu(fileName = "New Shop", menuName = "RPG/Shop")]
  5. public class Shop : ScriptableObject
  6. {
  7. [Header("Shop Info")]
  8. public string shopName;
  9. public string description;
  10. [Header("Shop Inventory")]
  11. public List<Item> availableItems = new List<Item>();
  12. [Header("Filters")]
  13. public bool sellWeapons = true;
  14. public bool sellArmor = true;
  15. public bool sellMiscellaneous = true;
  16. public List<Item> GetFilteredItems(ItemType? filterType = null, string searchTerm = "")
  17. {
  18. var filteredItems = availableItems.Where(item => item != null);
  19. // Apply type filter
  20. if (filterType.HasValue)
  21. {
  22. filteredItems = filteredItems.Where(item => item.itemType == filterType.Value);
  23. }
  24. // Apply search filter
  25. if (!string.IsNullOrEmpty(searchTerm))
  26. {
  27. filteredItems = filteredItems.Where(item => item.MatchesSearch(searchTerm));
  28. }
  29. // Apply shop type filters
  30. filteredItems = filteredItems.Where(item =>
  31. {
  32. switch (item.itemType)
  33. {
  34. case ItemType.Weapon:
  35. return sellWeapons;
  36. case ItemType.Armor:
  37. return sellArmor;
  38. case ItemType.Miscellaneous:
  39. case ItemType.Consumable:
  40. case ItemType.Tool:
  41. case ItemType.Accessory:
  42. return sellMiscellaneous;
  43. default:
  44. return false;
  45. }
  46. });
  47. return filteredItems.ToList();
  48. }
  49. }