PlayerNpcScreen.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //-----------------------------------------------------------------------------
  2. // PlayerNpcScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using RolePlaying.Data;
  9. namespace RolePlaying
  10. {
  11. /// <summary>
  12. /// Displays the Player NPC screen, shown when encountering a player on the map.
  13. /// Typically, the user has an opportunity to invite the Player into the party.
  14. /// </summary>
  15. class PlayerNpcScreen : NpcScreen<Player>
  16. {
  17. /// <summary>
  18. /// If true, the NPC's introduction dialogue is shown.
  19. /// </summary>
  20. private bool isIntroduction = true;
  21. /// <summary>
  22. /// Constructs a new PlayerNpcScreen object.
  23. /// </summary>
  24. /// <param name="mapEntry"></param>
  25. public PlayerNpcScreen(MapEntry<Player> mapEntry)
  26. : base(mapEntry)
  27. {
  28. // assign and check the parameter
  29. Player playerNpc = character as Player;
  30. if (playerNpc == null)
  31. {
  32. throw new ArgumentException(
  33. "PlayerNpcScreen requires a MapEntry with a Player");
  34. }
  35. this.DialogueText = playerNpc.IntroductionDialogue;
  36. this.BackText = "Reject";
  37. this.SelectText = "Accept";
  38. isIntroduction = true;
  39. }
  40. /// <summary>
  41. /// Handles user input.
  42. /// </summary>
  43. public override void HandleInput()
  44. {
  45. // view the player's statistics
  46. if (InputManager.IsActionTriggered(InputManager.Action.TakeView))
  47. {
  48. ScreenManager.AddScreen(new StatisticsScreen(character as Player));
  49. return;
  50. }
  51. if (isIntroduction)
  52. {
  53. // accept the invitation
  54. if (InputManager.IsActionTriggered(InputManager.Action.Ok))
  55. {
  56. isIntroduction = false;
  57. Player player = character as Player;
  58. Session.Party.JoinParty(player);
  59. Session.RemovePlayerNpc(mapEntry);
  60. this.DialogueText = player.JoinAcceptedDialogue;
  61. this.BackText = "Back";
  62. this.SelectText = "Back";
  63. }
  64. // reject the invitation
  65. if (InputManager.IsActionTriggered(InputManager.Action.Back))
  66. {
  67. isIntroduction = false;
  68. Player player = character as Player;
  69. this.DialogueText = player.JoinRejectedDialogue;
  70. this.BackText = "Back";
  71. this.SelectText = "Back";
  72. }
  73. }
  74. else
  75. {
  76. // exit the screen
  77. if (InputManager.IsActionTriggered(InputManager.Action.Ok) ||
  78. InputManager.IsActionTriggered(InputManager.Action.Back))
  79. {
  80. ExitScreen();
  81. return;
  82. }
  83. }
  84. }
  85. }
  86. }