123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- #region File Description
- //-----------------------------------------------------------------------------
- // CharacterClass.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using System.Collections.Generic;
- using Microsoft.Xna.Framework.Content;
- #endregion
- namespace RolePlayingGameData
- {
- /// <summary>
- /// The definition of a type of character.
- /// </summary>
- public class CharacterClass : ContentObject
- {
- #region Description
- /// <summary>
- /// The name of the character class.
- /// </summary>
- private string name;
- /// <summary>
- /// The name of the character class.
- /// </summary>
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- #endregion
- #region Statistics
- /// <summary>
- /// The initial statistics of characters that use this class.
- /// </summary>
- private StatisticsValue initialStatistics = new StatisticsValue();
- /// <summary>
- /// The initial statistics of characters that use this class.
- /// </summary>
- public StatisticsValue InitialStatistics
- {
- get { return initialStatistics; }
- set { initialStatistics = value; }
- }
-
- #endregion
- #region Leveling
- /// <summary>
- /// Statistics changes for leveling up characters that use this class.
- /// </summary>
- private CharacterLevelingStatistics levelingStatistics;
- /// <summary>
- /// Statistics changes for leveling up characters that use this class.
- /// </summary>
- public CharacterLevelingStatistics LevelingStatistics
- {
- get { return levelingStatistics; }
- set { levelingStatistics = value; }
- }
- /// <summary>
- /// Entries of the requirements and rewards for each level of this class.
- /// </summary>
- private List<CharacterLevelDescription> levelEntries =
- new List<CharacterLevelDescription>();
- /// <summary>
- /// Entries of the requirements and rewards for each level of this class.
- /// </summary>
- public List<CharacterLevelDescription> LevelEntries
- {
- get { return levelEntries; }
- set { levelEntries = value; }
- }
- /// <summary>
- /// Calculate the statistics of a character of this class and the given level.
- /// </summary>
- public StatisticsValue GetStatisticsForLevel(int characterLevel)
- {
- // check the parameter
- if (characterLevel <= 0)
- {
- throw new ArgumentOutOfRangeException("characterLevel");
- }
- // start with the initial statistics
- StatisticsValue output = initialStatistics;
- // add each level of leveling statistics
- for (int i = 1; i < characterLevel; i++)
- {
- if ((levelingStatistics.LevelsPerHealthPointsIncrease > 0) &&
- ((i % levelingStatistics.LevelsPerHealthPointsIncrease) == 0))
- {
- output.HealthPoints += levelingStatistics.HealthPointsIncrease;
- }
- if ((levelingStatistics.LevelsPerMagicPointsIncrease > 0) &&
- ((i % levelingStatistics.LevelsPerMagicPointsIncrease) == 0))
- {
- output.MagicPoints += levelingStatistics.MagicPointsIncrease;
- }
- if ((levelingStatistics.LevelsPerPhysicalOffenseIncrease > 0) &&
- ((i % levelingStatistics.LevelsPerPhysicalOffenseIncrease) == 0))
- {
- output.PhysicalOffense += levelingStatistics.PhysicalOffenseIncrease;
- }
- if ((levelingStatistics.LevelsPerPhysicalDefenseIncrease > 0) &&
- ((i % levelingStatistics.LevelsPerPhysicalDefenseIncrease) == 0))
- {
- output.PhysicalDefense += levelingStatistics.PhysicalDefenseIncrease;
- }
- if ((levelingStatistics.LevelsPerMagicalOffenseIncrease > 0) &&
- ((i % levelingStatistics.LevelsPerMagicalOffenseIncrease) == 0))
- {
- output.MagicalOffense += levelingStatistics.MagicalOffenseIncrease;
- }
- if ((levelingStatistics.LevelsPerMagicalDefenseIncrease > 0) &&
- ((i % levelingStatistics.LevelsPerMagicalDefenseIncrease) == 0))
- {
- output.MagicalDefense += levelingStatistics.MagicalDefenseIncrease;
- }
- }
- return output;
- }
- /// <summary>
- /// Build a list of all spells available to a character
- /// of this class and the given level.
- /// </summary>
- public List<Spell> GetAllSpellsForLevel(int characterLevel)
- {
- // check the parameter
- if (characterLevel <= 0)
- {
- throw new ArgumentOutOfRangeException("characterLevel");
- }
- // go through each level and add the spells to the output list
- List<Spell> spells = new List<Spell>();
- for (int i = 0; i < characterLevel; i++)
- {
- if (i >= levelEntries.Count)
- {
- break;
- }
- // add new spells, and level up existing ones
- foreach (Spell spell in levelEntries[i].Spells)
- {
- Spell existingSpell = spells.Find(
- delegate(Spell testSpell)
- {
- return spell.AssetName == testSpell.AssetName;
- });
- if (existingSpell == null)
- {
- spells.Add(spell.Clone() as Spell);
- }
- else
- {
- existingSpell.Level++;
- }
- }
- }
- return spells;
- }
- #endregion
- #region Value Data
- /// <summary>
- /// The base experience value of Npcs of this character class.
- /// </summary>
- /// <remarks>Used for calculating combat rewards.</remarks>
- private int baseExperienceValue;
- /// <summary>
- /// The base experience value of Npcs of this character class.
- /// </summary>
- /// <remarks>Used for calculating combat rewards.</remarks>
- public int BaseExperienceValue
- {
- get { return baseExperienceValue; }
- set { baseExperienceValue = value; }
- }
- /// <summary>
- /// The base gold value of Npcs of this character class.
- /// </summary>
- /// <remarks>Used for calculating combat rewards.</remarks>
- private int baseGoldValue;
- /// <summary>
- /// The base gold value of Npcs of this character class.
- /// </summary>
- /// <remarks>Used for calculating combat rewards.</remarks>
- public int BaseGoldValue
- {
- get { return baseGoldValue; }
- set { baseGoldValue = value; }
- }
- #endregion
- #region Content Type Reader
- /// <summary>
- /// Reads a CharacterClass object from the content pipeline.
- /// </summary>
- public class CharacterClassReader : ContentTypeReader<CharacterClass>
- {
- /// <summary>
- /// Reads a CharacterClass object from the content pipeline.
- /// </summary>
- protected override CharacterClass Read(ContentReader input,
- CharacterClass existingInstance)
- {
- CharacterClass characterClass = existingInstance;
- if (characterClass == null)
- {
- characterClass = new CharacterClass();
- }
- characterClass.AssetName = input.AssetName;
- characterClass.Name = input.ReadString();
- characterClass.InitialStatistics =
- input.ReadObject<StatisticsValue>();
- characterClass.LevelingStatistics =
- input.ReadObject<CharacterLevelingStatistics>();
- characterClass.LevelEntries.AddRange(
- input.ReadObject<List<CharacterLevelDescription>>());
- characterClass.BaseExperienceValue = input.ReadInt32();
- characterClass.BaseGoldValue = input.ReadInt32();
- return characterClass;
- }
- }
- #endregion
- }
- }
|