Example #1
0
        private static void ParseResists(string text, Race race)
        {
            foreach (string part in text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
            {
                RaceResist resist      = RaceResist.None;
                string     elementName = String.Empty;

                // note: because of the repeated characters, the order of the clauses below is important
                //       (part.StartsWith("-") will match both "-fire" and "--fire")
                if (part.StartsWith("*"))
                {
                    resist      = RaceResist.Immune;
                    elementName = part.Substring(1);
                }
                else if (part.StartsWith("--"))
                {
                    resist      = RaceResist.VeryWeak;
                    elementName = part.Substring(2);
                }
                else if (part.StartsWith("-"))
                {
                    resist      = RaceResist.Weak;
                    elementName = part.Substring(1);
                }
                else if (part.StartsWith("++"))
                {
                    resist      = RaceResist.VeryStrong;
                    elementName = part.Substring(2);
                }
                else if (part.StartsWith("+"))
                {
                    resist      = RaceResist.Strong;
                    elementName = part.Substring(1);
                }
                else if (part.StartsWith("."))
                {
                    resist      = RaceResist.None;
                    elementName = part.Substring(1);
                }
                else
                {
                    throw new Exception("Could not parse resist field \"" + text + "\".");
                }

                Element element = (Element)Enum.Parse(typeof(Element), elementName, true);
                race.SetResist(element, resist);
            }
        }
Example #2
0
 public void SetResist(Element element, RaceResist resistance)
 {
     mResists[element] = resistance;
 }