using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace OpenVIII
{
namespace Kernel
{
#region Classes
///
/// Command Abilities
///
///
public sealed class CommandAbilities : Ability
{
#region Fields
///
/// Section Count
///
public const int Count = 19;
///
/// Icon for this type.
///
public new const Icons.ID Icon = Icons.ID.Ability_Command;
///
/// Section ID
///
public const int ID = 12;
#endregion Fields
#region Constructors
private CommandAbilities(FF8String name, FF8String description, byte ap, BattleCommand battleCommand, byte index, byte[] unknown0) :
base(name, description, ap, Icon) => (BattleCommand,Index,Unknown0) = (battleCommand,index,unknown0);
#endregion Constructors
#region Properties
///
/// Battle Command related to this Command Abilities
///
public BattleCommand BattleCommand { get; }
///
/// Index to Battle commands
///
public byte Index { get; }
///
/// Unknown Bytes
///
public byte[] Unknown0 { get; }
///
/// Convert Command to Battle
///
private static IReadOnlyDictionary Convert { get; } = new Dictionary
{
{0,2},
{1,3},
{2,6},
{3,4},
{4,0},
{5,29},
{6,30},
{7,24},
{8,25},
{9,23},
{10,28},
{11,26},
{12,32},
{13,27},
{14,33},
{15,34},
{16,31},
{17,7},
{18,38},
};
#endregion Properties
#region Methods
public static IReadOnlyDictionary Read(BinaryReader br)
=> Enumerable.Range(0, Count)
.ToDictionary(i => (Abilities)(i + (int)Abilities.Magic), i => CreateInstance(br, i));
private static CommandAbilities CreateInstance(BinaryReader br, int i)
{
//Get related BattleCommand and set a reference to it.
BattleCommand battleCommand = null;
if (Memory.Kernel_Bin.BattleCommands != null && Convert.TryGetValue(i, out int convertIndex) && Memory.Kernel_Bin.BattleCommands.Count > convertIndex)
battleCommand = Memory.Kernel_Bin.BattleCommands[convertIndex];
//0x0000 2 bytes Offset to name
FF8StringReference name = Memory.Strings.Read(Strings.FileID.KERNEL, ID, i * 2);
//0x0002 2 bytes Offset to description
FF8StringReference description = Memory.Strings.Read(Strings.FileID.KERNEL, ID, i * 2 + 1);
//0x0004 1 byte
byte ap = br.ReadByte();
//0x0005 1 byte
byte index = br.ReadByte();
//0x0006 2 bytes
byte[] unknown0 = br.ReadBytes(2);
return new CommandAbilities(name, description, ap, battleCommand, index, unknown0);
}
#endregion Methods
}
#endregion Classes
}
}