PlayerSelectionScreen.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // PlayerSelectionScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. using Microsoft.Xna.Framework.Content;
  16. using RolePlayingGameData;
  17. #endregion
  18. namespace RolePlaying
  19. {
  20. /// <summary>
  21. /// Shows a list of players and allows the user to equip or use items.
  22. /// </summary>
  23. class PlayerSelectionScreen : GameScreen
  24. {
  25. private Gear usedGear;
  26. #region Player Data
  27. private bool isUseAllowed;
  28. private List<int> selectedPlayers;
  29. private StatisticsValue previewStatisticsModifier = new StatisticsValue();
  30. private Int32Range previewDamageRange = new Int32Range();
  31. private Int32Range previewHealthDefenseRange = new Int32Range();
  32. private Int32Range previewMagicDefenseRange = new Int32Range();
  33. #endregion
  34. #region Graphics Data
  35. private Texture2D playerInfoScreen;
  36. private Texture2D backButton;
  37. private Texture2D selectButton;
  38. private Texture2D scoreBoard;
  39. private Texture2D fadeTexture;
  40. private Texture2D tickMarkTexture;
  41. private Texture2D lineTexture;
  42. private Texture2D playerSelTexture;
  43. private Texture2D playerUnSelTexture;
  44. private readonly Vector2 textPosition = new Vector2(264f, 199f);
  45. private Vector2 currentTextPosition;
  46. private readonly Vector2 namePosition = new Vector2(394f, 39f);
  47. private Vector2 titlePosition;
  48. private readonly Vector2 scoreBoardPosition = new Vector2(972f, 235f);
  49. private readonly Vector2 selectButtonPosition = new Vector2(891f, 550f);
  50. private readonly Vector2 backButtonPosition = new Vector2(331f, 550f);
  51. private Vector2 popupPosition;
  52. private Vector2 playerNamePosition;
  53. private Vector2 portraitPosition;
  54. private readonly Point startPositionScreen = new Point(204, 44);
  55. private readonly Rectangle screenRect = new Rectangle(0, 0, 872, 633);
  56. #endregion
  57. #region Selection Data
  58. private int selectionMark;
  59. private bool isGearUsed;
  60. private int startIndex;
  61. private int endIndex;
  62. private int drawMaximum;
  63. #endregion
  64. #region Initialization
  65. /// <summary>
  66. /// Creates a new PlayerSelectionScreen object.
  67. /// </summary>
  68. public PlayerSelectionScreen(Gear gear)
  69. {
  70. // check the parameter
  71. if (gear == null)
  72. {
  73. throw new ArgumentNullException("gear");
  74. }
  75. this.IsPopup = true;
  76. this.usedGear = gear;
  77. isGearUsed = false;
  78. drawMaximum = 3;
  79. selectedPlayers = new List<int>();
  80. ResetValues();
  81. Reset();
  82. }
  83. /// <summary>
  84. /// Load the graphics content from the content manager.
  85. /// </summary>
  86. public override void LoadContent()
  87. {
  88. Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
  89. ContentManager content = ScreenManager.Game.Content;
  90. fadeTexture = content.Load<Texture2D>(@"Textures\GameScreens\FadeScreen");
  91. // Display screens
  92. playerInfoScreen =
  93. content.Load<Texture2D>(@"Textures\GameScreens\PopupScreen");
  94. popupPosition = new Vector2(viewport.Width / 2f, viewport.Height / 2f);
  95. popupPosition.X -= playerInfoScreen.Width / 2;
  96. popupPosition.Y -= playerInfoScreen.Height / 2;
  97. scoreBoard =
  98. content.Load<Texture2D>(@"Textures\GameScreens\CountShieldWithArrow");
  99. lineTexture =
  100. content.Load<Texture2D>(@"Textures\GameScreens\SeparationLine");
  101. selectButton = content.Load<Texture2D>(@"Textures\Buttons\AButton");
  102. backButton = content.Load<Texture2D>(@"Textures\Buttons\BButton");
  103. tickMarkTexture = content.Load<Texture2D>(@"Textures\GameScreens\TickMark");
  104. playerSelTexture =
  105. content.Load<Texture2D>(@"Textures\GameScreens\PlayerSelected");
  106. playerUnSelTexture =
  107. content.Load<Texture2D>(@"Textures\GameScreens\PlayerUnSelected");
  108. titlePosition = new Vector2(
  109. (viewport.Width - Fonts.HeaderFont.MeasureString("Choose Player").X) / 2,
  110. (viewport.Height - playerInfoScreen.Height) / 2 + 70f);
  111. }
  112. /// <summary>
  113. /// Reset the selection and player data.
  114. /// </summary>
  115. public void Reset()
  116. {
  117. if (selectionMark != -1)
  118. {
  119. isUseAllowed = true;
  120. if (usedGear != null)
  121. {
  122. isUseAllowed = usedGear.CheckRestrictions(
  123. Session.Party.Players[selectionMark]);
  124. }
  125. CalculateSelectedPlayers();
  126. CalculateForPreview();
  127. }
  128. }
  129. /// <summary>
  130. /// Reset the Variables to the Initial values
  131. /// </summary>
  132. private void ResetValues()
  133. {
  134. startIndex = 0;
  135. if (drawMaximum > Session.Party.Players.Count)
  136. {
  137. endIndex = Session.Party.Players.Count;
  138. }
  139. else
  140. {
  141. endIndex = drawMaximum;
  142. }
  143. selectionMark = 0;
  144. CalculateSelectedPlayers();
  145. }
  146. #endregion
  147. #region Updating
  148. /// <summary>
  149. /// Handle user input.
  150. /// </summary>
  151. public override void HandleInput()
  152. {
  153. // exit the screen
  154. if (InputManager.IsActionTriggered(InputManager.Action.Back))
  155. {
  156. ExitScreen();
  157. return;
  158. }
  159. // use the item or close the screen
  160. else if (isUseAllowed &&
  161. InputManager.IsActionTriggered(InputManager.Action.Ok))
  162. {
  163. if (isGearUsed)
  164. {
  165. ExitScreen();
  166. return;
  167. }
  168. else
  169. {
  170. if (usedGear is Equipment)
  171. {
  172. Equipment equipment = usedGear as Equipment;
  173. Equipment oldEquipment = null;
  174. if (Session.Party.Players[selectionMark].Equip(equipment,
  175. out oldEquipment))
  176. {
  177. Session.Party.RemoveFromInventory(usedGear, 1);
  178. if (oldEquipment != null)
  179. {
  180. Session.Party.AddToInventory(oldEquipment, 1);
  181. }
  182. isGearUsed = true;
  183. }
  184. }
  185. else if (usedGear is Item)
  186. {
  187. Item item = usedGear as Item;
  188. if ((item.Usage & Item.ItemUsage.NonCombat) > 0)
  189. {
  190. if (Session.Party.RemoveFromInventory(item, 1))
  191. {
  192. Session.Party.Players[selectionMark].
  193. StatisticsModifiers +=
  194. item.TargetEffectRange.GenerateValue(Session.Random);
  195. Session.Party.Players[selectionMark].StatisticsModifiers.
  196. ApplyMaximum(new StatisticsValue());
  197. isGearUsed = true;
  198. }
  199. else
  200. {
  201. ExitScreen();
  202. return;
  203. }
  204. }
  205. }
  206. }
  207. return;
  208. }
  209. // cursor up
  210. else if (!isGearUsed &&
  211. InputManager.IsActionTriggered(InputManager.Action.CursorUp))
  212. {
  213. if (selectionMark > 0)
  214. {
  215. ResetFromPreview();
  216. selectionMark--;
  217. if (selectionMark < startIndex)
  218. {
  219. startIndex--;
  220. endIndex--;
  221. }
  222. isUseAllowed = true;
  223. if (usedGear != null)
  224. {
  225. isUseAllowed = usedGear.CheckRestrictions(
  226. Session.Party.Players[selectionMark]);
  227. }
  228. CalculateSelectedPlayers();
  229. CalculateForPreview();
  230. }
  231. }
  232. // cursor down
  233. else if (!isGearUsed &&
  234. InputManager.IsActionTriggered(InputManager.Action.CursorDown))
  235. {
  236. isGearUsed = false;
  237. if (selectionMark < Session.Party.Players.Count - 1)
  238. {
  239. ResetFromPreview();
  240. selectionMark++;
  241. if (selectionMark == endIndex)
  242. {
  243. endIndex++;
  244. startIndex++;
  245. }
  246. isUseAllowed = true;
  247. if (usedGear != null)
  248. {
  249. isUseAllowed = usedGear.CheckRestrictions(
  250. Session.Party.Players[selectionMark]);
  251. }
  252. CalculateSelectedPlayers();
  253. CalculateForPreview();
  254. }
  255. }
  256. }
  257. #endregion
  258. #region Drawing
  259. /// <summary>
  260. /// Draw the character stats screen and text
  261. /// </summary>
  262. public override void Draw(GameTime gameTime)
  263. {
  264. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  265. spriteBatch.Begin();
  266. spriteBatch.Draw(fadeTexture, new Rectangle(0, 0, 1280, 720), Color.White);
  267. currentTextPosition = textPosition;
  268. spriteBatch.Draw(playerInfoScreen, popupPosition, Color.White);
  269. // DrawButtons
  270. DrawButtons();
  271. // Draw Heros
  272. DrawViewablePlayers();
  273. // Display Title of the Screen
  274. spriteBatch.DrawString(Fonts.HeaderFont, "Choose Player", titlePosition,
  275. Fonts.TitleColor);
  276. spriteBatch.End();
  277. }
  278. /// <summary>
  279. /// Draw a player's Details
  280. /// </summary>
  281. /// <param name="player">Players whose details have to be drawn</param>
  282. /// <param name="isSelected">Whether player is selected or not</param>
  283. private void DrawPlayerDetails(Player player, bool isSelected)
  284. {
  285. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  286. Vector2 position = new Vector2();
  287. Vector2 equipEffectPosition = new Vector2();
  288. Color textColor;
  289. Color nameColor, classColor, levelColor;
  290. string text;
  291. int length;
  292. if (isSelected)
  293. {
  294. textColor = Color.Black;
  295. nameColor = new Color(241, 173, 10);
  296. classColor = new Color(207, 131, 42);
  297. levelColor = new Color(151, 150, 148);
  298. }
  299. else
  300. {
  301. textColor = Color.DarkGray;
  302. nameColor = new Color(117, 88, 18);
  303. classColor = new Color(125, 78, 24);
  304. levelColor = new Color(110, 106, 99);
  305. }
  306. position = currentTextPosition;
  307. position.Y -= 5f;
  308. if (isSelected)
  309. {
  310. spriteBatch.Draw(playerSelTexture, position, Color.White);
  311. }
  312. else
  313. {
  314. spriteBatch.Draw(playerUnSelTexture, position, Color.White);
  315. }
  316. position.Y += 5f;
  317. // Draw portrait
  318. portraitPosition.X = position.X + 3f;
  319. portraitPosition.Y = position.Y + 16f;
  320. spriteBatch.Draw(player.ActivePortraitTexture, portraitPosition,
  321. Color.White);
  322. if (isGearUsed && isSelected)
  323. {
  324. spriteBatch.Draw(tickMarkTexture, position, Color.White);
  325. }
  326. // Draw Player Name
  327. playerNamePosition.X = position.X + 90f;
  328. playerNamePosition.Y = position.Y + 15f;
  329. spriteBatch.DrawString(Fonts.PlayerNameFont,
  330. player.Name.ToUpper(), playerNamePosition, nameColor);
  331. // Draw Player Class
  332. playerNamePosition.Y += 25f;
  333. spriteBatch.DrawString(Fonts.PlayerNameFont, player.CharacterClass.Name,
  334. playerNamePosition, classColor);
  335. // Draw Player Level
  336. playerNamePosition.Y += 26f;
  337. spriteBatch.DrawString(Fonts.PlayerNameFont, "LEVEL: " +
  338. player.CharacterLevel,
  339. playerNamePosition, levelColor);
  340. position = currentTextPosition;
  341. position.X += playerSelTexture.Width + 5f;
  342. DrawPlayerStats(player, isSelected, ref position);
  343. equipEffectPosition = position;
  344. equipEffectPosition.X += 100f;
  345. equipEffectPosition.Y = currentTextPosition.Y;
  346. text = "Weapon Atk: (";
  347. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  348. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  349. Fonts.CountColor);
  350. equipEffectPosition.X += length;
  351. // calculate weapon damage
  352. previewDamageRange = new Int32Range();
  353. previewHealthDefenseRange = new Int32Range();
  354. previewMagicDefenseRange = new Int32Range();
  355. if (isSelected && isUseAllowed && !isGearUsed)
  356. {
  357. if (usedGear is Equipment)
  358. {
  359. Equipment equipment = usedGear as Equipment;
  360. if (equipment is Weapon)
  361. {
  362. Weapon weapon = equipment as Weapon;
  363. previewDamageRange = weapon.TargetDamageRange;
  364. Weapon equippedWeapon = player.GetEquippedWeapon();
  365. if (equippedWeapon != null)
  366. {
  367. previewDamageRange -= equippedWeapon.TargetDamageRange;
  368. previewDamageRange -=
  369. equippedWeapon.OwnerBuffStatistics.PhysicalOffense;
  370. previewHealthDefenseRange -=
  371. equippedWeapon.OwnerBuffStatistics.PhysicalDefense;
  372. previewMagicDefenseRange -=
  373. equippedWeapon.OwnerBuffStatistics.MagicalDefense;
  374. }
  375. }
  376. else if (equipment is Armor)
  377. {
  378. Armor armor = usedGear as Armor;
  379. previewHealthDefenseRange = armor.OwnerHealthDefenseRange;
  380. previewMagicDefenseRange = armor.OwnerMagicDefenseRange;
  381. Armor equippedArmor = player.GetEquippedArmor(armor.Slot);
  382. if (equippedArmor != null)
  383. {
  384. previewHealthDefenseRange -=
  385. equippedArmor.OwnerHealthDefenseRange;
  386. previewMagicDefenseRange -=
  387. equippedArmor.OwnerMagicDefenseRange;
  388. previewDamageRange -=
  389. equippedArmor.OwnerBuffStatistics.PhysicalOffense;
  390. previewHealthDefenseRange -=
  391. equippedArmor.OwnerBuffStatistics.PhysicalDefense;
  392. previewMagicDefenseRange -=
  393. equippedArmor.OwnerBuffStatistics.MagicalDefense;
  394. }
  395. }
  396. previewDamageRange += equipment.OwnerBuffStatistics.PhysicalOffense;
  397. previewHealthDefenseRange +=
  398. equipment.OwnerBuffStatistics.PhysicalDefense;
  399. previewMagicDefenseRange +=
  400. equipment.OwnerBuffStatistics.MagicalDefense;
  401. }
  402. }
  403. Int32Range drawWeaponDamageRange = player.TargetDamageRange +
  404. previewDamageRange + player.CharacterStatistics.PhysicalOffense;
  405. text = drawWeaponDamageRange.Minimum.ToString();
  406. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  407. textColor = GetRangeColor(previewDamageRange.Minimum, isSelected);
  408. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  409. equipEffectPosition, textColor);
  410. equipEffectPosition.X += length;
  411. text = ",";
  412. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  413. spriteBatch.DrawString(Fonts.DescriptionFont,
  414. text, equipEffectPosition,
  415. Fonts.CountColor);
  416. equipEffectPosition.X += length;
  417. text = drawWeaponDamageRange.Maximum.ToString(); ;
  418. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  419. textColor = GetRangeColor(previewDamageRange.Maximum, isSelected);
  420. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  421. equipEffectPosition, textColor);
  422. equipEffectPosition.X += length;
  423. spriteBatch.DrawString(Fonts.DescriptionFont, ")", equipEffectPosition,
  424. Fonts.CountColor);
  425. equipEffectPosition.X = position.X + 100f;
  426. equipEffectPosition.Y += Fonts.DescriptionFont.LineSpacing;
  427. text = "Weapon Def: (";
  428. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  429. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  430. Fonts.CountColor);
  431. equipEffectPosition.X += length;
  432. Int32Range drawHealthDefenseRange = player.HealthDefenseRange +
  433. previewHealthDefenseRange + player.CharacterStatistics.PhysicalDefense;
  434. text = drawHealthDefenseRange.Minimum.ToString();
  435. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  436. textColor = GetRangeColor(previewHealthDefenseRange.Minimum, isSelected);
  437. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  438. equipEffectPosition, textColor);
  439. equipEffectPosition.X += length;
  440. text = ",";
  441. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  442. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  443. Fonts.CountColor);
  444. equipEffectPosition.X += length;
  445. text = drawHealthDefenseRange.Maximum.ToString();
  446. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  447. textColor = GetRangeColor(previewHealthDefenseRange.Maximum, isSelected);
  448. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  449. equipEffectPosition, textColor);
  450. equipEffectPosition.X += length;
  451. spriteBatch.DrawString(Fonts.DescriptionFont, ")", equipEffectPosition,
  452. Fonts.CountColor);
  453. equipEffectPosition.X = position.X + 100f;
  454. equipEffectPosition.Y += Fonts.DescriptionFont.LineSpacing;
  455. text = "Spell Def: (";
  456. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  457. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  458. Fonts.CountColor);
  459. equipEffectPosition.X += length;
  460. Int32Range drawMagicDefenseRange = player.MagicDefenseRange +
  461. previewMagicDefenseRange + player.CharacterStatistics.MagicalDefense;
  462. text = drawMagicDefenseRange.Minimum.ToString();
  463. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  464. textColor = GetRangeColor(previewMagicDefenseRange.Minimum, isSelected);
  465. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  466. equipEffectPosition, textColor);
  467. equipEffectPosition.X += length;
  468. text = ",";
  469. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  470. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  471. Fonts.CountColor);
  472. equipEffectPosition.X += length;
  473. text = drawMagicDefenseRange.Maximum.ToString();
  474. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  475. textColor = GetRangeColor(previewMagicDefenseRange.Maximum, isSelected);
  476. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  477. equipEffectPosition, textColor);
  478. equipEffectPosition.X += length;
  479. spriteBatch.DrawString(Fonts.DescriptionFont, ")", equipEffectPosition,
  480. Fonts.CountColor);
  481. currentTextPosition.Y = position.Y + 3f;
  482. spriteBatch.Draw(lineTexture, currentTextPosition, Color.White);
  483. currentTextPosition.Y += 20f;
  484. }
  485. /// <summary>
  486. /// Draw a Player's stats
  487. /// </summary>
  488. /// <param name="player">Player whose stats have to be drawn</param>
  489. /// <param name="isSelected">Whether player is selected or not</param>
  490. /// <param name="position">Position as to
  491. /// where to start drawing the stats</param>
  492. private void DrawPlayerStats(Player player, bool isSelected,
  493. ref Vector2 position)
  494. {
  495. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  496. Color color;
  497. string detail1, detail2;
  498. float length1, length2;
  499. StatisticsValue playersStatisticsModifier = new StatisticsValue();
  500. if (isSelected && isUseAllowed && !isGearUsed)
  501. {
  502. playersStatisticsModifier = previewStatisticsModifier;
  503. if (usedGear is Armor)
  504. {
  505. Armor armor = usedGear as Armor;
  506. Armor existingArmor = player.GetEquippedArmor(armor.Slot);
  507. if (existingArmor != null)
  508. {
  509. playersStatisticsModifier -= existingArmor.OwnerBuffStatistics;
  510. }
  511. }
  512. else if (usedGear is Weapon)
  513. {
  514. Weapon weapon = usedGear as Weapon;
  515. Weapon existingWeapon = player.GetEquippedWeapon();
  516. if (existingWeapon != null)
  517. {
  518. playersStatisticsModifier -= existingWeapon.OwnerBuffStatistics;
  519. }
  520. }
  521. }
  522. // Calculate HP and MP string Length
  523. detail1 = "HP: " + player.CurrentStatistics.HealthPoints + "/" +
  524. player.CharacterStatistics.HealthPoints;
  525. length1 = Fonts.DescriptionFont.MeasureString(detail1).X;
  526. detail2 = "MP: " + player.CurrentStatistics.MagicPoints + "/" +
  527. player.CharacterStatistics.MagicPoints;
  528. length2 = Fonts.DescriptionFont.MeasureString(detail2).X;
  529. StatisticsValue drawCurrentStatistics = player.CurrentStatistics;
  530. StatisticsValue drawCharacterStatistics = player.CharacterStatistics;
  531. if (isSelected)
  532. {
  533. drawCurrentStatistics += playersStatisticsModifier;
  534. drawCharacterStatistics += playersStatisticsModifier;
  535. }
  536. // Draw the character Health Points
  537. color = GetStatColor(playersStatisticsModifier.HealthPoints, isSelected);
  538. spriteBatch.DrawString(Fonts.DescriptionFont, "HP: " +
  539. drawCurrentStatistics.HealthPoints + "/" +
  540. drawCharacterStatistics.HealthPoints,
  541. position, color);
  542. // Draw the character Mana Points
  543. position.Y += Fonts.DescriptionFont.LineSpacing;
  544. color = GetStatColor(playersStatisticsModifier.MagicPoints, isSelected);
  545. spriteBatch.DrawString(Fonts.DescriptionFont, "MP: " +
  546. drawCurrentStatistics.MagicPoints + "/" +
  547. drawCharacterStatistics.MagicPoints,
  548. position, color);
  549. // Draw the physical offense
  550. position.X += 150f;
  551. position.Y -= Fonts.DescriptionFont.LineSpacing;
  552. color = GetStatColor(playersStatisticsModifier.PhysicalOffense, isSelected);
  553. spriteBatch.DrawString(Fonts.DescriptionFont, "PO: " +
  554. drawCurrentStatistics.PhysicalOffense, position, color);
  555. // Draw the physical defense
  556. position.Y += Fonts.DescriptionFont.LineSpacing;
  557. color = GetStatColor(playersStatisticsModifier.PhysicalDefense, isSelected);
  558. spriteBatch.DrawString(Fonts.DescriptionFont, "PD: " +
  559. drawCurrentStatistics.PhysicalDefense, position, color);
  560. // Draw the Magic offense
  561. position.Y += Fonts.DescriptionFont.LineSpacing;
  562. color = GetStatColor(playersStatisticsModifier.MagicalOffense, isSelected);
  563. spriteBatch.DrawString(Fonts.DescriptionFont, "MO: " +
  564. drawCurrentStatistics.MagicalOffense, position, color);
  565. // Draw the Magical defense
  566. position.Y += Fonts.DescriptionFont.LineSpacing;
  567. color = GetStatColor(playersStatisticsModifier.MagicalDefense, isSelected);
  568. spriteBatch.DrawString(Fonts.DescriptionFont, "MD: " +
  569. drawCurrentStatistics.MagicalDefense, position, color);
  570. position.Y += Fonts.DescriptionFont.LineSpacing;
  571. }
  572. /// <summary>
  573. /// Draw the Character Stats and Character Icons
  574. /// </summary>
  575. private void DrawViewablePlayers()
  576. {
  577. bool isSelectedPlayer = false;
  578. // Compute Start Index
  579. if (startIndex < 0)
  580. {
  581. startIndex = 0;
  582. selectionMark = 0;
  583. CalculateSelectedPlayers();
  584. }
  585. // Compute EndIndex
  586. if (endIndex > Session.Party.Players.Count)
  587. {
  588. endIndex = Session.Party.Players.Count;
  589. selectionMark = endIndex - 1;
  590. CalculateSelectedPlayers();
  591. }
  592. for (int playerIndex = startIndex; playerIndex < endIndex; playerIndex++)
  593. {
  594. isSelectedPlayer = false;
  595. for (int i = 0; i < selectedPlayers.Count; i++)
  596. {
  597. if (playerIndex == selectedPlayers[i])
  598. {
  599. isSelectedPlayer = true;
  600. break;
  601. }
  602. }
  603. DrawPlayerDetails(Session.Party.Players[playerIndex], isSelectedPlayer);
  604. }
  605. // Draw the Scroll button only if player count exceed the Max items
  606. if (selectionMark != -1)
  607. {
  608. if (Session.Party.Players.Count > drawMaximum)
  609. {
  610. DrawCharacterCount();
  611. }
  612. }
  613. }
  614. /// <summary>
  615. /// Draw the Current player Selected and total no.of
  616. /// Session.Party.Players in the list
  617. /// </summary>
  618. private void DrawCharacterCount()
  619. {
  620. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  621. Vector2 position = new Vector2();
  622. // Draw the ScoreBoard
  623. spriteBatch.Draw(scoreBoard, scoreBoardPosition, Color.White);
  624. position = scoreBoardPosition;
  625. position.X += 29;
  626. position.Y += 100;
  627. // Display Current Selected Player
  628. spriteBatch.DrawString(Fonts.GearInfoFont,
  629. (selectionMark + 1).ToString(),
  630. position, Fonts.CountColor);
  631. position.Y += 30;
  632. // Display Total Players count
  633. spriteBatch.DrawString(Fonts.GearInfoFont,
  634. Session.Party.Players.Count.ToString(), position, Fonts.CountColor);
  635. }
  636. /// <summary>
  637. /// Draw Select and Drop Button
  638. /// </summary>
  639. private void DrawButtons()
  640. {
  641. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  642. Vector2 position;
  643. Vector2 placeTextMid;
  644. string selectText;
  645. if (usedGear == null)
  646. {
  647. selectText = "Use";
  648. }
  649. else if (usedGear is Item)
  650. {
  651. selectText = "Use";
  652. }
  653. else
  654. {
  655. selectText = "Equip";
  656. }
  657. if (CombatEngine.IsActive)
  658. {
  659. if (selectionMark != -1)
  660. {
  661. isUseAllowed = true;
  662. }
  663. }
  664. if (isUseAllowed && !isGearUsed)
  665. {
  666. // Draw Select Button
  667. spriteBatch.Draw(selectButton, selectButtonPosition, Color.White);
  668. // Display Text
  669. position = selectButtonPosition;
  670. placeTextMid = Fonts.ButtonNamesFont.MeasureString(selectText);
  671. position.X -= placeTextMid.X + 10;
  672. spriteBatch.DrawString(Fonts.ButtonNamesFont, selectText, position,
  673. Color.White);
  674. }
  675. // Draw Back Button
  676. spriteBatch.Draw(backButton, backButtonPosition, Color.White);
  677. // Display Back Text
  678. position = backButtonPosition;
  679. position.X += backButton.Width + 10;
  680. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back", position, Color.White);
  681. }
  682. /// <summary>
  683. /// Gets Font color for stat display based on whether the stat has changed
  684. /// </summary>
  685. /// <param name="change">How the stat has changed</param>
  686. /// <param name="isSelected">Character's selection status</param>
  687. /// <returns>Returns Color for display of stat</returns>
  688. private Color GetStatColor(int change, bool isSelected)
  689. {
  690. if (isSelected && isUseAllowed)
  691. {
  692. if (change < 0)
  693. {
  694. return Color.Red;
  695. }
  696. else if (change > 0)
  697. {
  698. return Color.Green;
  699. }
  700. // fall through when == 0
  701. }
  702. return Fonts.CountColor;
  703. }
  704. /// <summary>
  705. /// Decides min/max of Weapon Attack/Weapon Def/Spell Def of player
  706. /// </summary>
  707. /// <param name="value">Describes if min/max of range has
  708. /// changed or not</param>
  709. /// <param name="isSelected">Character's selection status</param>
  710. /// <returns>Returns the color to display min/max of the range</returns>
  711. private Color GetRangeColor(int value, bool isSelected)
  712. {
  713. if (isSelected && isUseAllowed)
  714. {
  715. if (value > 0)
  716. {
  717. return Color.Green;
  718. }
  719. else if (value < 0)
  720. {
  721. return Color.Red;
  722. }
  723. else
  724. {
  725. return Fonts.CountColor;
  726. }
  727. }
  728. return Fonts.CountColor;
  729. }
  730. #endregion
  731. #region Preview Calculation
  732. /// <summary>
  733. /// Calculate selected Session.Party.Players around on the selection mark
  734. /// based on the range for items. Incase of equipment range is considered as 0
  735. /// </summary>
  736. private void CalculateSelectedPlayers()
  737. {
  738. int range = 0;
  739. int selMark = selectionMark;
  740. selectedPlayers.Clear();
  741. Item item = usedGear as Item;
  742. if (item != null)
  743. {
  744. range = item.AdjacentTargets;
  745. }
  746. selectedPlayers.Add(selMark);
  747. for (int i = 1; i <= range; i++)
  748. {
  749. if ((selMark >= i) &&
  750. !Session.Party.Players[selMark - i].IsDeadOrDying)
  751. {
  752. selectedPlayers.Add(selMark - i);
  753. }
  754. if ((selMark < (Session.Party.Players.Count - i)) &&
  755. !Session.Party.Players[selMark + i].IsDeadOrDying)
  756. {
  757. selectedPlayers.Add(selMark + i);
  758. }
  759. }
  760. }
  761. /// <summary>
  762. /// Calculate for selected Session.Party.Players stats for preview
  763. /// </summary>
  764. private void CalculateForPreview()
  765. {
  766. previewStatisticsModifier = new StatisticsValue();
  767. previewDamageRange = new Int32Range();
  768. previewHealthDefenseRange = new Int32Range();
  769. previewMagicDefenseRange = new Int32Range();
  770. if (isUseAllowed && !isGearUsed)
  771. {
  772. if (usedGear is Item)
  773. {
  774. // no preview for items
  775. }
  776. else if (usedGear is Armor)
  777. {
  778. Armor armor = usedGear as Armor;
  779. previewStatisticsModifier = armor.OwnerBuffStatistics;
  780. previewHealthDefenseRange = armor.OwnerHealthDefenseRange;
  781. previewMagicDefenseRange = armor.OwnerMagicDefenseRange;
  782. }
  783. else if (usedGear is Weapon)
  784. {
  785. Weapon weapon = usedGear as Weapon;
  786. previewStatisticsModifier = weapon.OwnerBuffStatistics;
  787. previewDamageRange = weapon.TargetDamageRange;
  788. }
  789. }
  790. }
  791. /// <summary>
  792. /// Reset Stats of previously selected Session.Party.Players stats from preview
  793. /// </summary>
  794. private void ResetFromPreview()
  795. {
  796. previewStatisticsModifier = new StatisticsValue();
  797. previewDamageRange = new Int32Range();
  798. previewHealthDefenseRange = new Int32Range();
  799. previewMagicDefenseRange = new Int32Range();
  800. }
  801. #endregion
  802. }
  803. }