Exemplo n.º 1
0
        public string GetFormat(Stat stat)
        {
            Type type = stat.GetType();

            MemberInfo[] infos = type.GetMember(stat.ToString());

            StatDescription description = infos[0].GetCustomAttribute <StatDescription>();

            if (description == null)
            {
                return(null);
            }

            switch (description.Mode)
            {
            case StatType.Default:
                return(string.Format(description.Format, this[stat]));

            case StatType.Min:
                return(this[description.MaxStat] == 0 ? (string.Format(description.Format, this[stat])) : null);

            case StatType.Max:
            case StatType.SpellPower:
                return(string.Format(description.Format, this[description.MinStat], this[stat]));

            case StatType.Percent:
                return(string.Format(description.Format, this[stat] / 100D));

            case StatType.Text:
                return(description.Format);

            case StatType.Time:
                if (this[stat] < 0)
                {
                    return("Permanent");
                }

                return(Functions.ToString(TimeSpan.FromSeconds(this[stat]), true));

            default: return(null);
            }
        }
Exemplo n.º 2
0
        public string GetDisplay(Stat stat)
        {
            Type type = stat.GetType();

            MemberInfo[] infos = type.GetMember(stat.ToString());

            StatDescription description = infos[0].GetCustomAttribute <StatDescription>();

            if (description == null)
            {
                return(null);
            }

            List <Stat> list;
            string      value;
            bool        neecComma;

            switch (description.Mode)
            {
            case StatType.None:
                return(null);

            case StatType.Default:
                return(description.Title + ": " + string.Format(description.Format, this[stat]));

            case StatType.Min:
                if (this[description.MaxStat] != 0)
                {
                    return(null);
                }

                return(description.Title + ": " + string.Format(description.Format, this[stat]));

            case StatType.Max:
                return(description.Title + ": " + string.Format(description.Format, this[description.MinStat], this[stat]));

            case StatType.Percent:
                return(description.Title + ": " + string.Format(description.Format, this[stat] / 100D));

            case StatType.Text:
                return(description.Title);

            case StatType.Time:
                if (this[stat] < 0)
                {
                    return(description.Title + ": Permanent");
                }

                return(description.Title + ": " + Functions.ToString(TimeSpan.FromSeconds(this[stat]), true));

            case StatType.SpellPower:
                if (description.MinStat == stat && this[description.MaxStat] != 0)
                {
                    return(null);
                }

                if (this[Stat.MinMC] != this[Stat.MinSC] || this[Stat.MaxMC] != this[Stat.MaxSC])
                {
                    return(description.Title + ": " + string.Format(description.Format, this[description.MinStat], this[stat]));
                }

                if (stat != Stat.MaxSC)
                {
                    return(null);
                }


                return("Spell Power: " + string.Format(description.Format, this[description.MinStat], this[stat]));

            case StatType.AttackElement:

                list = new List <Stat>();
                foreach (KeyValuePair <Stat, int> pair in Values)
                {
                    if (type.GetMember(pair.Key.ToString())[0].GetCustomAttribute <StatDescription>().Mode == StatType.AttackElement)
                    {
                        list.Add(pair.Key);
                    }
                }

                if (list.Count == 0 || list[0] != stat)
                {
                    return(null);
                }

                value = $"E. Atk: ";

                neecComma = false;
                foreach (Stat s in list)
                {
                    description = type.GetMember(s.ToString())[0].GetCustomAttribute <StatDescription>();

                    if (neecComma)
                    {
                        value += $", ";
                    }

                    value    += $"{description.Title} +" + this[s];
                    neecComma = true;
                }
                return(value);

            case StatType.ElementResistance:


                list = new List <Stat>();
                foreach (KeyValuePair <Stat, int> pair in Values)
                {
                    if (type.GetMember(pair.Key.ToString())[0].GetCustomAttribute <StatDescription>().Mode == StatType.ElementResistance)
                    {
                        list.Add(pair.Key);
                    }
                }

                if (list.Count == 0)
                {
                    return(null);
                }

                bool ei;
                bool hasAdv = false, hasDis = false;

                foreach (Stat s in list)
                {
                    if (this[s] > 0)
                    {
                        hasAdv = true;
                    }

                    if (this[s] < 0)
                    {
                        hasDis = true;
                    }
                }

                if (!hasAdv)     // EV Online
                {
                    ei = false;

                    if (list[0] != stat)
                    {
                        return(null);
                    }
                }
                else
                {
                    if (!hasDis && list[0] != stat)
                    {
                        return(null);
                    }

                    ei = list[0] == stat;

                    if (!ei && list[1] != stat)
                    {
                        return(null);                            //Impossible to be false and have less than 2 stats.
                    }
                }


                value = ei ? $"E. Adv: " : $"E. Dis: ";

                neecComma = false;


                foreach (Stat s in list)
                {
                    description = type.GetMember(s.ToString())[0].GetCustomAttribute <StatDescription>();

                    if ((this[s] > 0) != ei)
                    {
                        continue;
                    }

                    if (neecComma)
                    {
                        value += $", ";
                    }

                    value    += $"{description.Title} x" + Math.Abs(this[s]);
                    neecComma = true;
                }

                return(value);

            default: return(null);
            }
        }