GF.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. using Microsoft.Xna.Framework;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace OpenVIII.IGMData.Pool
  5. {
  6. public class GF : IGMData.Pool.Base<Saves.Data, GFs>
  7. {
  8. #region Properties
  9. public Dictionary<GFs, Characters> JunctionedGFs { get; private set; }
  10. public IEnumerable<GFs> UnlockedGFs { get; private set; }
  11. #endregion Properties
  12. #region Methods
  13. public static GF Create(Rectangle? pos = null, Damageable damageable = null, bool battle = false)
  14. {
  15. GF r = new GF
  16. {
  17. Count = 5,
  18. Depth = 3,
  19. CONTAINER = new IGMDataItem.Box
  20. {
  21. Pos = pos ?? new Rectangle(440, 149, 385, 193),
  22. Title = Icons.ID.GF
  23. },
  24. Rows = 4,
  25. DefaultPages = 4,
  26. Battle = battle
  27. };
  28. r.SetDamageable(damageable, null);
  29. r.Init();
  30. r.Refresh();
  31. r.Update();
  32. return r;
  33. }
  34. public override bool Inputs_CANCEL()
  35. {
  36. if (Battle) Hide();
  37. else
  38. {
  39. base.Inputs_CANCEL();
  40. Menu.IGM_Junction.Data[IGM_Junction.SectionName.TopMenu_GF_Group].Hide();
  41. Menu.IGM_Junction.SetMode(IGM_Junction.Mode.TopMenu_Junction);
  42. }
  43. return true;
  44. }
  45. public override bool Inputs_OKAY()
  46. {
  47. if (Battle)
  48. {
  49. base.Inputs_OKAY();
  50. Damageable.SetSummon(Contents[CURSOR_SELECT]);
  51. Hide();
  52. return true;
  53. }
  54. else
  55. {
  56. skipsnd = true;
  57. init_debugger_Audio.PlaySound(31);
  58. base.Inputs_OKAY();
  59. GFs select = Contents[CURSOR_SELECT];
  60. Characters characterid = Damageable.GetCharacterData(out Saves.CharacterData characterdata) && JunctionedGFs.ContainsKey(select) ?
  61. JunctionedGFs[select] : characterdata?.ID ?? Characters.Blank;
  62. if (characterid != Characters.Blank)
  63. {
  64. if (characterid != characterdata.ID)
  65. {
  66. //show error msg
  67. }
  68. else
  69. {
  70. //Purge everything that you can't have anymore. Because the GF provided for you.
  71. List<Kernel_bin.Abilities> a = (characterdata).UnlockedGFAbilities;
  72. characterdata.RemoveJunctionedGF(select);
  73. List<Kernel_bin.Abilities> b = (characterdata).UnlockedGFAbilities;
  74. foreach (Kernel_bin.Abilities r in a.Except(b).Where(v => !Kernel_bin.Junctionabilities.ContainsKey(v)))
  75. {
  76. if (Kernel_bin.Commandabilities.ContainsKey(r))
  77. {
  78. characterdata.Commands.Remove(r);
  79. characterdata.Commands.Add(Kernel_bin.Abilities.None);
  80. }
  81. else if (Kernel_bin.EquipableAbilities.ContainsKey(r))
  82. {
  83. characterdata.Abilities.Remove(r);
  84. characterdata.Abilities.Add(Kernel_bin.Abilities.None);
  85. }
  86. }
  87. foreach (Kernel_bin.Abilities r in a.Except(b).Where(v => Kernel_bin.Junctionabilities.ContainsKey(v)))
  88. {
  89. if (Kernel_bin.Stat2Ability.Any(item => item.Value == r))
  90. switch (r)
  91. {
  92. case Kernel_bin.Abilities.ST_Atk_J:
  93. characterdata.Stat_J[Kernel_bin.Stat.ST_Atk] = 0;
  94. break;
  95. case Kernel_bin.Abilities.EL_Atk_J:
  96. characterdata.Stat_J[Kernel_bin.Stat.EL_Atk] = 0;
  97. break;
  98. case Kernel_bin.Abilities.EL_Def_Jx1:
  99. case Kernel_bin.Abilities.EL_Def_Jx2:
  100. case Kernel_bin.Abilities.EL_Def_Jx4:
  101. byte count = 0;
  102. if (b.Contains(Kernel_bin.Abilities.EL_Def_Jx4))
  103. count = 4;
  104. else if (b.Contains(Kernel_bin.Abilities.EL_Def_Jx2))
  105. count = 2;
  106. else if (b.Contains(Kernel_bin.Abilities.EL_Def_Jx1))
  107. count = 1;
  108. for (; count < 4; count++)
  109. characterdata.Stat_J[Kernel_bin.Stat.EL_Def_1 + count] = 0;
  110. break;
  111. case Kernel_bin.Abilities.ST_Def_Jx1:
  112. case Kernel_bin.Abilities.ST_Def_Jx2:
  113. case Kernel_bin.Abilities.ST_Def_Jx4:
  114. count = 0;
  115. if (b.Contains(Kernel_bin.Abilities.ST_Def_Jx4))
  116. count = 4;
  117. else if (b.Contains(Kernel_bin.Abilities.ST_Def_Jx2))
  118. count = 2;
  119. else if (b.Contains(Kernel_bin.Abilities.ST_Def_Jx1))
  120. count = 1;
  121. for (; count < 4; count++)
  122. characterdata.Stat_J[Kernel_bin.Stat.ST_Def_1 + count] = 0;
  123. break;
  124. case Kernel_bin.Abilities.Abilityx3:
  125. case Kernel_bin.Abilities.Abilityx4:
  126. count = 2;
  127. if (b.Contains(Kernel_bin.Abilities.Abilityx4))
  128. count = 4;
  129. else if (b.Contains(Kernel_bin.Abilities.Abilityx3))
  130. count = 3;
  131. for (; count < characterdata.Abilities.Count; count++)
  132. characterdata.Abilities[count] = Kernel_bin.Abilities.None;
  133. break;
  134. default:
  135. characterdata.Stat_J[Kernel_bin.Stat2Ability.FirstOrDefault(x => x.Value == r).Key] = 0;
  136. break;
  137. }
  138. }
  139. Menu.IGM_Junction.Refresh();
  140. return true;
  141. }
  142. }
  143. }
  144. return false;
  145. }
  146. public override void Refresh()
  147. {
  148. Source = Memory.State;
  149. JunctionedGFs = Source.JunctionedGFs();
  150. UnlockedGFs = Source.UnlockedGFs;
  151. ((IGMDataItem.Icon)ITEM[Rows, 2]).Data = Battle ? Icons.ID.HP : Icons.ID.Size_16x08_Lv_;
  152. if (Damageable != null)
  153. {
  154. int pos = 0;
  155. int skip = Page * Rows;
  156. if (Damageable.GetCharacterData(out Saves.CharacterData c))
  157. {
  158. if (Battle)
  159. {
  160. AddGFs(ref pos, ref skip, g => JunctionedGFs.ContainsKey(g) && JunctionedGFs[g] == c.ID && !Source[g].IsDead, Font.ColorID.White);
  161. AddGFs(ref pos, ref skip, g => JunctionedGFs.ContainsKey(g) && JunctionedGFs[g] != c.ID && Source[g].IsDead, Font.ColorID.Red, true);
  162. }
  163. else
  164. {
  165. AddGFs(ref pos, ref skip, g => !JunctionedGFs.ContainsKey(g), Font.ColorID.White);
  166. AddGFs(ref pos, ref skip, g => JunctionedGFs.ContainsKey(g) && JunctionedGFs[g] == c.ID, Font.ColorID.Grey);
  167. AddGFs(ref pos, ref skip, g => JunctionedGFs.ContainsKey(g) && JunctionedGFs[g] != c.ID, Font.ColorID.Dark_Grey);
  168. UpdateCharacter();
  169. }
  170. }
  171. else if (Damageable.GetEnemy(out Enemy e))
  172. {
  173. var gfs = e.JunctionedGFs;
  174. foreach (GFs g in gfs)
  175. {
  176. if(!AddGF(ref pos, ref skip, g, Source[g].IsDead ? Font.ColorID.Red : Font.ColorID.White, Source[g].IsDead)) break;
  177. }
  178. }
  179. for (; pos < Rows; pos++)
  180. HideChild(pos);
  181. }
  182. base.Refresh();
  183. UpdateTitle();
  184. }
  185. public override void UpdateTitle()
  186. {
  187. base.UpdateTitle();
  188. if (Pages == 1)
  189. {
  190. ((IGMDataItem.Box)CONTAINER).Title = Icons.ID.GF;
  191. ITEM[Count - 1, 0].Hide();
  192. ITEM[Count - 2, 0].Hide();
  193. }
  194. else
  195. {
  196. ((IGMDataItem.Box)CONTAINER).Title = Icons.ID.GF_PG1 + checked((byte)Page);
  197. ITEM[Count - 1, 0].Show();
  198. ITEM[Count - 2, 0].Show();
  199. }
  200. }
  201. protected override void Init()
  202. {
  203. base.Init();
  204. SIZE[Rows] = SIZE[0];
  205. SIZE[Rows].Y = Y;
  206. ITEM[Rows, 2] = new IGMDataItem.Icon
  207. {
  208. Pos = new Rectangle(SIZE[Rows].X + SIZE[Rows].Width - (Battle ? 50 : 30), SIZE[Rows].Y, 0, 0),
  209. Scale = new Vector2(2.5f)
  210. };
  211. for (int i = 0; i < Rows;)
  212. AddGF(ref i, GFs.Blank);
  213. }
  214. protected override void InitShift(int i, int col, int row)
  215. {
  216. base.InitShift(i, col, row);
  217. SIZE[i].Inflate(-22, -8);
  218. SIZE[i].Offset(0, 12 + (-8 * row));
  219. }
  220. protected override void PAGE_NEXT()
  221. {
  222. do
  223. {
  224. base.PAGE_NEXT();
  225. Refresh();
  226. }
  227. while (!ITEM[0, 0].Enabled && Page != 0);
  228. }
  229. protected override void PAGE_PREV()
  230. {
  231. do
  232. {
  233. base.PAGE_PREV();
  234. Refresh();
  235. }
  236. while (!ITEM[0, 0].Enabled && Page != 0);
  237. }
  238. protected override void SetCursor_select(int value)
  239. {
  240. if (value != GetCursor_select())
  241. {
  242. base.SetCursor_select(value);
  243. UpdateCharacter();
  244. }
  245. }
  246. private void AddGF(ref int pos, GFs g, Font.ColorID color = Font.ColorID.White)
  247. {
  248. Contents[pos] = g;
  249. if (g != GFs.Blank)
  250. {
  251. ((IGMDataItem.Text)ITEM[pos, 0]).Data = Memory.Strings.GetName(g);
  252. ((IGMDataItem.Text)ITEM[pos, 0]).FontColor = color;
  253. ((IGMDataItem.Integer)ITEM[pos, 2]).Data = Battle ? Source.GFs[g].CurrentHP() : Source.GFs[g].Level;
  254. ShowChild(pos, g);
  255. if (Battle) ITEM[pos, 1].Hide();
  256. }
  257. else
  258. {
  259. if (ITEM[pos, 0] == null)
  260. ITEM[pos, 0] = new IGMDataItem.Text { Pos = SIZE[pos], FontColor = color };
  261. if (ITEM[pos, 1] == null)
  262. ITEM[pos, 1] = new IGMDataItem.Icon { Data = Icons.ID.JunctionSYM, Pos = new Rectangle(SIZE[pos].X + SIZE[pos].Width - 100, SIZE[pos].Y, 0, 0) };
  263. if (ITEM[pos, 2] == null)
  264. ITEM[pos, 2] = new IGMDataItem.Integer { Pos = new Rectangle(SIZE[pos].X + SIZE[pos].Width - 50, SIZE[pos].Y, 0, 0), Spaces = 3 };
  265. HideChild(pos);
  266. }
  267. pos++;
  268. }
  269. private void AddGFs(ref int pos, ref int skip, System.Func<GFs, bool> predicate, Font.ColorID colorid = Font.ColorID.White, bool blank = false)
  270. {
  271. foreach (GFs g in UnlockedGFs.Where(predicate))
  272. {
  273. if (!AddGF(ref pos, ref skip, g, colorid, blank)) break;
  274. }
  275. }
  276. private bool AddGF(ref int pos, ref int skip, GFs g, Font.ColorID colorid, bool blank)
  277. {
  278. if (pos >= Rows) return false;
  279. if (skip-- <= 0)
  280. {
  281. BLANKS[pos] = blank;
  282. AddGF(ref pos, g, colorid);
  283. }
  284. return true;
  285. }
  286. private void HideChild(int pos)
  287. {
  288. BLANKS[pos] = true;
  289. ITEM[pos, 0].Hide();
  290. ITEM[pos, 1].Hide();
  291. ITEM[pos, 2].Hide();
  292. }
  293. private void ShowChild(int pos, GFs g = GFs.Blank)
  294. {
  295. BLANKS[pos] = false;
  296. ITEM[pos, 0].Show();
  297. if (JunctionedGFs?.ContainsKey(g) ?? false && !Battle)
  298. ITEM[pos, 1].Show();
  299. else
  300. ITEM[pos, 1].Hide();
  301. ITEM[pos, 2].Show();
  302. }
  303. private void UpdateCharacter()
  304. {
  305. if (!Battle && Menu.IGM_Junction != null)
  306. {
  307. GFs g = Contents[CURSOR_SELECT];
  308. IGMDataItem.Box i =
  309. (IGMDataItem.Box)((IGM_Junction.IGMData_GF_Group)Menu.IGM_Junction.Data[IGM_Junction.SectionName.TopMenu_GF_Group]).ITEM[2, 0];
  310. i.Data = JunctionedGFs.Count > 0 && JunctionedGFs.ContainsKey(g) ? Memory.Strings.GetName(JunctionedGFs[g]) : null;
  311. }
  312. }
  313. #endregion Methods
  314. }
  315. }