public UnitGroup(string line, bool immuneSystem) { string[] words = line.Split(' '); UnitCount = int.Parse(words[0]); HP = int.Parse(words[4]); Initiative = int.Parse(words[words.Length - 1]); Damage = int.Parse(words[words.Length - 6]); DamageType = words[words.Length - 5]; ImmuneSystem = immuneSystem; int openIndex = line.IndexOf('('); int closeIndex = line.IndexOf(')'); if (openIndex != -1) { openIndex += 1; string resistances = line.Substring(openIndex, closeIndex - openIndex); string[] resistanceWords = resistances.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries); bool immuneState = true; for (int i = 0; i < resistanceWords.Length; i++) { switch (resistanceWords[i]) { case "immune": //Set state to Immunities immuneState = true; break; case "weak": //Set state to Weaknesses immuneState = false; break; case "to": //Skip meaningless word break; case "bludgeoning": case "radiation": case "slashing": case "cold": case "fire": DamageMultipliers.Add(resistanceWords[i], immuneState ? 0 : 2); break; default: throw new Exception($"Unexpected Keyword: {resistanceWords[i]}"); } } } }