/// <summary>
 /// Сериализует активные свойства.
 /// </summary>
 /// <returns>Пары (имя свойства, сериализованное значение).</returns>
 public IEnumerable <KeyValuePair <string, string> > SerializeProperties()
 {
     // ReSharper disable LoopCanBeConvertedToQuery
     foreach (PropertyInfo property in GlyphsHelper.GetActiveProperties(this))
     {
         yield return(new KeyValuePair <string, string>(
                          property.Name,
                          Core.Instance.Serializers.Serialize(property.PropertyType, property.GetValue(this, null))));
     }
     // ReSharper restore LoopCanBeConvertedToQuery
 }
        /// <summary>
        /// Десериализует активные свойства.
        /// </summary>
        /// <param name="pairs">Пары (имя свойства, сериализованное значение).</param>
        /// <returns>Свойства, которых не удалось задать (нет в глифе).</returns>
        public IEnumerable <string> DeserializeProperties(IEnumerable <KeyValuePair <string, string> > pairs)
        {
            // Активные свойства глифа.
            var activeProperties = new List <PropertyInfo>(GlyphsHelper.GetActiveProperties(this));

            // Проходим по заданным парам...
            foreach (KeyValuePair <string, string> kvp in pairs)
            {
                // Найдено ли свойство, чтобы задать ему значение.
                bool finded = false;

                // Проходим по активным свойствам глифа...
                foreach (PropertyInfo property in activeProperties)
                {
                    // Если нашли нужное свойство, задаём ему значение.
                    if (property.Name == kvp.Key)
                    {
                        property.SetValue(
                            this,
                            Core.Instance.Serializers.Deserialize(property.PropertyType, kvp.Value),
                            null);

                        // Свойство найдено, значит...
                        finded = true;

                        // ...больше его искать не нужно.
                        break;
                    }
                }

                // Если свойство в глифе не найдено, вернём его имя.
                if (!finded)
                {
                    yield return(kvp.Key);
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            CultureInfo.CurrentCulture   = CultureInfo.GetCultureInfo("en-us");
            CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-us");

            var file = File.ReadAllText(@"/home/cozar/Documents/VS Code/mmeg/Glyphes/nico.json");


            var creatures = CreaturesHelper.LoadAllCreatures();
            var glyphs    = GlyphsHelper.GetGlyphs(file, false).Where(g => g.Rarity == "legendary" || g.Rarity == "dark")
            ;


            //Croisé vent => le plus rapide possible
            var             paladin        = creatures.Where(c => c.Name == "Exalted Paladin").First();
            var             maxSpeedglyphs = SpeedMaximizer.Optimize(glyphs);
            GlyphedCreature glyphedPaladin = new GlyphedCreature(paladin, maxSpeedglyphs);

            Console.WriteLine("Croisé / Speed =" + glyphedPaladin.Speed);
            foreach (var glyph in maxSpeedglyphs)
            {
                Console.WriteLine(glyph);
            }
            glyphs = glyphs.Except(maxSpeedglyphs);

            //dragon eau => le plus rapide possible avec au moins 100 de précision
            var dragon          = creatures.Where(c => c.Name == "Sapphire Dragon").First();
            var dragonOptimizer = new FunctionOptimizer(
                dragon,
                glyphs,
                c => Math.Min(c.Accuracy, 100) * 100 + c.Speed
                );
            var glyphedDragon = dragonOptimizer.Search();

            Console.WriteLine($"Dragon / Speed ={glyphedDragon.Speed}, précision = {glyphedDragon.Accuracy}");
            foreach (var glyph in glyphedDragon.Glyphs)
            {
                Console.WriteLine(glyph);
            }
            glyphs = glyphs.Except(glyphedDragon.Glyphs);


            //Chaman terre => le plus rapide possible
            var shaman = creatures.Where(c => c.Name == "Forest Hexxer").First();

            maxSpeedglyphs = SpeedMaximizer.Optimize(glyphs);
            GlyphedCreature glyphedShaman = new GlyphedCreature(shaman, maxSpeedglyphs);

            Console.WriteLine($"Chaman / Speed ={glyphedShaman.Speed}, précision = {glyphedShaman.Accuracy}");
            foreach (var glyph in maxSpeedglyphs)
            {
                Console.WriteLine(glyph);
            }
            glyphs = glyphs.Except(maxSpeedglyphs);


            //rak vent => le plus de dégâts possibles
            var rak = creatures.Where(c => c.Name == "Storm Rakshasa Raja").First();

            //Le fichier xml ne contient pas les valeurs au niveau 35, il faut donc les adapter en attendant de trouver la formule de calcul
            rak.Attack = 1621;
            var rakOptimizer = new FunctionOptimizer(
                rak,
                glyphs,
                c => (1.2m * c.Attack + 10 * c.Speed) * (1 + Math.Min(c.CriticalChance, 100) / 100 * c.CriticalDamage)
                );
            var glyphedRak = rakOptimizer.Search();

            Console.WriteLine($"Rak / Speed ={glyphedShaman.Speed}, Atk = {glyphedRak.Accuracy}, Tcc = {glyphedRak.CriticalChance}, Dcc = {glyphedRak.CriticalDamage}");
            foreach (var glyph in glyphedRak.Glyphs)
            {
                Console.WriteLine(glyph);
            }
        }