Saves.GFs.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace OpenVIII
  5. {
  6. public static partial class Saves
  7. {
  8. #region Fields
  9. /// <summary>
  10. /// Converts to GF value from GFflag using a dictionay.
  11. /// </summary>
  12. public static readonly IReadOnlyDictionary<GFflags, GFs> ConvertGFEnum = Enum.GetValues(typeof(GFflags)).Cast<GFflags>().Where(x => x > 0).ToDictionary(x => x, x => ConvertGFEnumLog(x));
  13. #endregion Fields
  14. #region Enums
  15. [Flags]
  16. public enum GFflags : ushort
  17. {
  18. None = 0,
  19. Quezacotl = 0x1,
  20. Shiva = 0x2,
  21. Ifrit = 0x4,
  22. Siren = 0x8,
  23. Brothers = 0x10,
  24. Diablos = 0x20,
  25. Carbuncle = 0x40,
  26. Leviathan = 0x80,
  27. Pandemona = 0x100,
  28. Cerberus = 0x200,
  29. Alexander = 0x400,
  30. Doomtrain = 0x800,
  31. Bahamut = 0x1000,
  32. Cactuar = 0x2000,
  33. Tonberry = 0x4000,
  34. Eden = 0x8000,
  35. }
  36. #endregion Enums
  37. #region Methods
  38. /// <summary>
  39. /// Converts to GF value from GFflag using math.
  40. /// </summary>
  41. /// <param name="flag">must be only one or all flags set</param>
  42. /// <returns></returns>
  43. /// <remarks>assuming the values are always in the same order</remarks>
  44. public static GFs ConvertGFEnumLog(GFflags flag)
  45. {
  46. if (flag == (GFflags)0xFFFF)
  47. return GFs.All;
  48. if ((flag & (flag - 1)) != 0)
  49. throw new Exception("ConvertGFEnumLog :: must only have one flag set");
  50. return flag.Equals(GFflags.None) ? GFs.Blank : (GFs)checked((byte)(Math.Log((double)flag, 2d)));
  51. }
  52. /// <summary>
  53. /// Converts to GF value to GFflag using math.
  54. /// </summary>
  55. /// <param name="gf">gf value</param>
  56. /// <returns></returns>
  57. /// <remarks>assuming the values are always in the same order</remarks>
  58. public static GFflags ConvertGFEnumLog(GFs gf)
  59. {
  60. if (gf.Equals(GFs.Blank)) return GFflags.None;
  61. if (gf.Equals(GFs.All)) return (GFflags)0xFFFF;
  62. return (GFflags)checked((int)Math.Pow(2, (double)gf));
  63. }
  64. #endregion Methods
  65. }
  66. }