コード例 #1
0
    public string RunePageTotalsTable(RunePageDto runePage)
    {
        if (runePage.slots == null)
        {
            return("");
        }

        KeyValuePair <string, float>[] totals = CalculateTotals(runePage);

        // build totals table
        StringBuilder sb = new StringBuilder("<table class=\"runeTotalsTable\">");

        foreach (KeyValuePair <string, float> pair in totals)
        {
            string description = pair.Key;
            string plus        = (pair.Value > 0 ? "+" : "");
            string valueString = pair.Value.ToString("0.##");

            if (description.Contains("per level"))
            {
                valueString = (pair.Value * 18).ToString("0.##");
                description = description.Replace("per level", "at lvl 18");
            }

            if (description[0] == '%')
            {
                valueString += '%';
                description  = description.Substring(1);
            }

            if (description.Contains('.'))
            {
                description = description.Remove(description.IndexOf('.'), 1);
            }

            description = description.Replace("increased ", "");

            description = addColorToDescription(description);

            sb.Append("<tr><td class=\"runeTotalsLeftColumn\">");
            sb.Append(plus);
            sb.Append(valueString);
            sb.Append("</td><td class=\"runeTotalsRightColumn\">");
            sb.Append(description);
            sb.Append("</td></tr>");
        }

        sb.Append("</table>");

        return(sb.ToString());
    }
コード例 #2
0
    public KeyValuePair <string, float>[] CalculateTotals(RunePageDto runePage)
    {
        List <KeyValuePair <string, float> > totals = new List <KeyValuePair <string, float> >();
        string str;

        // loop through rune slots
        foreach (RuneSlotDto runeSlot in runePage.slots)
        {
            // get rune description
            str = runeSlot.rune.description;
            str = str.ToLower();

            // remove anything in parentheses from string
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '(')
                {
                    str = str.Remove(i - 1);
                    break;
                }
            }

            // if hybrid
            if (runeSlot.rune.name.Contains("Hybrid"))
            {
                string str1 = "", str2 = "";

                for (int i = 0; i < str.Length; i++)
                {
                    if (str[i] == '/')
                    {
                        str1 = str.Substring(0, i - 1);
                        str2 = str.Substring(i + 2);
                        break;
                    }
                }

                int multiplier;

                if (str1[0] == '+')
                {
                    multiplier = 1;
                }
                else
                {
                    multiplier = -1;
                }

                // cut off + or -
                str1 = str1.Substring(1);
                str2 = str2.Substring(1);

                // strings to hold the value
                string valueStr1 = "", valueStr2 = "";

                // build valueStr1 then cut it off str1
                for (int i = 0; i < str1.Length; i++)
                {
                    char c = str1[i];

                    if (char.IsDigit(c) || c == '.')
                    {
                        valueStr1 += c;
                    }
                    else
                    {
                        str1 = str1.Substring(i);
                        break;
                    }
                }
                // build valueStr2 then cut it off str2
                for (int i = 0; i < str2.Length; i++)
                {
                    char c = str2[i];

                    if (char.IsDigit(c) || c == '.')
                    {
                        valueStr2 += c;
                    }
                    else
                    {
                        str2 = str2.Substring(i);
                        break;
                    }
                }

                // parse actual value from valueStr1
                float value1 = float.Parse(valueStr1) * multiplier;
                // parse actual value from valueStr2
                float value2 = float.Parse(valueStr2) * multiplier;

                // add value1 to totals
                bool found = false;
                for (int i = 0; i < totals.Count; i++)
                {
                    KeyValuePair <string, float> pair = totals[i];

                    if (pair.Key == str1)
                    {
                        totals[i] = new KeyValuePair <string, float>(pair.Key, pair.Value + value1);
                        found     = true;
                        break;
                    }
                }
                // if not already in list, add it
                if (!found)
                {
                    totals.Add(new KeyValuePair <string, float>(str1, value1));
                }

                // add value2 to totals
                found = false;
                for (int i = 0; i < totals.Count; i++)
                {
                    KeyValuePair <string, float> pair = totals[i];

                    if (pair.Key == str2)
                    {
                        totals[i] = new KeyValuePair <string, float>(pair.Key, pair.Value + value2);
                        found     = true;
                        break;
                    }
                }
                // if not already in list, add it
                if (!found)
                {
                    totals.Add(new KeyValuePair <string, float>(str2, value2));
                }
            }
            // if not hybrid
            else
            {
                int multiplier;

                if (str[0] == '+')
                {
                    multiplier = 1;
                }
                else
                {
                    multiplier = -1;
                }

                // cut off + or -
                str = str.Substring(1);

                // string to hold the value
                string valueStr = "";

                // build value string then cut it off str
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];

                    if (char.IsDigit(c) || c == '.')
                    {
                        valueStr += c;
                    }
                    else
                    {
                        str = str.Substring(i);
                        break;
                    }
                }

                // parse actual value from valueStr
                float value = float.Parse(valueStr) * multiplier;

                // add value to totals
                bool found = false;
                for (int i = 0; i < totals.Count; i++)
                {
                    KeyValuePair <string, float> pair = totals[i];

                    if (pair.Key == str)
                    {
                        totals[i] = new KeyValuePair <string, float>(pair.Key, pair.Value + value);
                        found     = true;
                        break;
                    }
                }
                // if not already in list, add it
                if (!found)
                {
                    totals.Add(new KeyValuePair <string, float>(str, value));
                }
            }
        }

        return(totals.ToArray());
    }