ShopPlatform.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ScrapYard.API
  4. {
  5. public class ShopPlatform
  6. {
  7. public readonly ShopPlatformSpacingType Type;
  8. public readonly string Title;
  9. internal List<ShopPlatformEntry> Entries = new List<ShopPlatformEntry>();
  10. internal static Dictionary<string, ShopPlatform> ShopPlatforms = new Dictionary<string, ShopPlatform>();
  11. public static ShopPlatform DefaultObjects
  12. {
  13. get => ShopPlatforms["DefaultObjects"];
  14. }
  15. public static ShopPlatform DefaultBlocks
  16. {
  17. get => ShopPlatforms["DefaultBlocks"];
  18. }
  19. public static ShopPlatform DefaultWalls
  20. {
  21. get => ShopPlatforms["DefaultWalls"];
  22. }
  23. public ShopPlatform(string title, ShopPlatformSpacingType spacingType = ShopPlatformSpacingType.Normal)
  24. {
  25. this.Type = spacingType;
  26. this.Title = title;
  27. }
  28. public virtual ShopPlatform Register()
  29. {
  30. return Register(this.Title);
  31. }
  32. public virtual ShopPlatform Register(string id)
  33. {
  34. if (ShopPlatforms.ContainsKey(id))
  35. ShopPlatforms.Remove(id);
  36. ShopPlatforms.Add(id, this);
  37. return this;
  38. }
  39. public ShopPlatformSpacingType GetShopPlatformSpacingType()
  40. {
  41. return Type;
  42. }
  43. public void AddShopPlatformEntry(ShopPlatformEntry row)
  44. {
  45. foreach (var e in Entries)
  46. if (e.CurrencyItemID == row.CurrencyItemID
  47. && e.Id == row.Id
  48. && e.Quantity == row.Quantity
  49. && e.Price == row.Price
  50. && e.EntryType == row.EntryType)
  51. return;
  52. Entries.Add(row);
  53. }
  54. public void RemoveShopPlatformEntry(ShopPlatformEntry row)
  55. {
  56. Entries.Remove(row);
  57. }
  58. public ShopPlatformEntry[] GetShopPlatformEntries()
  59. {
  60. return Entries.ToArray();
  61. }
  62. public static ShopPlatform[] GetShopPlatforms()
  63. {
  64. return new List<ShopPlatform>(ShopPlatforms.Values).ToArray();
  65. }
  66. internal int GetSpacesPerRow()
  67. {
  68. int spaces = 0;
  69. switch (Type)
  70. {
  71. case ShopPlatformSpacingType.Normal:
  72. spaces = 7;
  73. break;
  74. case ShopPlatformSpacingType.Near:
  75. spaces = 13;
  76. break;
  77. case ShopPlatformSpacingType.Far:
  78. spaces = 3;
  79. break;
  80. }
  81. return spaces;
  82. }
  83. internal int GetRowsNeeded()
  84. {
  85. return ((Entries.Count - 1) / GetSpacesPerRow()) + 1;
  86. }
  87. internal static void Reset()
  88. {
  89. ShopPlatforms = new Dictionary<string, ShopPlatform>();
  90. }
  91. }
  92. public enum ShopPlatformSpacingType
  93. {
  94. Normal,
  95. Near,
  96. Far
  97. }
  98. public enum ShopPlatformEntryType
  99. {
  100. Item, Chip
  101. }
  102. }