private void ManageBlockEquipment(Creature c, HtmlNode currentPar, MonsterStatType monsterStatType)
        {
            switch (monsterStatType)
            {
            case MonsterStatType.Old:
                c.Equipment = CleanHtml(currentPar.InnerText.Replace("Equipment: ", "")).Trim();
                break;

            case MonsterStatType.MM3:
                //should not happen
                throw new NotImplementedException();
            }
        }
        private void ManageBlockAlignement(Creature c, HtmlNode currentPar, MonsterStatType monsterStatType)
        {
            string skills = GetTextUntilTag(currentPar.InnerHtml, "<b>Skills</b>");

            if (!String.IsNullOrEmpty(skills))
            {
                if (!string.IsNullOrEmpty(c.Skills))
                { //perception already in skills
                    c.Skills += ", ";
                }
                c.Skills += skills.Trim();
            }
            ReadAbilities(c, currentPar.InnerHtml);
        }
Example #3
0
        public short GetStat(MonsterStatType statType)
        {
            switch (statType)
            {
                case MonsterStatType.HP:
                    return HP;
                case MonsterStatType.Attack:
                    return Attack;
                case MonsterStatType.Defense:
                    return Defense;
                case MonsterStatType.SpecialAttack:
                    return SpecialAttack;
                case MonsterStatType.SpecialDefense:
                    return SpecialDefense;
                case MonsterStatType.Speed:
                    return Speed;
            }

            return 0;
        }
        public static short CalculateStat(MonsterInstanceData instanceData, MonsterStatType statType)
        {
            if (statType == MonsterStatType.HP)
                return CalculateHP(instanceData);

            // Stat = 
            // floor((floor(((2 * base + IV + floor(EV / 4)) * level) / 100) + 5) * nature)

            int IV = instanceData.IV.GetStat(statType);
            int EV = instanceData.EV.GetStat(statType);
            int baseStat = instanceData.StaticData.BaseStats.GetStat(statType);

            double nature = 1.0d;

            //if (Monster.Nature.StatIncrease.Contains(statType))
            //    nature = 1.1d;
            //else if (Monster.Nature.StatDecrease.Contains(statType))
            //    nature = 0.9d;

            return (short) ((Math.Floor((Math.Floor(2 * baseStat + IV + Math.Floor((double) EV / 4)) * instanceData.Level) / 100) + 5) * nature);
        }
        /// <summary>
        /// Set the recharge text, and PowerUse to Encounter
        /// </summary>
        /// <param name="html">The HTML.</param>
        /// <param name="cp">The cp.</param>
        private void CalculateRecharge(string html, CreaturePower cp, MonsterStatType version)
        {
            cp.Action.Use = PowerUseType.Encounter;
            //if (currentPar.InnerHtml.Contains("/images/symbol/1a.gif"))
            //{
            //    cp.Action.Recharge=
            //}
            if (html.Contains("/images/symbol/2a.gif"))
            {
                cp.Action.Recharge = "Recharges on 2-6";
                return;
            }
            if (html.Contains("/images/symbol/3a.gif"))
            {
                cp.Action.Recharge = "Recharges on 3-6";
                return;
            }
            if (html.Contains("/images/symbol/4a.gif"))
            {
                cp.Action.Recharge = "Recharges on 4-6";
                return;
            }
            if (html.Contains("/images/symbol/5a.gif"))
            {
                cp.Action.Recharge = "Recharges on 5-6";
                return;
            }
            if (html.Contains("/images/symbol/6a.gif"))
            {
                cp.Action.Recharge = "Recharges on 6";
                return;
            }
            if (version == MonsterStatType.MM3)
            {
                html = html.Replace("<b>", "");
                html = html.Replace("</b>", "");
                cp.Action.Recharge = CleanExtraComma(GetTextUntilTag(html, null));
                return;
            }
            string match = " at the end of the ";

            if (!html.Contains(match))
            {
                match = " at the start ";
            }
            if (!html.Contains(match))
            {
                match = " when ";
            }
            if (!html.Contains(match))
            {
                match = " if ";
            }
            if (!html.Contains(match))
            {
                match = " after ";
            }
            if (html.Contains(match))
            {
                int pos = html.IndexOf(match);
                html = html.Substring(pos);
                cp.Action.Recharge = "Recharge " + CleanExtraComma(GetTextUntilTag(html, null));
                if (cp.Action.Recharge.EndsWith(")"))
                {
                    cp.Action.Recharge = cp.Action.Recharge.Substring(0, cp.Action.Recharge.Length - 1);
                }
                return;
            }
            if (html.ToLower().Contains(" , or recharge ")) // Ancien abyssal Wurm: <b>Recharge 6 , or recharge 5 while bloodied</b>
            {
                html = html.Replace("<b>", "");
                cp.Action.Recharge = CleanExtraComma(GetTextUntilTag(html, null));
                return;
            }
            throw new Exception("Invalid recharge value " + html);
        }
 private void ManageblockUpdate(Creature c, string update, MonsterStatType monsterStatType)
 {
 }
        private void ReadPowers(Creature c, HtmlNode monsterNode, MonsterStatType versionStat)
        {
            bool               IsTrait = false;
            HtmlNode           currentPar;
            HtmlNodeCollection paragraphs = null;

            switch (versionStat)
            {
            case MonsterStatType.Old:
                paragraphs = monsterNode.SelectNodes("//p");    //[@class='flavor alt']");

                break;

            case MonsterStatType.MM3:
                paragraphs = monsterNode.SelectNodes(("//h2|//p"));
                int pos = monsterNode.ParentNode.InnerText.IndexOf("Equipment:");
                if (pos > -1)
                {
                    pos += "Equipment:".Length;
                    int pos2 = monsterNode.ParentNode.InnerText.IndexOf("Published", pos);
                    c.Equipment = CleanHtml(monsterNode.ParentNode.InnerText.Substring(pos, pos2 - pos));
                }
                // currentPar = monsterNode.SelectSingleNode(("//h2"));
                //currentPar = currentPar.NextSibling;
                //  Debug.Assert(currentPar.Name == "h2");
                break;

            default:
                throw new ArgumentException("Invalid monsterStatType " + versionStat);
            }
            ActionType currentActionType = ActionType.None;

            for (int posParagraph = 0; posParagraph < paragraphs.Count(); posParagraph++)
            {
                currentPar = paragraphs[posParagraph];
                string innerHtmlPar = currentPar.InnerHtml.Trim();
                if (String.IsNullOrEmpty(innerHtmlPar.Trim()))
                {
                    continue;
                }
                if (innerHtmlPar.StartsWith("<b>Initiative</b>"))
                {
                    continue;
                }
                if (innerHtmlPar.StartsWith("<b>Str</b>"))
                {
                    ReadAbilities(c, innerHtmlPar);
                    continue;
                }

                if (innerHtmlPar.StartsWith("<b>Skills</b>"))
                {
                    ManageBlockAlignement(c, currentPar, versionStat);
                    continue;
                }
                if (innerHtmlPar.StartsWith("<b>Alignment") || (currentPar.Name == "b" && innerHtmlPar.StartsWith("Alignment")))
                {
                    ManageBlockAlignement(c, currentPar, versionStat);
                    continue;
                }
                if (innerHtmlPar.StartsWith("<b>Equipment"))// || (currentPar.Name == "b" && innerHtmlPar.StartsWith("Equipment")))
                {
                    ManageBlockEquipment(c, currentPar, versionStat);
                    continue;
                }
                if (innerHtmlPar.StartsWith("<b>Description"))
                {
                    ManageBlockDescription(c, currentPar);
                    currentPar = currentPar.NextSibling;
                    continue;
                }
                if (innerHtmlPar.StartsWith("Published in"))
                {
                    ManageBlockPublished(c, currentPar, versionStat);
                    currentPar = currentPar.NextSibling;
                    continue;
                }
                if (innerHtmlPar.StartsWith("Update"))
                {
                    string update = innerHtmlPar;
                    while (currentPar.NextSibling != null && currentPar.NextSibling.Name != "<p>")
                    {
                        currentPar = currentPar.NextSibling;
                        update    += Environment.NewLine + innerHtmlPar;
                    }
                    ManageblockUpdate(c, update, versionStat);
                    continue;
                }
                if (versionStat == MonsterStatType.MM3)
                {
                    if (currentPar.Name == "h2")
                    {
                        IsTrait = innerHtmlPar.Trim() == "Traits";
                        if (innerHtmlPar == "Standard Actions")
                        {
                            currentActionType = ActionType.Standard;
                        }
                        if (innerHtmlPar == "Minor Actions")
                        {
                            currentActionType = ActionType.Minor;
                        }
                        if (innerHtmlPar == "Move Actions")
                        {
                            currentActionType = ActionType.Move;
                        }
                        if (innerHtmlPar == "Triggered Actions")
                        {
                            currentActionType = ActionType.Reaction;
                        }
                        continue;
                    }
                }
                if (currentPar.Name != "p" || (currentPar.Attributes["class"].Value == "flavorIndent") || currentPar.InnerHtml.StartsWith("<i>")) //power details
                {
                    continue;
                }
                if (currentPar.InnerHtml.Contains("<b>Aura</b>"))
                {
                    continue;
                }
                CreaturePower cp = new CreaturePower();
                cp.Name = GetTextUntilTag(innerHtmlPar, "<b>");
                string afterName = GetTextUntilTag(innerHtmlPar, "</b>");
                cp.Keywords = GetTextUntilTag(innerHtmlPar, "<b>", 2) ?? String.Empty;
                string src = String.Empty;
                if (currentPar.FirstChild.Name == "img")
                {
                    src = currentPar.FirstChild.Attributes["src"].Value.ToString();
                }
                cp.Action = new PowerAction();
                if (_regBasicAttack.Match(src).Success)
                {
                    cp.Action.Use = PowerUseType.Basic;
                }
                if (src.Contains("symbol/Z2a.gif"))
                {
                    cp.Range = "Melee";
                }

                string powerTitleHtml = innerHtmlPar;
                currentPar = currentPar.NextSibling;
                switch (versionStat)
                {
                case MonsterStatType.Old:
                    ReadOldPower(currentPar, cp, String.IsNullOrEmpty(src)     //trait should have no action image
                                 , afterName, powerTitleHtml);
                    currentPar = currentPar.NextSibling;
                    while ((currentPar != null) && (currentPar.Name == "p") && (currentPar.Attributes["class"] != null) && (currentPar.Attributes["class"].Value.ToLower() == "flavorindent"))
                    {     // more details for action
                        cp.Details = cp.Details + Environment.NewLine + CleanHtml(currentPar.InnerText);
                        posParagraph++;
                        currentPar = currentPar.NextSibling;
                    }
                    break;

                case MonsterStatType.MM3:
                    if (IsTrait)
                    {
                        cp.Action = null;
                    }
                    else
                    {
                        cp.Action.Action = currentActionType;
                    }
                    currentPar = ReadMM3Power(currentPar, cp, IsTrait, powerTitleHtml.Replace("  ", " "));
                    break;

                default:
                    throw new ArgumentException("Invalid monsterStatType " + versionStat);
                }

                c.CreaturePowers.Add(cp);
            }
        }
        /// <summary>
        /// Extracts the auras from HTML.
        /// </summary>
        /// <param name="c">Current Creature.</param>
        /// <param name="html">The HTML.</param>
        /// <param name="version">The version.</param>
        private void ExtractAurasFromHtml(Creature c, string html, MonsterStatType version)
        {
            int auraStartsAt = GetAuraPos(html, 0);

            while (auraStartsAt > 0)
            {
                int pos2 = html.ToLower().LastIndexOf("<b>", auraStartsAt); // farther than the name, so go back to find it
                if (pos2 == -1)
                {
                    break;
                }
                Aura aura = new Aura();
                aura.Name = GetTextUntilTag(html.Substring(pos2), "<b>");
                string temp = html.Substring(pos2 + aura.Name.Length + 7).Trim();
                if (temp.StartsWith(">"))
                {
                    temp = temp.Substring(1).Trim();
                }
                int pos;
                if (temp.StartsWith("(")) //keyword
                {
                    pos           = temp.IndexOf(")");
                    aura.Keywords = Upper1(CleanHtml(temp.Substring(1, pos - 1)));
                }

                if (version == MonsterStatType.MM3)
                {
                    pos = temp.ToLower().IndexOf("<b>aura</b>") + "<b>aura</b>".Length;
                }
                else
                {
                    pos = temp.ToLower().IndexOf("aura ") + "aura ".Length;
                }
                temp         = temp.Substring(pos).Trim().Replace("  ", " ");
                aura.Details = GetTextUntilTag(temp, null);
                pos2         = aura.Details.IndexOf(";");
                if (pos2 < 5)
                {
                    if (pos2 == -1)
                    { // for postMM3
                        pos2          = temp.IndexOf("<p ");
                        pos2          = temp.IndexOf(">", pos2) + 1;
                        temp          = temp.Substring(pos2);
                        temp          = GetTextUntilTag(temp, null);
                        aura.Details += ": " + temp;
                        auraStartsAt += aura.Details.Length + 40; // text + img link size
                    }
                    else
                    {
                        aura.Details = aura.Details.Remove(pos2, 1).Insert(pos2, ":");
                        auraStartsAt = html.ToLower().IndexOf(" aura ", auraStartsAt) + 10 + 1;
                    }
                }
                else
                {
                    auraStartsAt = html.ToLower().IndexOf(" aura ", auraStartsAt) + 10 + 1;
                }
                c.Auras.Add(aura);
                auraStartsAt = GetAuraPos(html, auraStartsAt);
            }
        }
        public override Creature GetMasterPlanObjectFromDoc(HtmlDocument doc, List <string> warnings)
        {
            string temp, temp2;
            int    pos;

            string[] tempArray;
            Creature c = new Creature();

            if (doc.DocumentNode.InnerText.Contains("Get full access"))
            {
                throw new Exception("Stuck on login page !");
            }
            HtmlNode monsterNode = doc.DocumentNode.SelectSingleNode("//h1[attribute::class='monster']");
            HtmlNode detailNode  = doc.DocumentNode.SelectSingleNode("//div[attribute::id='detail']");
            HtmlNode levelBlock  = monsterNode.SelectSingleNode("//span[@class='level']");

            c.Name      = CleanHtml(monsterNode.FirstChild.InnerText);
            CurrentName = c.Name;
            if (levelBlock == null)
            {
                throw new InvalidStructureException("no level found", c.Name);
            }
            HtmlNode current = monsterNode.SelectSingleNode("//span[@class='type']");

            temp = current.InnerText;
            if (temp.Contains("("))
            {
                tempArray  = temp.Split(new string[] { "(" }, 2, StringSplitOptions.RemoveEmptyEntries);
                c.Keywords = CleanParenthesis(tempArray[1]);
                temp       = tempArray[0].Trim();
            }
            if (temp.Contains(",")) //keywords
            {
                Trace.Assert(String.IsNullOrEmpty(c.Keywords));
                tempArray  = temp.Split(new string[] { "," }, 2, StringSplitOptions.RemoveEmptyEntries);
                c.Keywords = CleanParenthesis(tempArray[1].Trim());
                temp       = tempArray[0].Trim();
            }
            temp      = temp.Replace("magical beast", "MagicalBeast");
            tempArray = temp.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            if (tempArray.Count() < 3)
            {
                if (!HardFix(c))
                {
                    SetPhenotypeValues(tempArray, c);
                }
            }
            else
            {
                SetPhenotypeValues(tempArray, c);
            }


            int level;

            c.Role  = GetLevelAndRoleFrom(levelBlock.InnerText, out level).Copy();
            c.Level = level;

            HtmlNodeCollection paragraphs = monsterNode.SelectNodes("//h2");
            MonsterStatType    version    = MonsterStatType.Old;

            if (paragraphs != null)
            {
                version = MonsterStatType.MM3;
            }
            ExtractAurasFromHtml(c, detailNode.InnerHtml, version);
            Match match = _regAlignement.Match(detailNode.InnerText);

            c.Alignment = CleanHtml(match.Value.Substring(match.Value.IndexOf(" ")));
            Debug.Assert(!String.IsNullOrEmpty(c.Alignment));
            match = _RegLanguagesHtml.Match(detailNode.InnerHtml);
            Debug.Assert(match.Success);
            c.Languages = GetTextUntilTag(detailNode.InnerHtml.Substring(match.Index + match.Value.Length), "");
            if (c.Languages == "-")
            {
                c.Languages = "";
            }
            temp         = detailNode.InnerHtml;
            c.HP         = GetIntValue(temp, "<b>HP</b>");
            c.Initiative = GetIntValue(temp, "<b>Initiative</b>");
            c.AC         = GetIntValue(temp, "<b>AC</b>");
            c.Fortitude  = GetIntValue(temp, "<b>Fortitude</b>");
            c.Reflex     = GetIntValue(temp, "<b>Reflex</b>");
            c.Will       = GetIntValue(temp, "<b>Will</b>");
            c.Movement   = GetSpeed(temp, warnings);

            c.Immune = GetTextUntilTag(temp, "<b>Immune</b>") ?? String.Empty;
            AddVulnerab(c, temp);
            SetRegeneration(c, temp);
            temp2 = GetTextUntilTag(temp, "<b>Senses</b>");
            if (string.IsNullOrEmpty(temp2))
            {
                temp2 = GetTextUntilTag(temp, "<b>Perception</b>");
            }

            temp2 = temp2.Replace("Perception", "").Trim();
            if (string.IsNullOrEmpty(temp2)) // Xander GravelStoke is wrong in compendium (2011/10/22)
            {
                c.Skills = "Perception Invalid";
            }
            else
            {
                c.Skills = "Perception " + AsBonus(GetIntValue(temp2, null));
            }

            if (temp2.Contains(';'))
            {
                c.Senses = Upper1(CleanHtml(temp2.Substring(temp2.IndexOf(";") + 1)));
            }
            else
            {
                if (version == MonsterStatType.MM3)
                {
                    pos      = temp.IndexOf("<b>Perception</b>");
                    temp2    = temp.Substring(pos);
                    c.Senses = GetTextUntilTag(temp2, "<td class=\"rightalign\">");
                }
            }
            AddResist(c, temp);
            ReadPowers(c, monsterNode, version);

            if (c.Equipment.EndsWith("."))
            {
                c.Equipment = c.Equipment.Substring(0, c.Equipment.Length - 1).Trim();
            }
            //if (c.Skills.Trim().EndsWith(","))
            //    c.Skills = c.Skills.Trim().Substring(0, c.Skills.Trim().Length - 1);
            return(c);
        }
 private void ManageBlockPublished(Creature c, HtmlNode currentPar, MonsterStatType monsterStatType)
 {
 }