Slot.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections.Generic;
  2. using System.Diagnostics.CodeAnalysis;
  3. using System.IO;
  4. using System.Linq;
  5. namespace OpenVIII
  6. {
  7. namespace Kernel
  8. {
  9. /// <summary>
  10. /// Slot Magic Data
  11. /// </summary>
  12. /// <see cref="https://github.com/alexfilth/doomtrain/wiki/Selphie-limit-break-sets"/>
  13. [SuppressMessage("ReSharper", "UnusedMember.Global")]
  14. public sealed class Slot
  15. {
  16. private const int Count = 8;
  17. #region Fields
  18. private readonly byte _count;
  19. private readonly byte _magicID;
  20. #endregion Fields
  21. #region Constructors
  22. private Slot(BinaryReader br) : this(magicID: br.ReadByte(), count: br.ReadByte()) =>
  23. (_magicID, _count) = (br.ReadByte(), br.ReadByte());
  24. private Slot((byte, byte) valueTuple) => (_magicID, _count) = valueTuple;
  25. private Slot(byte magicID, byte count) => (_magicID, _count) = (magicID, count);
  26. #endregion Constructors
  27. #region Properties
  28. public byte Casts => checked((byte)(Memory.Random.Next(_count) + 1));
  29. public MagicData MagicData => Memory.KernelBin.MagicData != null && _magicID < Memory.KernelBin.MagicData.Count ? Memory.KernelBin.MagicData[_magicID] : null;
  30. #endregion Properties
  31. #region Methods
  32. public static Slot CreateInstance((byte, byte) valueTuple) => new Slot(valueTuple);
  33. public static Slot CreateInstance(byte magicID, byte count) => new Slot(magicID, count);
  34. public static Slot CreateInstance(BinaryReader br) => new Slot(br);
  35. public static IReadOnlyList<Slot> Read(BinaryReader br)
  36. => Enumerable.Range(0, Count).Select(x => CreateInstance(br)).ToList().AsReadOnly();
  37. #endregion Methods
  38. }
  39. }
  40. }