RandomCombat.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // RandomCombat.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.IO;
  13. using Microsoft.Xna.Framework.Content;
  14. #endregion
  15. namespace RolePlayingGameData
  16. {
  17. /// <summary>
  18. /// Description of possible random combats in a particular map.
  19. /// </summary>
  20. public class RandomCombat
  21. {
  22. /// <summary>
  23. /// The chance of a random combat starting with each step, from 1 to 100.
  24. /// </summary>
  25. private int combatProbability;
  26. /// <summary>
  27. /// The chance of a random combat starting with each step, from 1 to 100.
  28. /// </summary>
  29. public int CombatProbability
  30. {
  31. get { return combatProbability; }
  32. set { combatProbability = value; }
  33. }
  34. /// <summary>
  35. /// The chance of a successful escape from a random combat, from 1 to 100.
  36. /// </summary>
  37. private int fleeProbability;
  38. /// <summary>
  39. /// The chance of a successful escape from a random combat, from 1 to 100.
  40. /// </summary>
  41. public int FleeProbability
  42. {
  43. get { return fleeProbability; }
  44. set { fleeProbability = value; }
  45. }
  46. /// <summary>
  47. /// The range of possible quantities of monsters in the random encounter.
  48. /// </summary>
  49. private Int32Range monsterCountRange;
  50. /// <summary>
  51. /// The range of possible quantities of monsters in the random encounter.
  52. /// </summary>
  53. public Int32Range MonsterCountRange
  54. {
  55. get { return monsterCountRange; }
  56. set { monsterCountRange = value; }
  57. }
  58. /// <summary>
  59. /// The monsters that might be in the random encounter,
  60. /// along with quantity and weight.
  61. /// </summary>
  62. private List<WeightedContentEntry<Monster>> entries =
  63. new List<WeightedContentEntry<Monster>>();
  64. /// <summary>
  65. /// The monsters that might be in the random encounter,
  66. /// along with quantity and weight.
  67. /// </summary>
  68. public List<WeightedContentEntry<Monster>> Entries
  69. {
  70. get { return entries; }
  71. set { entries = value; }
  72. }
  73. #region Content Type Reader
  74. /// <summary>
  75. /// Reads a RandomCombat object from the content pipeline.
  76. /// </summary>
  77. public class RandomCombatReader : ContentTypeReader<RandomCombat>
  78. {
  79. protected override RandomCombat Read(ContentReader input,
  80. RandomCombat existingInstance)
  81. {
  82. RandomCombat randomCombat = existingInstance;
  83. if (randomCombat == null)
  84. {
  85. randomCombat = new RandomCombat();
  86. }
  87. randomCombat.CombatProbability = input.ReadInt32();
  88. randomCombat.FleeProbability = input.ReadInt32();
  89. randomCombat.MonsterCountRange = input.ReadObject<Int32Range>();
  90. randomCombat.Entries.AddRange(
  91. input.ReadObject<List<WeightedContentEntry<Monster>>>());
  92. foreach (ContentEntry<Monster> randomCombatEntry in randomCombat.Entries)
  93. {
  94. randomCombatEntry.Content = input.ContentManager.Load<Monster>(
  95. Path.Combine(@"Characters\Monsters",
  96. randomCombatEntry.ContentName));
  97. }
  98. return randomCombat;
  99. }
  100. }
  101. #endregion
  102. }
  103. }