PlayerSelectionScreen.cs 34 KB

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