private void UpdateStatsByModifiers(Descriptor descriptor) { if (descriptor != null && descriptor.GetType() == typeof (Race) && Classes.Count > 0) { var modifiers = new Dictionary<StatType, object[]>(); float totalPercents = 0; foreach (Class c in Classes) { foreach (Modifier modifier in c.Modifiers) { if (!modifiers.ContainsKey(modifier.Stat)) modifiers.Add(modifier.Stat, new object[] {new Modifier(), 0}); var m = (Modifier) modifiers[modifier.Stat][0]; var total = (int) modifiers[modifier.Stat][1]; m.PercentValue += modifier.PercentValue; m.Value += modifier.Value; modifiers[modifier.Stat][1] = ++total; } } foreach (var modifier in modifiers) { var m = (Modifier) modifier.Value[0]; var total = (short) modifier.Value[1]; m.PercentValue /= total; m.Value /= total; totalPercents += m.PercentValue; } if (totalPercents < 100) totalPercents = 100; int pointWeight = _random.Next(1, 101); int pointWeightTotal = 0; int numStats = 0; for (int i = 0; i < _numPointWeights.Length; ++i) { pointWeightTotal += _numPointWeights[i]; if (pointWeight <= pointWeightTotal) { if (_numPointWeights[i] - 6 < 0) { int spread = _numPointWeights[i]; _numPointWeights[i] = 0; for (int j = 0; j < spread; ++j) { int index = j%_numPointWeights.Length; if (i != index) ++_numPointWeights[index]; else ++spread; } } else { for (int j = 0; j < _numPointWeights.Length; ++j) { if (i != j) _numPointWeights[j] += 2; else _numPointWeights[j] -= 6; } } numStats = i + 2; break; } } for (int i = 0; i < numStats; ++i) { int weight = _random.Next(1, (int) Math.Round(totalPercents) + 1); float weightTotal = 0; foreach (var modifier in modifiers) { var m = (Modifier) modifier.Value[0]; weightTotal += m.PercentValue; if (weight <= weightTotal) { int modifierValue = m.Value; if (modifierValue == 0) modifierValue = 1; BaseStats[modifier.Key] += modifierValue; EffectiveStats[modifier.Key] += modifierValue; break; } } } } }
private void UpdateStats(Descriptor oldDescriptor, Descriptor newDescriptor) { if ((oldDescriptor != null && oldDescriptor.GetType() == typeof (Race)) || (newDescriptor != null && newDescriptor.GetType() == typeof (Race))) { var oldRace = (Race) oldDescriptor; var newRace = (Race) newDescriptor; if (oldDescriptor != null) { BaseStats -= oldRace.Stats; EffectiveStats -= oldRace.Stats; } else { if (BaseStats != 0 && EffectiveStats != 0) { BaseStats -= newRace.Stats; EffectiveStats -= newRace.Stats; } } if (newDescriptor != null) { BaseStats += newRace.Stats; EffectiveStats += newRace.Stats; } } }
private void UpdateLevels(Descriptor descriptor) { RemoveCharacteristicsOutOfLevel(descriptor); UpdateStatsByModifiers(descriptor); UpdateModifiersByLevel(); }
private void UpdateDescriptors(Descriptor oldDescriptor, Descriptor newDescriptor) { UpdateCharacteristics(oldDescriptor, newDescriptor); UpdateStats(oldDescriptor, newDescriptor); }
private void UpdateCharacteristics(Descriptor oldDescriptor, Descriptor newDescriptor) { if (oldDescriptor != null) { foreach (var ability in oldDescriptor.AbilityList) { if (newDescriptor == null || !newDescriptor.AbilityList.ContainsKey(ability.Key)) CurrentAbilities.Remove(ability.Key); } foreach (var skill in oldDescriptor.SkillList) { if (newDescriptor == null || !newDescriptor.SkillList.ContainsKey(skill.Key)) CurrentSkills.Remove(skill.Key); } foreach (var trait in oldDescriptor.TraitList) { if (newDescriptor == null || !newDescriptor.TraitList.ContainsKey(trait.Key)) { Modifiers.Remove(CurrentTraits[trait.Key].Modifier); CurrentTraits.Remove(trait.Key); } } } if (newDescriptor != null) { for (int i = 0; i <= newDescriptor.Level; ++i) { List<int> list = newDescriptor.GetAbilityListByLevel(i); foreach (int id in list) { if (!Abilities.ContainsKey(id)) // TODO: Create ability from factory Abilities.Add(id, new Ability()); if (!CurrentAbilities.ContainsKey(id)) CurrentAbilities.Add(id, Abilities[id]); } list = newDescriptor.GetTraitListByLevel(i); foreach (int id in list) { if (!Traits.ContainsKey(id)) // TODO: Create trait from factory Traits.Add(id, new Trait()); if (!CurrentTraits.ContainsKey(id)) { Modifiers.Add(Traits[id].Modifier); CurrentTraits.Add(id, Traits[id]); } } } } }
private void RemoveCharacteristicsOutOfLevel(Descriptor descriptor) { var keys = new List<int>(); foreach (var ability in CurrentAbilities) { if (descriptor.AbilityList[ability.Key] > descriptor.Level) keys.Add(ability.Key); } foreach (int key in keys) CurrentAbilities.Remove(key); keys.Clear(); foreach (var skill in CurrentSkills) { if (descriptor.SkillList[skill.Key] > descriptor.Level) keys.Add(skill.Key); } foreach (int key in keys) CurrentSkills.Remove(key); keys.Clear(); foreach (var trait in CurrentTraits) { if (descriptor.TraitList[trait.Key] > descriptor.Level) keys.Add(trait.Key); } foreach (int key in keys) CurrentTraits.Remove(key); }