#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
{
///
/// The definition of a type of character.
///
public class CharacterClass : ContentObject
{
#region Description
///
/// The name of the character class.
///
private string name;
///
/// The name of the character class.
///
public string Name
{
get { return name; }
set { name = value; }
}
#endregion
#region Statistics
///
/// The initial statistics of characters that use this class.
///
private StatisticsValue initialStatistics = new StatisticsValue();
///
/// The initial statistics of characters that use this class.
///
public StatisticsValue InitialStatistics
{
get { return initialStatistics; }
set { initialStatistics = value; }
}
#endregion
#region Leveling
///
/// Statistics changes for leveling up characters that use this class.
///
private CharacterLevelingStatistics levelingStatistics;
///
/// Statistics changes for leveling up characters that use this class.
///
public CharacterLevelingStatistics LevelingStatistics
{
get { return levelingStatistics; }
set { levelingStatistics = value; }
}
///
/// Entries of the requirements and rewards for each level of this class.
///
private List levelEntries =
new List();
///
/// Entries of the requirements and rewards for each level of this class.
///
public List LevelEntries
{
get { return levelEntries; }
set { levelEntries = value; }
}
///
/// Calculate the statistics of a character of this class and the given level.
///
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;
}
///
/// Build a list of all spells available to a character
/// of this class and the given level.
///
public List 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 spells = new List();
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
///
/// The base experience value of Npcs of this character class.
///
/// Used for calculating combat rewards.
private int baseExperienceValue;
///
/// The base experience value of Npcs of this character class.
///
/// Used for calculating combat rewards.
public int BaseExperienceValue
{
get { return baseExperienceValue; }
set { baseExperienceValue = value; }
}
///
/// The base gold value of Npcs of this character class.
///
/// Used for calculating combat rewards.
private int baseGoldValue;
///
/// The base gold value of Npcs of this character class.
///
/// Used for calculating combat rewards.
public int BaseGoldValue
{
get { return baseGoldValue; }
set { baseGoldValue = value; }
}
#endregion
#region Content Type Reader
///
/// Reads a CharacterClass object from the content pipeline.
///
public class CharacterClassReader : ContentTypeReader
{
///
/// Reads a CharacterClass object from the content pipeline.
///
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();
characterClass.LevelingStatistics =
input.ReadObject();
characterClass.LevelEntries.AddRange(
input.ReadObject>());
characterClass.BaseExperienceValue = input.ReadInt32();
characterClass.BaseGoldValue = input.ReadInt32();
return characterClass;
}
}
#endregion
}
}