| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //-----------------------------------------------------------------------------
- // CharacterLevelDescription.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.IO;
- using System.Linq;
- using System.Xml.Linq;
- using Microsoft.Xna.Framework.Content;
- namespace RolePlaying.Data
- {
- /// <summary>
- /// The requirements and rewards for each level for a character class.
- /// </summary>
- public class CharacterLevelDescription
- {
- /// <summary>
- /// The amount of additional experience necessary to achieve this level.
- /// </summary>
- private int experiencePoints;
- /// <summary>
- /// The amount of additional experience necessary to achieve this level.
- /// </summary>
- public int ExperiencePoints
- {
- get { return experiencePoints; }
- set { experiencePoints = value; }
- }
- /// <summary>
- /// The content names of the spells given to the character
- /// when it reaches this level.
- /// </summary>
- private List<string> spellContentNames = new List<string>();
- /// <summary>
- /// The content names of the spells given to the character
- /// when it reaches this level.
- /// </summary>
- public List<string> SpellContentNames
- {
- get { return spellContentNames; }
- set { spellContentNames = value; }
- }
- /// <summary>
- /// Spells given to the character when it reaches this level.
- /// </summary>
- private List<Spell> spells = new List<Spell>();
- /// <summary>
- /// Spells given to the character when it reaches this level.
- /// </summary>
- [ContentSerializerIgnore]
- public List<Spell> Spells
- {
- get { return spells; }
- set { spells = value; }
- }
- /// <summary>
- /// Read a CharacterLevelDescription object from the content pipeline.
- /// </summary>
- public class CharacterLevelDescriptionReader :
- ContentTypeReader<CharacterLevelDescription>
- {
- /// <summary>
- /// Read a CharacterLevelDescription object from the content pipeline.
- /// </summary>
- protected override CharacterLevelDescription Read(ContentReader input,
- CharacterLevelDescription existingInstance)
- {
- CharacterLevelDescription desc = existingInstance;
- if (desc == null)
- {
- desc = new CharacterLevelDescription();
- }
- desc.ExperiencePoints = input.ReadInt32();
- desc.SpellContentNames.AddRange(input.ReadObject<List<string>>());
- // load all of the spells immediately
- foreach (string spellContentName in desc.SpellContentNames)
- {
- desc.spells.Add(input.ContentManager.Load<Spell>(Path.Combine("Spells", spellContentName)));
- }
- return desc;
- }
- }
- internal static CharacterLevelDescription Load(XElement item, ContentManager contentManager)
- {
- var characterLevelDescription = new CharacterLevelDescription
- {
- ExperiencePoints = (int?)item.Element("ExperiencePoints") ?? 0,
- SpellContentNames = item.Element("SpellContentNames")?
- .Elements("Item")
- .Select(x =>
- {
- return (string)x;
- })
- .ToList() ?? new List<string>(),
- };
- if (characterLevelDescription.SpellContentNames.Count > 0)
- {
- // Load the spells for this level
- characterLevelDescription.Spells = new List<Spell>();
- foreach (var spellContentName in characterLevelDescription.SpellContentNames)
- {
- var spell = Spell.Load(Path.Combine("Spells", spellContentName), contentManager);
- characterLevelDescription.Spells.Add(spell);
- }
- }
- return characterLevelDescription;
- }
- }
- }
|