PlayerSelectionScreen.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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 RolePlaying.Data;
  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, Fonts.TitleColor, MathHelper.ToRadians(-3.0f), Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
  260. spriteBatch.End();
  261. }
  262. /// <summary>
  263. /// Draw a player's Details
  264. /// </summary>
  265. /// <param name="player">Players whose details have to be drawn</param>
  266. /// <param name="isSelected">Whether player is selected or not</param>
  267. private void DrawPlayerDetails(Player player, bool isSelected)
  268. {
  269. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  270. Vector2 position = new Vector2();
  271. Vector2 equipEffectPosition = new Vector2();
  272. Color textColor;
  273. Color nameColor, classColor, levelColor;
  274. string text;
  275. int length;
  276. if (isSelected)
  277. {
  278. textColor = Color.Black;
  279. nameColor = new Color(241, 173, 10);
  280. classColor = new Color(207, 131, 42);
  281. levelColor = new Color(151, 150, 148);
  282. }
  283. else
  284. {
  285. textColor = Color.DarkGray;
  286. nameColor = new Color(117, 88, 18);
  287. classColor = new Color(125, 78, 24);
  288. levelColor = new Color(110, 106, 99);
  289. }
  290. position = currentTextPosition;
  291. position.Y -= 5f;
  292. if (isSelected)
  293. {
  294. spriteBatch.Draw(playerSelTexture, position, Color.White);
  295. }
  296. else
  297. {
  298. spriteBatch.Draw(playerUnSelTexture, position, Color.White);
  299. }
  300. position.Y += 5f;
  301. // Draw portrait
  302. portraitPosition.X = position.X + 3f;
  303. portraitPosition.Y = position.Y + 16f;
  304. spriteBatch.Draw(player.ActivePortraitTexture, portraitPosition,
  305. Color.White);
  306. if (isGearUsed && isSelected)
  307. {
  308. spriteBatch.Draw(tickMarkTexture, position, Color.White);
  309. }
  310. // Draw Player Name
  311. playerNamePosition.X = position.X + 90f;
  312. playerNamePosition.Y = position.Y + 15f;
  313. spriteBatch.DrawString(Fonts.PlayerNameFont,
  314. player.Name.ToUpper(), playerNamePosition, nameColor);
  315. // Draw Player Class
  316. playerNamePosition.Y += 25f;
  317. spriteBatch.DrawString(Fonts.PlayerNameFont, player.CharacterClass.Name,
  318. playerNamePosition, classColor);
  319. // Draw Player Level
  320. playerNamePosition.Y += 26f;
  321. spriteBatch.DrawString(Fonts.PlayerNameFont, "LEVEL: " +
  322. player.CharacterLevel,
  323. playerNamePosition, levelColor);
  324. position = currentTextPosition;
  325. position.X += playerSelTexture.Width + 5f;
  326. DrawPlayerStats(player, isSelected, ref position);
  327. equipEffectPosition = position;
  328. equipEffectPosition.X += 100f;
  329. equipEffectPosition.Y = currentTextPosition.Y;
  330. text = "Weapon Atk: (";
  331. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  332. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  333. Fonts.CountColor);
  334. equipEffectPosition.X += length;
  335. // calculate weapon damage
  336. previewDamageRange = new Int32Range();
  337. previewHealthDefenseRange = new Int32Range();
  338. previewMagicDefenseRange = new Int32Range();
  339. if (isSelected && isUseAllowed && !isGearUsed)
  340. {
  341. if (usedGear is Equipment)
  342. {
  343. Equipment equipment = usedGear as Equipment;
  344. if (equipment is Weapon)
  345. {
  346. Weapon weapon = equipment as Weapon;
  347. previewDamageRange = weapon.TargetDamageRange;
  348. Weapon equippedWeapon = player.GetEquippedWeapon();
  349. if (equippedWeapon != null)
  350. {
  351. previewDamageRange -= equippedWeapon.TargetDamageRange;
  352. previewDamageRange -=
  353. equippedWeapon.OwnerBuffStatistics.PhysicalOffense;
  354. previewHealthDefenseRange -=
  355. equippedWeapon.OwnerBuffStatistics.PhysicalDefense;
  356. previewMagicDefenseRange -=
  357. equippedWeapon.OwnerBuffStatistics.MagicalDefense;
  358. }
  359. }
  360. else if (equipment is Armor)
  361. {
  362. Armor armor = usedGear as Armor;
  363. previewHealthDefenseRange = armor.OwnerHealthDefenseRange;
  364. previewMagicDefenseRange = armor.OwnerMagicDefenseRange;
  365. Armor equippedArmor = player.GetEquippedArmor(armor.Slot);
  366. if (equippedArmor != null)
  367. {
  368. previewHealthDefenseRange -=
  369. equippedArmor.OwnerHealthDefenseRange;
  370. previewMagicDefenseRange -=
  371. equippedArmor.OwnerMagicDefenseRange;
  372. previewDamageRange -=
  373. equippedArmor.OwnerBuffStatistics.PhysicalOffense;
  374. previewHealthDefenseRange -=
  375. equippedArmor.OwnerBuffStatistics.PhysicalDefense;
  376. previewMagicDefenseRange -=
  377. equippedArmor.OwnerBuffStatistics.MagicalDefense;
  378. }
  379. }
  380. previewDamageRange += equipment.OwnerBuffStatistics.PhysicalOffense;
  381. previewHealthDefenseRange +=
  382. equipment.OwnerBuffStatistics.PhysicalDefense;
  383. previewMagicDefenseRange +=
  384. equipment.OwnerBuffStatistics.MagicalDefense;
  385. }
  386. }
  387. Int32Range drawWeaponDamageRange = player.TargetDamageRange +
  388. previewDamageRange + player.CharacterStatistics.PhysicalOffense;
  389. text = drawWeaponDamageRange.Minimum.ToString();
  390. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  391. textColor = GetRangeColor(previewDamageRange.Minimum, isSelected);
  392. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  393. equipEffectPosition, textColor);
  394. equipEffectPosition.X += length;
  395. text = ",";
  396. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  397. spriteBatch.DrawString(Fonts.DescriptionFont,
  398. text, equipEffectPosition,
  399. Fonts.CountColor);
  400. equipEffectPosition.X += length;
  401. text = drawWeaponDamageRange.Maximum.ToString(); ;
  402. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  403. textColor = GetRangeColor(previewDamageRange.Maximum, isSelected);
  404. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  405. equipEffectPosition, textColor);
  406. equipEffectPosition.X += length;
  407. spriteBatch.DrawString(Fonts.DescriptionFont, ")", equipEffectPosition,
  408. Fonts.CountColor);
  409. equipEffectPosition.X = position.X + 100f;
  410. equipEffectPosition.Y += Fonts.DescriptionFont.LineSpacing;
  411. text = "Weapon Def: (";
  412. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  413. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  414. Fonts.CountColor);
  415. equipEffectPosition.X += length;
  416. Int32Range drawHealthDefenseRange = player.HealthDefenseRange +
  417. previewHealthDefenseRange + player.CharacterStatistics.PhysicalDefense;
  418. text = drawHealthDefenseRange.Minimum.ToString();
  419. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  420. textColor = GetRangeColor(previewHealthDefenseRange.Minimum, isSelected);
  421. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  422. equipEffectPosition, textColor);
  423. equipEffectPosition.X += length;
  424. text = ",";
  425. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  426. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  427. Fonts.CountColor);
  428. equipEffectPosition.X += length;
  429. text = drawHealthDefenseRange.Maximum.ToString();
  430. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  431. textColor = GetRangeColor(previewHealthDefenseRange.Maximum, isSelected);
  432. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  433. equipEffectPosition, textColor);
  434. equipEffectPosition.X += length;
  435. spriteBatch.DrawString(Fonts.DescriptionFont, ")", equipEffectPosition,
  436. Fonts.CountColor);
  437. equipEffectPosition.X = position.X + 100f;
  438. equipEffectPosition.Y += Fonts.DescriptionFont.LineSpacing;
  439. text = "Spell Def: (";
  440. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  441. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  442. Fonts.CountColor);
  443. equipEffectPosition.X += length;
  444. Int32Range drawMagicDefenseRange = player.MagicDefenseRange +
  445. previewMagicDefenseRange + player.CharacterStatistics.MagicalDefense;
  446. text = drawMagicDefenseRange.Minimum.ToString();
  447. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  448. textColor = GetRangeColor(previewMagicDefenseRange.Minimum, isSelected);
  449. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  450. equipEffectPosition, textColor);
  451. equipEffectPosition.X += length;
  452. text = ",";
  453. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  454. spriteBatch.DrawString(Fonts.DescriptionFont, text, equipEffectPosition,
  455. Fonts.CountColor);
  456. equipEffectPosition.X += length;
  457. text = drawMagicDefenseRange.Maximum.ToString();
  458. length = (int)Fonts.DescriptionFont.MeasureString(text).X;
  459. textColor = GetRangeColor(previewMagicDefenseRange.Maximum, isSelected);
  460. spriteBatch.DrawString(Fonts.DescriptionFont, text,
  461. equipEffectPosition, textColor);
  462. equipEffectPosition.X += length;
  463. spriteBatch.DrawString(Fonts.DescriptionFont, ")", equipEffectPosition,
  464. Fonts.CountColor);
  465. currentTextPosition.Y = position.Y + 3f;
  466. spriteBatch.Draw(lineTexture, currentTextPosition, Color.White);
  467. currentTextPosition.Y += 20f;
  468. }
  469. /// <summary>
  470. /// Draw a Player's stats
  471. /// </summary>
  472. /// <param name="player">Player whose stats have to be drawn</param>
  473. /// <param name="isSelected">Whether player is selected or not</param>
  474. /// <param name="position">Position as to
  475. /// where to start drawing the stats</param>
  476. private void DrawPlayerStats(Player player, bool isSelected,
  477. ref Vector2 position)
  478. {
  479. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  480. Color color;
  481. string detail1, detail2;
  482. float length1, length2;
  483. StatisticsValue playersStatisticsModifier = new StatisticsValue();
  484. if (isSelected && isUseAllowed && !isGearUsed)
  485. {
  486. playersStatisticsModifier = previewStatisticsModifier;
  487. if (usedGear is Armor)
  488. {
  489. Armor armor = usedGear as Armor;
  490. Armor existingArmor = player.GetEquippedArmor(armor.Slot);
  491. if (existingArmor != null)
  492. {
  493. playersStatisticsModifier -= existingArmor.OwnerBuffStatistics;
  494. }
  495. }
  496. else if (usedGear is Weapon)
  497. {
  498. Weapon weapon = usedGear as Weapon;
  499. Weapon existingWeapon = player.GetEquippedWeapon();
  500. if (existingWeapon != null)
  501. {
  502. playersStatisticsModifier -= existingWeapon.OwnerBuffStatistics;
  503. }
  504. }
  505. }
  506. // Calculate HP and MP string Length
  507. detail1 = "HP: " + player.CurrentStatistics.HealthPoints + "/" +
  508. player.CharacterStatistics.HealthPoints;
  509. length1 = Fonts.DescriptionFont.MeasureString(detail1).X;
  510. detail2 = "MP: " + player.CurrentStatistics.MagicPoints + "/" +
  511. player.CharacterStatistics.MagicPoints;
  512. length2 = Fonts.DescriptionFont.MeasureString(detail2).X;
  513. StatisticsValue drawCurrentStatistics = player.CurrentStatistics;
  514. StatisticsValue drawCharacterStatistics = player.CharacterStatistics;
  515. if (isSelected)
  516. {
  517. drawCurrentStatistics += playersStatisticsModifier;
  518. drawCharacterStatistics += playersStatisticsModifier;
  519. }
  520. // Draw the character Health Points
  521. color = GetStatColor(playersStatisticsModifier.HealthPoints, isSelected);
  522. spriteBatch.DrawString(Fonts.DescriptionFont, "HP: " +
  523. drawCurrentStatistics.HealthPoints + "/" +
  524. drawCharacterStatistics.HealthPoints,
  525. position, color);
  526. // Draw the character Mana Points
  527. position.Y += Fonts.DescriptionFont.LineSpacing;
  528. color = GetStatColor(playersStatisticsModifier.MagicPoints, isSelected);
  529. spriteBatch.DrawString(Fonts.DescriptionFont, "MP: " +
  530. drawCurrentStatistics.MagicPoints + "/" +
  531. drawCharacterStatistics.MagicPoints,
  532. position, color);
  533. // Draw the physical offense
  534. position.X += 150f;
  535. position.Y -= Fonts.DescriptionFont.LineSpacing;
  536. color = GetStatColor(playersStatisticsModifier.PhysicalOffense, isSelected);
  537. spriteBatch.DrawString(Fonts.DescriptionFont, "PO: " +
  538. drawCurrentStatistics.PhysicalOffense, position, color);
  539. // Draw the physical defense
  540. position.Y += Fonts.DescriptionFont.LineSpacing;
  541. color = GetStatColor(playersStatisticsModifier.PhysicalDefense, isSelected);
  542. spriteBatch.DrawString(Fonts.DescriptionFont, "PD: " +
  543. drawCurrentStatistics.PhysicalDefense, position, color);
  544. // Draw the Magic offense
  545. position.Y += Fonts.DescriptionFont.LineSpacing;
  546. color = GetStatColor(playersStatisticsModifier.MagicalOffense, isSelected);
  547. spriteBatch.DrawString(Fonts.DescriptionFont, "MO: " +
  548. drawCurrentStatistics.MagicalOffense, position, color);
  549. // Draw the Magical defense
  550. position.Y += Fonts.DescriptionFont.LineSpacing;
  551. color = GetStatColor(playersStatisticsModifier.MagicalDefense, isSelected);
  552. spriteBatch.DrawString(Fonts.DescriptionFont, "MD: " +
  553. drawCurrentStatistics.MagicalDefense, position, color);
  554. position.Y += Fonts.DescriptionFont.LineSpacing;
  555. }
  556. /// <summary>
  557. /// Draw the Character Stats and Character Icons
  558. /// </summary>
  559. private void DrawViewablePlayers()
  560. {
  561. bool isSelectedPlayer = false;
  562. // Compute Start Index
  563. if (startIndex < 0)
  564. {
  565. startIndex = 0;
  566. selectionMark = 0;
  567. CalculateSelectedPlayers();
  568. }
  569. // Compute EndIndex
  570. if (endIndex > Session.Party.Players.Count)
  571. {
  572. endIndex = Session.Party.Players.Count;
  573. selectionMark = endIndex - 1;
  574. CalculateSelectedPlayers();
  575. }
  576. for (int playerIndex = startIndex; playerIndex < endIndex; playerIndex++)
  577. {
  578. isSelectedPlayer = false;
  579. for (int i = 0; i < selectedPlayers.Count; i++)
  580. {
  581. if (playerIndex == selectedPlayers[i])
  582. {
  583. isSelectedPlayer = true;
  584. break;
  585. }
  586. }
  587. DrawPlayerDetails(Session.Party.Players[playerIndex], isSelectedPlayer);
  588. }
  589. // Draw the Scroll button only if player count exceed the Max items
  590. if (selectionMark != -1)
  591. {
  592. if (Session.Party.Players.Count > drawMaximum)
  593. {
  594. DrawCharacterCount();
  595. }
  596. }
  597. }
  598. /// <summary>
  599. /// Draw the Current player Selected and total no.of
  600. /// Session.Party.Players in the list
  601. /// </summary>
  602. private void DrawCharacterCount()
  603. {
  604. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  605. Vector2 position = new Vector2();
  606. // Draw the ScoreBoard
  607. spriteBatch.Draw(scoreBoard, scoreBoardPosition, Color.White);
  608. position = scoreBoardPosition;
  609. position.X += 29;
  610. position.Y += 100;
  611. // Display Current Selected Player
  612. spriteBatch.DrawString(Fonts.GearInfoFont,
  613. (selectionMark + 1).ToString(),
  614. position, Fonts.CountColor);
  615. position.Y += 30;
  616. // Display Total Players count
  617. spriteBatch.DrawString(Fonts.GearInfoFont,
  618. Session.Party.Players.Count.ToString(), position, Fonts.CountColor);
  619. }
  620. /// <summary>
  621. /// Draw Select and Drop Button
  622. /// </summary>
  623. private void DrawButtons()
  624. {
  625. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  626. Vector2 position;
  627. Vector2 placeTextMid;
  628. string selectText;
  629. if (usedGear == null)
  630. {
  631. selectText = "Use";
  632. }
  633. else if (usedGear is Item)
  634. {
  635. selectText = "Use";
  636. }
  637. else
  638. {
  639. selectText = "Equip";
  640. }
  641. if (CombatEngine.IsActive)
  642. {
  643. if (selectionMark != -1)
  644. {
  645. isUseAllowed = true;
  646. }
  647. }
  648. if (isUseAllowed && !isGearUsed)
  649. {
  650. // Draw Select Button
  651. spriteBatch.Draw(selectButton, selectButtonPosition, Color.White);
  652. // Display Text
  653. position = selectButtonPosition;
  654. placeTextMid = Fonts.ButtonNamesFont.MeasureString(selectText);
  655. position.X -= placeTextMid.X + 10;
  656. spriteBatch.DrawString(Fonts.ButtonNamesFont, selectText, position,
  657. Color.White);
  658. }
  659. // Draw Back Button
  660. spriteBatch.Draw(backButton, backButtonPosition, Color.White);
  661. // Display Back Text
  662. position = backButtonPosition;
  663. position.X += backButton.Width + 10;
  664. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back", position, Color.White);
  665. }
  666. /// <summary>
  667. /// Gets Font color for stat display based on whether the stat has changed
  668. /// </summary>
  669. /// <param name="change">How the stat has changed</param>
  670. /// <param name="isSelected">Character's selection status</param>
  671. /// <returns>Returns Color for display of stat</returns>
  672. private Color GetStatColor(int change, bool isSelected)
  673. {
  674. if (isSelected && isUseAllowed)
  675. {
  676. if (change < 0)
  677. {
  678. return Color.Red;
  679. }
  680. else if (change > 0)
  681. {
  682. return Color.Green;
  683. }
  684. // fall through when == 0
  685. }
  686. return Fonts.CountColor;
  687. }
  688. /// <summary>
  689. /// Decides min/max of Weapon Attack/Weapon Def/Spell Def of player
  690. /// </summary>
  691. /// <param name="value">Describes if min/max of range has
  692. /// changed or not</param>
  693. /// <param name="isSelected">Character's selection status</param>
  694. /// <returns>Returns the color to display min/max of the range</returns>
  695. private Color GetRangeColor(int value, bool isSelected)
  696. {
  697. if (isSelected && isUseAllowed)
  698. {
  699. if (value > 0)
  700. {
  701. return Color.Green;
  702. }
  703. else if (value < 0)
  704. {
  705. return Color.Red;
  706. }
  707. else
  708. {
  709. return Fonts.CountColor;
  710. }
  711. }
  712. return Fonts.CountColor;
  713. }
  714. /// <summary>
  715. /// Calculate selected Session.Party.Players around on the selection mark
  716. /// based on the range for items. Incase of equipment range is considered as 0
  717. /// </summary>
  718. private void CalculateSelectedPlayers()
  719. {
  720. int range = 0;
  721. int selMark = selectionMark;
  722. selectedPlayers.Clear();
  723. Item item = usedGear as Item;
  724. if (item != null)
  725. {
  726. range = item.AdjacentTargets;
  727. }
  728. selectedPlayers.Add(selMark);
  729. for (int i = 1; i <= range; i++)
  730. {
  731. if ((selMark >= i) &&
  732. !Session.Party.Players[selMark - i].IsDeadOrDying)
  733. {
  734. selectedPlayers.Add(selMark - i);
  735. }
  736. if ((selMark < (Session.Party.Players.Count - i)) &&
  737. !Session.Party.Players[selMark + i].IsDeadOrDying)
  738. {
  739. selectedPlayers.Add(selMark + i);
  740. }
  741. }
  742. }
  743. /// <summary>
  744. /// Calculate for selected Session.Party.Players stats for preview
  745. /// </summary>
  746. private void CalculateForPreview()
  747. {
  748. previewStatisticsModifier = new StatisticsValue();
  749. previewDamageRange = new Int32Range();
  750. previewHealthDefenseRange = new Int32Range();
  751. previewMagicDefenseRange = new Int32Range();
  752. if (isUseAllowed && !isGearUsed)
  753. {
  754. if (usedGear is Item)
  755. {
  756. // no preview for items
  757. }
  758. else if (usedGear is Armor)
  759. {
  760. Armor armor = usedGear as Armor;
  761. previewStatisticsModifier = armor.OwnerBuffStatistics;
  762. previewHealthDefenseRange = armor.OwnerHealthDefenseRange;
  763. previewMagicDefenseRange = armor.OwnerMagicDefenseRange;
  764. }
  765. else if (usedGear is Weapon)
  766. {
  767. Weapon weapon = usedGear as Weapon;
  768. previewStatisticsModifier = weapon.OwnerBuffStatistics;
  769. previewDamageRange = weapon.TargetDamageRange;
  770. }
  771. }
  772. }
  773. /// <summary>
  774. /// Reset Stats of previously selected Session.Party.Players stats from preview
  775. /// </summary>
  776. private void ResetFromPreview()
  777. {
  778. previewStatisticsModifier = new StatisticsValue();
  779. previewDamageRange = new Int32Range();
  780. previewHealthDefenseRange = new Int32Range();
  781. previewMagicDefenseRange = new Int32Range();
  782. }
  783. }
  784. }