PartySaveData.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // PartySaveData.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 RolePlayingGameData;
  13. #endregion
  14. namespace RolePlaying
  15. {
  16. /// <summary>
  17. /// Serializable data for the state of the party.
  18. /// </summary>
  19. public class PartySaveData
  20. {
  21. /// <summary>
  22. /// The serializable data for all party members.
  23. /// </summary>
  24. public List<PlayerSaveData> players = new List<PlayerSaveData>();
  25. /// <summary>
  26. /// The asset names of all party gear.
  27. /// </summary>
  28. public List<ContentEntry<Gear>> inventory = new List<ContentEntry<Gear>>();
  29. /// <summary>
  30. /// The amount of gold held by the party.
  31. /// </summary>
  32. public int partyGold;
  33. /// <summary>
  34. /// The names of the monsters killed so far during the active quest.
  35. /// </summary>
  36. /// <remarks>
  37. /// Dictionaries don't serialize easily, so the party data is stored separately.
  38. /// </remarks>
  39. public List<string> monsterKillNames = new List<string>();
  40. /// <summary>
  41. /// The kill-counts of the monsters killed so far during the active quest.
  42. /// </summary>
  43. /// <remarks>
  44. /// Dictionaries don't serialize easily, so the party data is stored separately.
  45. /// </remarks>
  46. public List<int> monsterKillCounts = new List<int>();
  47. #region Initialization
  48. /// <summary>
  49. /// Creates a new PartyData object.
  50. /// </summary>
  51. public PartySaveData() { }
  52. /// <summary>
  53. /// Creates a new PartyData object from the given Party object.
  54. /// </summary>
  55. public PartySaveData(Party party)
  56. : this()
  57. {
  58. // check the parameter
  59. if (party == null)
  60. {
  61. throw new ArgumentNullException("party");
  62. }
  63. // create and add the serializable player data
  64. foreach (Player player in party.Players)
  65. {
  66. players.Add(new PlayerSaveData(player));
  67. }
  68. // add the items
  69. inventory.AddRange(party.Inventory);
  70. // store the amount of gold held by the party
  71. partyGold = party.PartyGold;
  72. // add the monster kill data for the active quest
  73. foreach (string monsterName in party.MonsterKills.Keys)
  74. {
  75. monsterKillNames.Add(monsterName);
  76. monsterKillCounts.Add(party.MonsterKills[monsterName]);
  77. }
  78. }
  79. #endregion
  80. }
  81. }