Kernel_bin.Character_Stats.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace FF8
  4. {
  5. public partial class Kernel_bin
  6. {
  7. /// <summary>
  8. /// Character Stats from Kernel
  9. /// </summary>
  10. /// <see cref="https://github.com/alexfilth/doomtrain/wiki/Characters"/>
  11. /// <seealso cref="http://forums.qhimm.com/index.php?topic=16923.msg240609#msg240609"/>
  12. public class Character_Stats
  13. {
  14. public const int id = 6;
  15. public const int count = 11;
  16. public const ushort MAX_HP_VALUE = 9999;
  17. public const byte MAX_STAT_VALUE = 255;
  18. private Characters char_id;
  19. public FF8String Name => Memory.Strings.GetName((Faces.ID)char_id);
  20. public override string ToString() => Name;
  21. //public ushort Offset; //0x0000; 2 bytes; Offset to character name
  22. //Squall and Rinoa have name offsets of 0xFFFF because their name is in the save game data rather than kernel.bin.
  23. /// <summary>
  24. /// Crisis level modifier
  25. /// </summary>
  26. /// <see cref="https://finalfantasy.fandom.com/wiki/Crisis_Level#Crisis_Level"/>
  27. public byte Crisis; //0x0002; 1 byte; Crisis level hp multiplier
  28. public Gender Gender; //0x0003; 1 byte; Gender; 0x00 - Male 0x01 - Female
  29. public byte LimitID; //0x0004; 1 byte; Limit Break ID
  30. public byte LimitParam; //0x0005; 1 byte; Limit Break Param used for the power of each renzokuken hit before finisher
  31. private byte[] _EXP; //0x0006; 2 bytes; EXP modifier
  32. private byte[] _HP; //0x0008; 4 bytes; HP
  33. private byte[] _STR; //0x000C; 4 bytes; STR
  34. private byte[] _VIT; //0x0010; 4 bytes; VIT
  35. private byte[] _MAG; //0x0014; 4 bytes; MAG
  36. private byte[] _SPR; //0x0018; 4 bytes; SPR
  37. private byte[] _SPD; //0x001C; 4 bytes; SPD
  38. private byte[] _LUCK; //0x0020; 4 bytes; LUCK
  39. public void Read(BinaryReader br, Characters char_id)
  40. {
  41. this.char_id = char_id;
  42. //Offset = br.ReadUInt16(); //0x0000; 2 bytes; Offset to character name
  43. //Squall and Rinoa have name offsets of 0xFFFF because their name is in the save game data rather than kernel.bin.
  44. br.BaseStream.Seek(2, SeekOrigin.Current);
  45. Crisis = br.ReadByte(); //0x0002; 1 byte; Crisis level hp multiplier
  46. Gender = br.ReadByte() == 0 ? Gender.Male : Gender.Female; //0x0003; 1 byte; Gender; 0x00 - Male 0x01 - Female
  47. LimitID = br.ReadByte(); //0x0004; 1 byte; Limit Break ID
  48. LimitParam = br.ReadByte(); //0x0005; 1 byte; Limit Break Param used for the power of each renzokuken hit before finisher
  49. _EXP = br.ReadBytes(2); //0x0006; 2 bytes; EXP modifier
  50. _HP = br.ReadBytes(4); //0x0008; 4 bytes; HP
  51. _STR = br.ReadBytes(4); //0x000C; 4 bytes; STR
  52. _VIT = br.ReadBytes(4); //0x0010; 4 bytes; VIT
  53. _MAG = br.ReadBytes(4); //0x0014; 4 bytes; MAG
  54. _SPR = br.ReadBytes(4); //0x0018; 4 bytes; SPR
  55. _SPD = br.ReadBytes(4); //0x001C; 4 bytes; SPD
  56. _LUCK = br.ReadBytes(4); //0x0020; 4 bytes; LUCK
  57. int hp = HP(8);
  58. }
  59. public static Dictionary<Characters, Character_Stats> Read(BinaryReader br)
  60. {
  61. Dictionary<Characters, Character_Stats> ret = new Dictionary<Characters, Character_Stats>(count);
  62. for (int i = 0; i < count; i++)
  63. {
  64. Character_Stats tmp = new Character_Stats();
  65. tmp.Read(br, (Characters)i);
  66. ret[(Characters)i] = tmp;
  67. }
  68. return ret;
  69. }
  70. //public static Character_Stats[] Read(BinaryReader br)
  71. //{
  72. // Character_Stats[] ret = new Character_Stats[count];
  73. // for (int i = 0; i < count; i++)
  74. // {
  75. // Character_Stats tmp = new Character_Stats();
  76. // tmp.Read(br, (Characters)i);
  77. // ret[i] = tmp;
  78. // }
  79. // return ret;
  80. //}
  81. private const int _percent_mod = 100;
  82. /// <summary>
  83. /// Experence to reach level
  84. /// </summary>
  85. /// <param name="lvl">Level</param>
  86. /// <returns></returns>
  87. public int EXP(sbyte lvl) => ((lvl - 1) * (lvl - 1) * _EXP[1]) / 256 + (lvl - 1) * _EXP[0] * 10;
  88. /// <summary>
  89. /// </summary>
  90. /// <param name="lvl">Level</param>
  91. /// <param name="MagicID">Bonus Value of Junctioned Magic</param>
  92. /// <param name="magic_count">Total amount of Magic in slot</param>
  93. /// <param name="stat_bonus">Bonus integer based HP</param>
  94. /// <param name="percent_mod">50% = 50, 100%=100, etc</param>
  95. /// <returns></returns>
  96. public ushort HP(sbyte lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int percent_mod = 0)
  97. {
  98. int value = (((MagicData[MagicID].HP_J * magic_count) + stat_bonus + (lvl * _HP[0]) - ((10 * lvl * lvl) / _HP[1]) + _HP[2]) * (percent_mod + _percent_mod)) / 100;
  99. return (ushort)(value > MAX_HP_VALUE ? MAX_HP_VALUE : value);
  100. }
  101. public byte STR(int lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int percent_mod = _percent_mod, int weapon = 0)
  102. => STR_VIT_MAG_SPR(_STR[0], _STR[1], _STR[2], _STR[3], lvl, MagicData[MagicID].STR_J, magic_count, stat_bonus, percent_mod, weapon);
  103. public byte VIT(int lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int percent_mod = _percent_mod)
  104. => STR_VIT_MAG_SPR(_VIT[0], _VIT[1], _VIT[2], _VIT[3], lvl, MagicData[MagicID].VIT_J, magic_count, stat_bonus, percent_mod);
  105. public byte MAG(int lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int percent_mod = _percent_mod)
  106. => STR_VIT_MAG_SPR(_MAG[0], _MAG[1], _MAG[2], _MAG[3], lvl, MagicData[MagicID].MAG_J, magic_count, stat_bonus, percent_mod);
  107. public byte SPR(int lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int percent_mod = _percent_mod)
  108. => STR_VIT_MAG_SPR(_SPR[0], _SPR[1], _SPR[2], _SPR[3], lvl, MagicData[MagicID].SPR_J, magic_count, stat_bonus, percent_mod);
  109. private byte STR_VIT_MAG_SPR(int a, int b, int c, int d, int lvl, int magic_J_val, int magic_count, int stat_bonus, int percent_mod = 0, int UNK = 0)
  110. {
  111. int value = ((UNK + (magic_J_val * magic_count) / 100 + stat_bonus + ((lvl * a) / 10 + lvl / b - (lvl * lvl) / d / 2 + c) / 4) * (percent_mod + _percent_mod)) / 100;
  112. return (byte)(value > MAX_STAT_VALUE ? MAX_STAT_VALUE : value);
  113. }
  114. public byte SPD(int lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int percent_mod = _percent_mod)
  115. => SPD_LUCK(_SPD[0], _SPD[1], _SPD[2], _SPD[3], lvl, MagicData[MagicID].SPD_J, magic_count, stat_bonus, percent_mod);
  116. public byte LUCK(int lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int percent_mod = _percent_mod)
  117. => SPD_LUCK(_LUCK[0], _LUCK[1], _LUCK[2], _LUCK[3], lvl, MagicData[MagicID].LUCK_J, magic_count, stat_bonus, percent_mod);
  118. private byte SPD_LUCK(int a, int b, int c, int d, int lvl, int magic_J_val, int magic_count, int stat_bonus, int percent_mod = 0, int UNK = 0)
  119. {
  120. int value = ((UNK + (magic_J_val * magic_count) / 100 + stat_bonus + lvl / b - lvl / d + lvl * a + c) * (percent_mod + _percent_mod)) / 100;
  121. return (byte)(value > MAX_STAT_VALUE ? MAX_STAT_VALUE : value);
  122. }
  123. public byte EVA(int lvl, int MagicID = 0, int magic_count = 0, int stat_bonus = 0, int spd = 0, int percent_mod = 0)
  124. {
  125. int value = (((MagicData[MagicID].EVA_J * magic_count) / 100 + spd / 4) * (percent_mod + _percent_mod)) / 100;
  126. return (byte)(value > MAX_STAT_VALUE ? MAX_STAT_VALUE : value);
  127. }
  128. public byte HIT(int MagicID = 0, int magic_count = 0, int weapon = 0)
  129. {
  130. int value = MagicData[MagicID].HIT_J * magic_count + weapon;
  131. return (byte)(value > MAX_STAT_VALUE ? MAX_STAT_VALUE : value);
  132. }
  133. }
  134. }
  135. }