Kernel_bin.Command_abilities.cs 3.8 KB

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