CommandAbility.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System.Collections.Generic;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. namespace OpenVIII.Kernel
  6. {
  7. /// <summary>
  8. /// Command Abilities
  9. /// </summary>
  10. /// <see cref="https://github.com/alexfilth/doomtrain/wiki/Command-abilities"/>
  11. public sealed class CommandAbility : IAbility, ICommand
  12. {
  13. #region Fields
  14. /// <summary>
  15. /// Section Count
  16. /// </summary>
  17. public const int Count = 19;
  18. /// <summary>
  19. /// Section ID
  20. /// </summary>
  21. public const int ID = 12;
  22. #endregion Fields
  23. #region Constructors
  24. public static explicit operator BattleCommand(CommandAbility commandAbility) =>
  25. commandAbility.BattleCommand;
  26. private CommandAbility(BinaryReader br, int i, BattleCommand battleCommand)
  27. {
  28. //set a reference to it.
  29. BattleCommand = battleCommand;
  30. //0x0000 2 bytes Offset to name
  31. Name = Memory.Strings.Read(Strings.FileID.Kernel, ID, i * 2);
  32. //0x0002 2 bytes Offset to description
  33. Description = Memory.Strings.Read(Strings.FileID.Kernel, ID, i * 2 + 1);
  34. //0x0004 1 byte
  35. AP = br.ReadByte();
  36. //0x0005 1 byte
  37. Index = br.ReadByte();
  38. //0x0006 2 bytes
  39. Unknown0 = br.ReadBytes(2);
  40. }
  41. #endregion Constructors
  42. #region Properties
  43. public byte AP { get; }
  44. /// <summary>
  45. /// Battle Command related to this Command Abilities
  46. /// </summary>
  47. public BattleCommand BattleCommand { get; }
  48. public FF8String Description { get; }
  49. public Icons.ID Icon { get; } = Icons.ID.Ability_Command;
  50. /// <summary>
  51. /// Index to Battle commands
  52. /// </summary>
  53. public byte Index { get; }
  54. public FF8String Name { get; }
  55. public byte Palette { get; } = Ability.DefaultPalette;
  56. /// <summary>
  57. /// Unknown Bytes
  58. /// </summary>
  59. public byte[] Unknown0 { get; }
  60. /// <summary>
  61. /// Convert Command to Battle
  62. /// </summary>
  63. private static IReadOnlyDictionary<int, int> Convert { get; } = new Dictionary<int, int>
  64. {
  65. {0,2},
  66. {1,3},
  67. {2,6},
  68. {3,4},
  69. {4,0},
  70. {5,29},
  71. {6,30},
  72. {7,24},
  73. {8,25},
  74. {9,23},
  75. {10,28},
  76. {11,26},
  77. {12,32},
  78. {13,27},
  79. {14,33},
  80. {15,34},
  81. {16,31},
  82. {17,7},
  83. {18,38},
  84. };
  85. #endregion Properties
  86. #region Methods
  87. public static IReadOnlyDictionary<Abilities, CommandAbility> Read(BinaryReader br,
  88. IEnumerable<BattleCommand> battleCommands)
  89. {
  90. Debug.Assert(Convert.Count == Count);
  91. return Convert
  92. .ToDictionary(i => (Abilities)(i.Key + (int)Abilities.Magic),
  93. i => CreateInstance(br, i.Key, battleCommands.ElementAtOrDefault(i.Value)));
  94. }
  95. private static CommandAbility CreateInstance(BinaryReader br, int i, BattleCommand battleCommand)
  96. => new CommandAbility(br, i, battleCommand);
  97. #endregion Methods
  98. }
  99. }