RandomCombat.cs 3.7 KB

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