private void CheckAppliedTemplates(TemplateManager.TemplateManager TM, ref MonsterStatBlock TestMonSB)
        {
            string CheckName        = "CheckAppliedTemplates";
            bool   stackedTemplates = false;

            if (MonSB.TemplatesApplied.Contains(","))
            {
                stackedTemplates = true;                                       //|1,2,3…@sk|
            }
            List <string> templates = MonSB.TemplatesApplied.Split('|').ToList <string>();

            templates.Remove("");
            List <string> stackedTemplateList = new List <string>();
            string        stackedTemplateBase = string.Empty;

            if (stackedTemplates)
            {
                FindStackTemplates(templates, ref stackedTemplateList, ref stackedTemplateBase);
            }


            foreach (string appliedTemplate in templates)
            {
                string lowerAppliedTemplate = appliedTemplate.ToLower();
                if (lowerAppliedTemplate.Contains("advanced") || lowerAppliedTemplate.Contains("advanced hd"))
                {
                    if (MonSB.HDValue() - CharacterClasses.FindTotalClassLevels() != Race_Base.RacialHDValue())
                    {
                        TestMonSB = ApplyAdvancedHDTemplate(TM, TestMonSB);
                    }
                    else
                    {
                        if (TestMonSB != null)
                        {
                            List <string> Failures;
                            if (stackedTemplates)
                            {
                                TestMonSB = ApplyStackedTemplates(TM, TestMonSB, stackedTemplateList, stackedTemplateBase, out Failures);
                            }
                            else
                            {
                                if (templates.Count == 1)
                                {
                                    TestMonSB = ApplyOneTemplate(CheckName, TM, TestMonSB);
                                }
                                else
                                {
                                    TestMonSB = ApplyMultipleTemplates(TM, TestMonSB, templates, stackedTemplateList);
                                }
                            }
                            Race_Base.ApplyTemplatedRaceSB(TestMonSB, true);
                        }
                    }
                }
                else
                {
                    if (TestMonSB != null)
                    {
                        bool             Success;
                        MonsterStatBlock tempmonSB = null;
                        List <string>    Failures;

                        if (stackedTemplates)
                        {
                            TestMonSB = ApplyStackedTemplates(TM, TestMonSB, stackedTemplateList, stackedTemplateBase, out Failures);
                            Success   = !Failures.Any();
                        }
                        else
                        {
                            TM.ApplyTemplate(TestMonSB, lowerAppliedTemplate.Trim(), out Success);
                        }
                        if (tempmonSB != null)
                        {
                            TestMonSB = tempmonSB;
                        }
                        if (!Success)
                        {
                            _messageXML.AddFail("CheckTemplates", "Template not applied for " + lowerAppliedTemplate.Trim());
                        }
                        else
                        {
                            _messageXML.AddInfo("Template Applied - " + lowerAppliedTemplate.Trim());
                            Race_Base.ApplyTemplatedRaceSB(TestMonSB, true);
                        }
                    }
                }
            }
        }