CharacterLevelDescription.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // CharacterLevelDescription.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 Microsoft.Xna.Framework.Content;
  13. #endregion
  14. namespace RolePlayingGameData
  15. {
  16. /// <summary>
  17. /// The requirements and rewards for each level for a character class.
  18. /// </summary>
  19. public class CharacterLevelDescription
  20. {
  21. #region Experience Requirements
  22. /// <summary>
  23. /// The amount of additional experience necessary to achieve this level.
  24. /// </summary>
  25. private int experiencePoints;
  26. /// <summary>
  27. /// The amount of additional experience necessary to achieve this level.
  28. /// </summary>
  29. public int ExperiencePoints
  30. {
  31. get { return experiencePoints; }
  32. set { experiencePoints = value; }
  33. }
  34. #endregion
  35. #region Spell Rewards
  36. /// <summary>
  37. /// The content names of the spells given to the character
  38. /// when it reaches this level.
  39. /// </summary>
  40. private List<string> spellContentNames = new List<string>();
  41. /// <summary>
  42. /// The content names of the spells given to the character
  43. /// when it reaches this level.
  44. /// </summary>
  45. public List<string> SpellContentNames
  46. {
  47. get { return spellContentNames; }
  48. set { spellContentNames = value; }
  49. }
  50. /// <summary>
  51. /// Spells given to the character when it reaches this level.
  52. /// </summary>
  53. private List<Spell> spells = new List<Spell>();
  54. /// <summary>
  55. /// Spells given to the character when it reaches this level.
  56. /// </summary>
  57. [ContentSerializerIgnore]
  58. public List<Spell> Spells
  59. {
  60. get { return spells; }
  61. set { spells = value; }
  62. }
  63. #endregion
  64. #region Content Type Reader
  65. /// <summary>
  66. /// Read a CharacterLevelDescription object from the content pipeline.
  67. /// </summary>
  68. public class CharacterLevelDescriptionReader :
  69. ContentTypeReader<CharacterLevelDescription>
  70. {
  71. /// <summary>
  72. /// Read a CharacterLevelDescription object from the content pipeline.
  73. /// </summary>
  74. protected override CharacterLevelDescription Read(ContentReader input,
  75. CharacterLevelDescription existingInstance)
  76. {
  77. CharacterLevelDescription desc = existingInstance;
  78. if (desc == null)
  79. {
  80. desc = new CharacterLevelDescription();
  81. }
  82. desc.ExperiencePoints = input.ReadInt32();
  83. desc.SpellContentNames.AddRange(input.ReadObject<List<string>>());
  84. // load all of the spells immediately
  85. foreach (string spellContentName in desc.SpellContentNames)
  86. {
  87. desc.spells.Add(input.ContentManager.Load<Spell>(
  88. System.IO.Path.Combine("Spells", spellContentName)));
  89. }
  90. return desc;
  91. }
  92. }
  93. #endregion
  94. }
  95. }