Can add spells successfully.
Signed-off-by: Melissa Avery-Weir <melissa.avery@wellsfargo.com>
This commit is contained in:
@@ -5,253 +5,55 @@ using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using d20_SRD_Spell_Lists.Exceptions;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace d20_SRD_Spell_Lists.Models {
|
||||
public class Character {
|
||||
|
||||
private string charXmlFile;
|
||||
private XElement charDetails;
|
||||
public List<Spell> Spells { get; set; }
|
||||
|
||||
public Character() {
|
||||
charDetails = new XElement("character");
|
||||
charDetails.Add(new XElement("spells"));
|
||||
}
|
||||
|
||||
public Character(string _charXmlFile) {
|
||||
charXmlFile = _charXmlFile;
|
||||
charDetails = XElement.Load(charXmlFile);
|
||||
}
|
||||
|
||||
internal void save() {
|
||||
if (charXmlFile == null) {
|
||||
throw new NoCharacterFileException("Don't have a file location for the character.");
|
||||
}
|
||||
charDetails.Save(charXmlFile);
|
||||
}
|
||||
|
||||
internal XElement spells() {
|
||||
return charDetails.Element("spells");
|
||||
Spells = new List<Spell>();
|
||||
}
|
||||
|
||||
private int modifier(int score) {
|
||||
return (int)Math.Floor((score - 10) / 2.00);
|
||||
}
|
||||
|
||||
public string FileName {
|
||||
set {
|
||||
charXmlFile = value;
|
||||
}
|
||||
}
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
if (charDetails.Element("name") != null) {
|
||||
return charDetails.Element("name").Value;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("name") != null) {
|
||||
charDetails.Element("name").Value = value;
|
||||
} else {
|
||||
charDetails.Add(new XElement("name", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Strength {
|
||||
get {
|
||||
if (charDetails.Element("strength") != null) {
|
||||
return int.Parse(charDetails.Element("strength").Value);
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("strength") != null) {
|
||||
charDetails.Element("strength").Value = value.ToString();
|
||||
} else {
|
||||
charDetails.Add(new XElement("strength", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Dexterity {
|
||||
get {
|
||||
if (charDetails.Element("dexterity") != null) {
|
||||
return int.Parse(charDetails.Element("dexterity").Value);
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("dexterity") != null) {
|
||||
charDetails.Element("dexterity").Value = value.ToString();
|
||||
} else {
|
||||
charDetails.Add(new XElement("dexterity", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Constitution {
|
||||
get {
|
||||
if (charDetails.Element("constitution") != null) {
|
||||
return int.Parse(charDetails.Element("constitution").Value);
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("constitution") != null) {
|
||||
charDetails.Element("constitution").Value = value.ToString();
|
||||
} else {
|
||||
charDetails.Add(new XElement("constitution", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Intelligence {
|
||||
get {
|
||||
if (charDetails.Element("intelligence") != null) {
|
||||
return int.Parse(charDetails.Element("intelligence").Value);
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("intelligence") != null) {
|
||||
charDetails.Element("intelligence").Value = value.ToString();
|
||||
} else {
|
||||
charDetails.Add(new XElement("intelligence", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Wisdom {
|
||||
get {
|
||||
if (charDetails.Element("wisdom") != null) {
|
||||
return int.Parse(charDetails.Element("wisdom").Value);
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("wisdom") != null) {
|
||||
charDetails.Element("wisdom").Value = value.ToString();
|
||||
} else {
|
||||
charDetails.Add(new XElement("wisdom", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Charisma {
|
||||
get {
|
||||
if (charDetails.Element("charisma") != null) {
|
||||
return int.Parse(charDetails.Element("charisma").Value);
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("charisma") != null) {
|
||||
charDetails.Element("charisma").Value = value.ToString();
|
||||
} else {
|
||||
charDetails.Add(new XElement("charisma", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int SpellCastingAttribute {
|
||||
public string SpellCastingAttributeName {
|
||||
get {
|
||||
switch (CharacterClass) {
|
||||
case SpellCastingClasses.Bard:
|
||||
return Charisma;
|
||||
return "Charisma";
|
||||
case SpellCastingClasses.Cleric:
|
||||
return Wisdom;
|
||||
return "Wisdom";
|
||||
case SpellCastingClasses.Druid:
|
||||
return Wisdom;
|
||||
return "Wisdom";
|
||||
case SpellCastingClasses.Paladin:
|
||||
return Wisdom;
|
||||
return "Wisdom";
|
||||
case SpellCastingClasses.Ranger:
|
||||
return Wisdom;
|
||||
return "Wisdom";
|
||||
case SpellCastingClasses.Sorcerer:
|
||||
return Charisma;
|
||||
return "Charisma";
|
||||
case SpellCastingClasses.Wizard:
|
||||
return Intelligence;
|
||||
return "Intelligence";
|
||||
default:
|
||||
return Wisdom;
|
||||
return "Wisdom";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int SpellCastingAttribute { get; set; }
|
||||
|
||||
public int SpellCastingAttributeMod {
|
||||
get {
|
||||
switch (CharacterClass) {
|
||||
case SpellCastingClasses.Bard:
|
||||
return CharismaMod;
|
||||
case SpellCastingClasses.Cleric:
|
||||
return WisdomMod;
|
||||
case SpellCastingClasses.Druid:
|
||||
return WisdomMod;
|
||||
case SpellCastingClasses.Paladin:
|
||||
return WisdomMod;
|
||||
case SpellCastingClasses.Ranger:
|
||||
return WisdomMod;
|
||||
case SpellCastingClasses.Sorcerer:
|
||||
return CharismaMod;
|
||||
case SpellCastingClasses.Wizard:
|
||||
return IntelligenceMod;
|
||||
default:
|
||||
return WisdomMod;
|
||||
}
|
||||
return modifier(SpellCastingAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
public SpellCastingClasses CharacterClass {
|
||||
get {
|
||||
if (charDetails.Element("class") != null) {
|
||||
return (SpellCastingClasses)Enum.Parse(typeof(SpellCastingClasses), charDetails.Element("class").Value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
set {
|
||||
if (charDetails.Element("class") != null) {
|
||||
charDetails.Element("class").Value = getClassName(value);
|
||||
} else {
|
||||
charDetails.Add(new XElement("class", getClassName(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int StrengthMod {
|
||||
get {
|
||||
return modifier(Strength);
|
||||
}
|
||||
}
|
||||
|
||||
public int DexterityMod {
|
||||
get {
|
||||
return modifier(Dexterity);
|
||||
}
|
||||
}
|
||||
|
||||
public int ConstitutionMod {
|
||||
get {
|
||||
return modifier(Constitution);
|
||||
}
|
||||
}
|
||||
|
||||
public int IntelligenceMod {
|
||||
get {
|
||||
return modifier(Intelligence);
|
||||
}
|
||||
}
|
||||
|
||||
public int WisdomMod {
|
||||
get {
|
||||
return modifier(Wisdom);
|
||||
}
|
||||
}
|
||||
|
||||
public int CharismaMod {
|
||||
get {
|
||||
return modifier(Charisma);
|
||||
}
|
||||
}
|
||||
public SpellCastingClasses CharacterClass { get; set; }
|
||||
|
||||
public enum SpellCastingClasses {
|
||||
Bard = 0,
|
||||
@@ -263,10 +65,14 @@ namespace d20_SRD_Spell_Lists.Models {
|
||||
Wizard = 6
|
||||
}
|
||||
|
||||
public static string getClassName(SpellCastingClasses spellCastingClass) {
|
||||
public static string getSpellcastingClassName(SpellCastingClasses spellCastingClass) {
|
||||
return Enum.GetName(typeof(SpellCastingClasses), spellCastingClass);
|
||||
}
|
||||
|
||||
public static SpellCastingClasses getSpellcastingClass(string className) {
|
||||
return (Character.SpellCastingClasses)Enum.Parse(typeof(Character.SpellCastingClasses), className);
|
||||
}
|
||||
|
||||
public int[] BonusSpells {
|
||||
get {
|
||||
int[] bs = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
@@ -282,11 +88,15 @@ namespace d20_SRD_Spell_Lists.Models {
|
||||
get {
|
||||
List<string> classes = new List<string>();
|
||||
foreach (SpellCastingClasses cl in Enum.GetValues(typeof(SpellCastingClasses))) {
|
||||
classes.Add(getClassName(cl));
|
||||
classes.Add(getSpellcastingClassName(cl));
|
||||
}
|
||||
|
||||
return classes.ToArray<string>();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAllClassSpells() {
|
||||
Spells.AddRange(new MasterSpellSet().byClass(CharacterClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
163
d20 SRD Spell Lists/Models/MasterSpellSet.cs
Normal file
163
d20 SRD Spell Lists/Models/MasterSpellSet.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using d20_SRD_Spell_Lists.Exceptions;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections;
|
||||
|
||||
namespace d20_SRD_Spell_Lists.Models {
|
||||
public class MasterSpellSet {
|
||||
private XElement masterSpellList;
|
||||
|
||||
public MasterSpellSet() {
|
||||
loadXML(Properties.Settings.Default.MasterSpells);
|
||||
}
|
||||
|
||||
private void loadXML(string _masterXmlFile) {
|
||||
// Load the XML file.
|
||||
if (_masterXmlFile == null) {
|
||||
_masterXmlFile = Properties.Settings.Default.MasterSpells;
|
||||
}
|
||||
masterSpellList = XElement.Load(_masterXmlFile);
|
||||
}
|
||||
|
||||
public List<Spell> byClass(Character.SpellCastingClasses spellCastingClass) {
|
||||
List<Spell> spells = new List<Spell>();
|
||||
|
||||
filterMasterSpellsByClass(spellCastingClass, spells);
|
||||
|
||||
return spells;
|
||||
}
|
||||
|
||||
private void filterMasterSpellsByClass(Character.SpellCastingClasses spellCastingClass, List<Spell> spells) {
|
||||
spells.AddRange(querySpellsByClass(masterSpellList, spellCastingClass, false, false).ToList<Spell>());
|
||||
}
|
||||
|
||||
public List<Spell> byClassAndLevel(Character.SpellCastingClasses spellCastingClass, int level) {
|
||||
List<Spell> spells = new List<Spell>();
|
||||
|
||||
filterMasterSpellsByClassAndLevel(spellCastingClass, level, spells);
|
||||
|
||||
return spells;
|
||||
}
|
||||
|
||||
private List<Spell> querySpellsByClassAndLevel(XElement list, Character.SpellCastingClasses spellCastingClass, int level, bool isCustom, bool isCharCustom) {
|
||||
string c = Character.getSpellcastingClassName(spellCastingClass);
|
||||
Regex levelReg = new Regex(@" (\d+)?");
|
||||
return (from sp in list.Elements("spell")
|
||||
let xmlLevel = (string)sp.Element("level")
|
||||
where xmlLevel != null && xmlLevel.Contains(c + " " + level.ToString())
|
||||
orderby levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value
|
||||
select new Spell {
|
||||
Name = (string)sp.Element("name"),
|
||||
AltName = (string)sp.Element("altname"),
|
||||
School = (string)sp.Element("school"),
|
||||
Subschool = (string)sp.Element("subschool"),
|
||||
Descriptor = (string)sp.Element("descriptor"),
|
||||
FullLevel = (string)sp.Element("level"),
|
||||
Level = int.Parse(levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value),
|
||||
Components = (string)sp.Element("components"),
|
||||
CastingTime = (string)sp.Element("casting_time"),
|
||||
Range = (string)sp.Element("range"),
|
||||
Effect = (string)sp.Element("effect"),
|
||||
Target = (string)sp.Element("target"),
|
||||
Duration = (string)sp.Element("duration"),
|
||||
SavingThrow = (string)sp.Element("saving_throw"),
|
||||
SpellResistance = (string)sp.Element("sp_resistance"),
|
||||
ShortDescription = (string)sp.Element("short_description"),
|
||||
ArcaneMaterialComponents = (string)sp.Element("arcane_material_components"),
|
||||
Description = (string)sp.Element("description"),
|
||||
FullText = (string)sp.Element("full_text"),
|
||||
Reference = (string)sp.Element("reference")
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private List<Spell> querySpellsByClass(XElement list, Character.SpellCastingClasses spellCastingClass, bool isCustom, bool isCharCustom) {
|
||||
string c = Character.getSpellcastingClassName(spellCastingClass);
|
||||
Regex levelReg = new Regex(@" (\d+),?");
|
||||
return (from sp in list.Elements("spell")
|
||||
let xmlLevel = (string)sp.Element("level")
|
||||
where xmlLevel != null && xmlLevel.Contains(c)
|
||||
orderby levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value
|
||||
select new Spell {
|
||||
Name = (string)sp.Element("name"),
|
||||
AltName = (string)sp.Element("altname"),
|
||||
School = (string)sp.Element("school"),
|
||||
Subschool = (string)sp.Element("subschool"),
|
||||
Descriptor = (string)sp.Element("descriptor"),
|
||||
FullLevel = (string)sp.Element("level"),
|
||||
Level = int.Parse(levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value),
|
||||
Components = (string)sp.Element("components"),
|
||||
CastingTime = (string)sp.Element("casting_time"),
|
||||
Range = (string)sp.Element("range"),
|
||||
Effect = (string)sp.Element("effect"),
|
||||
Target = (string)sp.Element("target"),
|
||||
Duration = (string)sp.Element("duration"),
|
||||
SavingThrow = (string)sp.Element("saving_throw"),
|
||||
SpellResistance = (string)sp.Element("sp_resistance"),
|
||||
ShortDescription = (string)sp.Element("short_description"),
|
||||
ArcaneMaterialComponents = (string)sp.Element("arcane_material_components"),
|
||||
Description = (string)sp.Element("description"),
|
||||
FullText = (string)sp.Element("full_text"),
|
||||
Reference = (string)sp.Element("reference")
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private void filterMasterSpellsByClassAndLevel(Character.SpellCastingClasses spellCastingClass, int level, List<Spell> spells) {
|
||||
spells.AddRange(querySpellsByClassAndLevel(masterSpellList, spellCastingClass, level, false, false).ToList<Spell>());
|
||||
}
|
||||
|
||||
public int totalCount() {
|
||||
return masterSpellList.Elements("spell").Count();
|
||||
}
|
||||
|
||||
public IList asChoosableList() {
|
||||
ArrayList spells = new ArrayList();
|
||||
spells.Add(new { Name = "--", Display = "Base spells..."});
|
||||
foreach (XElement spell in (from sp in masterSpellList.Elements("spell")
|
||||
orderby (string)sp.Element("name")
|
||||
select sp)){
|
||||
spells.Add(new {
|
||||
Name = (string)spell.Element("name"),
|
||||
Display = (string)spell.Element("name") + (spell.Element("level") != null ? " (" + (string)spell.Element("level") + ")" : "")
|
||||
});
|
||||
}
|
||||
|
||||
return spells;
|
||||
}
|
||||
|
||||
public Spell byName(string name, Character.SpellCastingClasses characterClass) {
|
||||
string c = Character.getSpellcastingClassName(characterClass);
|
||||
Regex levelReg = new Regex(@" (\d+),?");
|
||||
return (from sp in masterSpellList.Elements("spell")
|
||||
let xmlLevel = (string)sp.Element("level")
|
||||
orderby (string)sp.Element("name")
|
||||
where (string)sp.Element("name") == name
|
||||
select new Spell {
|
||||
Name = (string)sp.Element("name"),
|
||||
AltName = (string)sp.Element("altname"),
|
||||
School = (string)sp.Element("school"),
|
||||
Subschool = (string)sp.Element("subschool"),
|
||||
Descriptor = (string)sp.Element("descriptor"),
|
||||
FullLevel = (string)sp.Element("level"),
|
||||
Level = int.Parse((xmlLevel.IndexOf(c) >= 0 ? levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value : levelReg.Match(xmlLevel).Groups[1].Value)),
|
||||
Components = (string)sp.Element("components"),
|
||||
CastingTime = (string)sp.Element("casting_time"),
|
||||
Range = (string)sp.Element("range"),
|
||||
Effect = (string)sp.Element("effect"),
|
||||
Target = (string)sp.Element("target"),
|
||||
Duration = (string)sp.Element("duration"),
|
||||
SavingThrow = (string)sp.Element("saving_throw"),
|
||||
SpellResistance = (string)sp.Element("sp_resistance"),
|
||||
ShortDescription = (string)sp.Element("short_description"),
|
||||
ArcaneMaterialComponents = (string)sp.Element("arcane_material_components"),
|
||||
Description = (string)sp.Element("description"),
|
||||
FullText = (string)sp.Element("full_text"),
|
||||
Reference = (string)sp.Element("reference")
|
||||
}).FirstOrDefault<Spell>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,57 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace d20_SRD_Spell_Lists.Models {
|
||||
public class Spell {
|
||||
public bool IsPrepped { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string AltName { get; set; }
|
||||
public string School { get; set; }
|
||||
public string Subschool { get; set; }
|
||||
public string Descriptor { get; set; }
|
||||
public int Level { get; set; }
|
||||
public string FullLevel {get; set;}
|
||||
public string Components { get; set; }
|
||||
public string CastingTime { get; set; }
|
||||
public string Range { get; set; }
|
||||
public string Effect { get; set; }
|
||||
public string Target { get; set; }
|
||||
public string Duration { get; set; }
|
||||
public string SavingThrow { get; set; }
|
||||
public string SpellResistance { get; set; }
|
||||
public string ShortDescription { get; set; }
|
||||
public bool IsCustom { get; set; }
|
||||
public bool IsCharCustom { get; set; }
|
||||
public string ArcaneMaterialComponents { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string FullText { get; set; }
|
||||
public string Reference { get; set; }
|
||||
|
||||
public void fromMasterSpell(XElement spell, string className) {
|
||||
Regex levelReg = new Regex(@" (\d+)?");
|
||||
|
||||
Name = (string)spell.Element("name");
|
||||
AltName = (string)spell.Element("altname");
|
||||
School = (string)spell.Element("school");
|
||||
Subschool = (string)spell.Element("subschool");
|
||||
Descriptor = (string)spell.Element("descriptor");
|
||||
FullLevel = (string)spell.Element("level");
|
||||
Level = int.Parse(levelReg.Match(FullLevel, FullLevel.IndexOf(className)).Groups[1].Value);
|
||||
Components = (string)spell.Element("components");
|
||||
CastingTime = (string)spell.Element("casting_time");
|
||||
Range = (string)spell.Element("range");
|
||||
Effect = (string)spell.Element("effect");
|
||||
Target = (string)spell.Element("target");
|
||||
Duration = (string)spell.Element("duration");
|
||||
SavingThrow = (string)spell.Element("saving_throw");
|
||||
SpellResistance = (string)spell.Element("spell_resistance");
|
||||
ShortDescription = (string)spell.Element("short_description");
|
||||
ArcaneMaterialComponents = (string)spell.Element("arcane_material_components");
|
||||
Description = (string)spell.Element("description");
|
||||
FullText = (string)spell.Element("full_text");
|
||||
Reference = (string)spell.Element("reference");
|
||||
}
|
||||
}
|
||||
|
||||
public class SpellComparer : IEqualityComparer<Spell> {
|
||||
|
||||
@@ -1,240 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using d20_SRD_Spell_Lists.Exceptions;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace d20_SRD_Spell_Lists.Models {
|
||||
public class SpellSet {
|
||||
private XElement masterSpellList;
|
||||
private XElement userSpellList;
|
||||
private XElement charSpellList;
|
||||
private string userXmlFile;
|
||||
private Character character;
|
||||
|
||||
public SpellSet(string _masterXmlFile = null, string _userXmlFile = null, Character _character = null) {
|
||||
userXmlFile = _userXmlFile;
|
||||
character = _character;
|
||||
loadXML(ref _masterXmlFile);
|
||||
}
|
||||
|
||||
private void loadXML(ref string _masterXmlFile) {
|
||||
// Load the XML file.
|
||||
if (_masterXmlFile == null) {
|
||||
_masterXmlFile = Properties.Settings.Default.MasterSpells;
|
||||
}
|
||||
if (userXmlFile == null) {
|
||||
userXmlFile = Properties.Settings.Default.UserSpells;
|
||||
}
|
||||
masterSpellList = XElement.Load(_masterXmlFile);
|
||||
userSpellList = XElement.Load(userXmlFile);
|
||||
|
||||
if (character != null) {
|
||||
charSpellList = character.spells();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a spell to the application's list of custom spells.
|
||||
/// </summary>
|
||||
/// <param name="xElement">The XML details of the new spell.</param>
|
||||
public void addUserSpell(XElement xElement) {
|
||||
userSpellList.Add(xElement);
|
||||
}
|
||||
|
||||
public IList<Spell> byClass(Character.SpellCastingClasses spellCastingClass) {
|
||||
List<Spell> spells = new List<Spell>();
|
||||
|
||||
filterMasterSpellsByClass(spellCastingClass, spells);
|
||||
filterUserSpellsByClass(spellCastingClass, spells);
|
||||
filterCharacterSpellsByClass(spellCastingClass, spells);
|
||||
|
||||
removeHiddenSpells(spells);
|
||||
|
||||
return spells;
|
||||
}
|
||||
|
||||
private void filterMasterSpellsByClass(Character.SpellCastingClasses spellCastingClass, List<Spell> spells) {
|
||||
spells.AddRange(querySpellsByClass(masterSpellList, spellCastingClass, false, false).ToList<Spell>());
|
||||
}
|
||||
|
||||
private void filterCharacterSpellsByClass(Character.SpellCastingClasses spellCastingClass, List<Spell> spells) {
|
||||
if (characterSpellCount() > 0) {
|
||||
spells.AddRange(querySpellsByClass(charSpellList, spellCastingClass, false, true));
|
||||
}
|
||||
}
|
||||
|
||||
private void filterUserSpellsByClass(Character.SpellCastingClasses spellCastingClass, List<Spell> spells) {
|
||||
if (userSpellCount() > 0) {
|
||||
spells.AddRange(querySpellsByClass(userSpellList, spellCastingClass, true, false).ToList<Spell>());
|
||||
}
|
||||
}
|
||||
|
||||
private void removeHiddenSpells(List<Spell> spells) {
|
||||
if (hiddenSpellCount() > 0) {
|
||||
foreach (string hiddenSpellName in (from hp in userSpellList.Elements("hidden_spell").Elements("spell")
|
||||
select (string)hp.Element("name"))) {
|
||||
spells.RemoveAll(sp => sp.Name == hiddenSpellName);
|
||||
}
|
||||
}
|
||||
|
||||
if (hiddenCharacterSpellCount() > 0) {
|
||||
foreach (string hiddenSpellName in (from hp in charSpellList.Elements("hidden_spell").Elements("spell")
|
||||
select (string)hp.Element("name"))) {
|
||||
spells.RemoveAll(sp => sp.Name == hiddenSpellName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Spell> byClassAndLevel(Character.SpellCastingClasses spellCastingClass, int level) {
|
||||
List<Spell> spells = new List<Spell>();
|
||||
|
||||
filterMasterSpellsByClassAndLevel(spellCastingClass, level, spells);
|
||||
filterUserSpellsByClassAndLevel(spellCastingClass, level, spells);
|
||||
filterCharacterSpellsByClassAndLevel(spellCastingClass, level, spells);
|
||||
|
||||
removeHiddenSpells(spells);
|
||||
|
||||
return spells;
|
||||
}
|
||||
|
||||
private void filterCharacterSpellsByClassAndLevel(Character.SpellCastingClasses spellCastingClass, int level, List<Spell> spells) {
|
||||
if (characterSpellCount() > 0) {
|
||||
spells.AddRange(querySpellsByClassAndLevel(charSpellList, spellCastingClass, level, false, true));
|
||||
}
|
||||
}
|
||||
|
||||
private void filterUserSpellsByClassAndLevel(Character.SpellCastingClasses spellCastingClass, int level, List<Spell> spells) {
|
||||
if (userSpellCount() > 0) {
|
||||
spells.AddRange(querySpellsByClassAndLevel(userSpellList, spellCastingClass, level, true, false).ToList<Spell>());
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Spell> querySpellsByClassAndLevel(XElement list, Character.SpellCastingClasses spellCastingClass, int level, bool isCustom, bool isCharCustom) {
|
||||
string c = Character.getClassName(spellCastingClass);
|
||||
Regex levelReg = new Regex(@" (\d+)?");
|
||||
return (from sp in list.Elements("spell")
|
||||
let xmlLevel = (string)sp.Element("level")
|
||||
let xmlComp = (string)sp.Element("components")
|
||||
let xmlDesc = (string)sp.Element("short_description")
|
||||
where xmlLevel != null && xmlLevel.Contains(c + " " + level.ToString())
|
||||
orderby levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value
|
||||
select new Spell {
|
||||
IsPrepped = false,
|
||||
Name = sp.Element("name").Value,
|
||||
Level = int.Parse(levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value),
|
||||
Components = (xmlComp != null ? xmlComp : ""),
|
||||
ShortDescription = (xmlDesc != null ? xmlDesc : ""),
|
||||
IsCustom = isCustom,
|
||||
IsCharCustom = isCharCustom
|
||||
});
|
||||
}
|
||||
|
||||
private IEnumerable<Spell> querySpellsByClass(XElement list, Character.SpellCastingClasses spellCastingClass, bool isCustom, bool isCharCustom) {
|
||||
string c = Character.getClassName(spellCastingClass);
|
||||
Regex levelReg = new Regex(@" (\d+),?");
|
||||
return (from sp in list.Elements("spell")
|
||||
let xmlLevel = (string)sp.Element("level")
|
||||
let xmlComp = (string)sp.Element("components")
|
||||
let xmlDesc = (string)sp.Element("short_description")
|
||||
where xmlLevel != null && xmlLevel.Contains(c)
|
||||
orderby levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value
|
||||
select new Spell {
|
||||
IsPrepped = false,
|
||||
Name = sp.Element("name").Value,
|
||||
Level = int.Parse(levelReg.Match(xmlLevel, xmlLevel.IndexOf(c)).Groups[1].Value),
|
||||
Components = (xmlComp != null ? xmlComp : ""),
|
||||
ShortDescription = (xmlDesc != null ? xmlDesc : ""),
|
||||
IsCustom = isCustom,
|
||||
IsCharCustom = isCharCustom
|
||||
});
|
||||
}
|
||||
|
||||
private void filterMasterSpellsByClassAndLevel(Character.SpellCastingClasses spellCastingClass, int level, List<Spell> spells) {
|
||||
spells.AddRange(querySpellsByClassAndLevel(masterSpellList, spellCastingClass, level, false, false).ToList<Spell>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves all XML files to the system.
|
||||
/// </summary>
|
||||
public void save() {
|
||||
userSpellList.Save(userXmlFile);
|
||||
if (character != null) {
|
||||
character.save();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a node from the application's custom spell list.
|
||||
/// </summary>
|
||||
/// <param name="nodeName">The name of the node to be searched on. Could be "name", "school", etc.</param>
|
||||
/// <param name="nodeValue">The value of the node matching the nodeName.</param>
|
||||
public void removeUserSpell(string nodeName, string nodeValue) {
|
||||
(from sp in userSpellList.Elements("spell")
|
||||
where (string)sp.Element(nodeName) == nodeValue
|
||||
select sp).Remove();
|
||||
}
|
||||
|
||||
public void hideMasterSpell(string nodeName, string nodeValue) {
|
||||
userSpellList.Add(new XElement("hidden_spell", (from msp in masterSpellList.Elements("spell")
|
||||
where (string)msp.Element(nodeName) == nodeValue
|
||||
select msp)));
|
||||
}
|
||||
|
||||
public void hideMasterSpellForCharacter(string nodeName, string nodeValue) {
|
||||
charSpellList.Add(new XElement("hidden_spell", (from msp in masterSpellList.Elements("spell")
|
||||
where (string)msp.Element(nodeName) == nodeValue
|
||||
select msp)));
|
||||
}
|
||||
|
||||
public void showMasterSpell(string nodeName, string nodeValue) {
|
||||
(from hsp in userSpellList.Elements("hidden_spell")
|
||||
where (string)hsp.Element("spell").Element(nodeName) == nodeValue
|
||||
select hsp).Remove();
|
||||
}
|
||||
|
||||
public void showMasterSpellForCharacter(string nodeName, string nodeValue) {
|
||||
(from hsp in charSpellList.Elements("hidden_spell")
|
||||
where (string)hsp.Element("spell").Element(nodeName) == nodeValue
|
||||
select hsp).Remove();
|
||||
}
|
||||
|
||||
public int hiddenSpellCount() {
|
||||
return userSpellList.Descendants("hidden_spell").Count();
|
||||
}
|
||||
|
||||
public int hiddenCharacterSpellCount() {
|
||||
if (charSpellList != null) {
|
||||
return charSpellList.Descendants("hidden_spell").Count();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int totalCount() {
|
||||
int total = masterSpellList.Elements("spell").Count() + userSpellList.Elements("spell").Count();
|
||||
if (charSpellList != null) {
|
||||
total += charSpellList.Elements("spell").Count();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int masterSpellCount() {
|
||||
return masterSpellList.Elements("spell").Count();
|
||||
}
|
||||
|
||||
public int userSpellCount() {
|
||||
return userSpellList.Elements("spell").Count();
|
||||
}
|
||||
|
||||
public int characterSpellCount() {
|
||||
if (character != null) {
|
||||
return character.spells().Elements("spell").Count();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user