PartySaveData.cs 2.7 KB

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