public void addAbility(Ability ability) { //Remove the ability from any list it may be in. if (BasicAttacks.Contains(ability)) { BasicAttacks.Remove(ability); } if (SpecialAttacks.Contains(ability)) { SpecialAttacks.Remove(ability); } if (SpecialAbilities.Contains(ability)) { SpecialAbilities.Remove(ability); } //Add the ability to the appropriate container. if (ability.Type == Ability.AbilityType.Basic) { BasicAttacks.Add(ability); } if (ability.Type == Ability.AbilityType.Special) { SpecialAttacks.Add(ability); } if (ability.Type == Ability.AbilityType.Ability || ability.Type == Ability.AbilityType.Passive) { SpecialAbilities.Add(ability); } //Update the character points updateCharacterPoints(); }
/// <summary> /// Rentre les valeurs /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <param name="dico"></param> private bool SetCharacterize <T>(T t) where T : IRepository <T> { List <string> items = new List <string>(); List <Features> features = new List <Features>(); Dictionary <string, int> dico = new Dictionary <string, int>(); bool switchToArray = false; int i = 1; string message = string.Concat("Il manque les caractéristiques suivantes :", Environment.NewLine); _missed = new List <string>(); if (t.GetType() == typeof(Features)) { _missed.Add(string.Concat("Il manque les caractéristiques suivantes :", Environment.NewLine)); message = string.Concat("Il manque les caractéristiques suivantes :", Environment.NewLine); } if (!CheckCharacterize(t, ref dico)) { throw new CharacterException(string.Concat(_missed)); } foreach (KeyValuePair <string, int> item in dico) { switch (t) { case Features f: f = new Features { Id = i, Name = item.Key, Value = item.Value }; features.Add(f); switchToArray = true; break; case Skills s: s = new Skills { Id = i, Name = item.Key, Value = item.Value }; Skills.Add(s); break; case SpecialAbilities sa: sa = new SpecialAbilities { Id = i, Name = item.Key, Value = item.Value }; SpecialAbilities.Add(sa); break; case Ressources r: r = new Ressources { Id = i, Name = item.Key, Value = item.Value }; Ressources.Add(r); break; default: throw new CharacterException("Données inconnues"); } i++; } if (switchToArray) { Features = features.ToArray(); } return(true); }