public bool AddSpellpage(int pageNumber) { if (!IsLegalPageNumber(pageNumber)) { throw new System.Exception("Illegal page number"); } if (spellpages[pageNumber] != null) { //Must first remove the existing Spellpage return(false); } spellpages[pageNumber] = new Spellpage(this); observers.ForEach(o => o.OnSpellpageAdded(pageNumber)); return(true); }
public Spellbook() { energies = new SortedDictionary <SpellAttribute, int>(Comparer <SpellAttribute> .Create((x, y) => x.CompareTo(y))); Energies = new System.Collections.ObjectModel.ReadOnlyDictionary <SpellAttribute, int>(energies); foreach (SpellAttribute energy in energies.Keys) { energies[energy] = 0; } castRuneModifiers = new List <ICastRuneModifier>(); CastRuneModifiers = castRuneModifiers.AsReadOnly(); storedRunes = new List <Rune>(); StoredRunes = storedRunes.AsReadOnly(); spellpages = new Spellpage[MaxPageNumber + 1]; //+1 is because API is one-indexed; note that we "waste" the zeroth index }
public bool CastSpell(int pageNumber) { if (!IsLegalPageNumber(pageNumber)) { throw new System.Exception("Illegal page number"); } if (!CanCastSpell(pageNumber)) { return(false); } Spellpage spellpage = GetSpellpage(pageNumber); //TODO: Adjust Energies based on energy requirements observers.ForEach(o => o.OnSpellCast(pageNumber)); observers.ForEach(o => o.OnEnergiesChanged(Energies)); //Remember, casting a spell consumes energy. return(true); }