ShopPlatform.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Ships.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.ItemID == row.ItemID
  48. && e.Quantity == row.Quantity
  49. && e.Price == row.Price)
  50. return;
  51. Entries.Add(row);
  52. }
  53. public void RemoveShopPlatformEntry(ShopPlatformEntry row)
  54. {
  55. Entries.Remove(row);
  56. }
  57. public ShopPlatformEntry[] GetShopPlatformEntries()
  58. {
  59. return Entries.ToArray();
  60. }
  61. public static ShopPlatform[] GetShopPlatforms()
  62. {
  63. return new List<ShopPlatform>(ShopPlatforms.Values).ToArray();
  64. }
  65. internal int GetSpacesPerRow()
  66. {
  67. int spaces = 0;
  68. switch (Type)
  69. {
  70. case ShopPlatformSpacingType.Normal:
  71. spaces = 7;
  72. break;
  73. case ShopPlatformSpacingType.Near:
  74. spaces = 13;
  75. break;
  76. case ShopPlatformSpacingType.Far:
  77. spaces = 3;
  78. break;
  79. }
  80. return spaces;
  81. }
  82. internal int GetRowsNeeded()
  83. {
  84. return ((Entries.Count - 1) / GetSpacesPerRow()) + 1;
  85. }
  86. internal static void Reset()
  87. {
  88. ShopPlatforms = new Dictionary<string, ShopPlatform>();
  89. }
  90. }
  91. public enum ShopPlatformSpacingType
  92. {
  93. Normal,
  94. Near,
  95. Far
  96. }
  97. }