Exemplo n.º 1
0
        public static void GetItemsFromJSON(string json, Main main)
        {
            ItemRAW[] rawItems = new ItemRAW[1];
            try
            {
                rawItems = JsonConvert.DeserializeObject <ItemRAW[]>(json);
            }
            catch (Exception e)
            {
                rawItems[0] = JsonConvert.DeserializeObject <ItemRAW>(json);
            }
            for (int a = 0; a < rawItems.Length; a++)
            {
                double  cur = a, max = rawItems.Length;
                ItemRAW itemRAW = rawItems[a];
                main.JSON.Add(new KeyValuePair <string, string>("Item", JsonConvert.SerializeObject(itemRAW)));
                Item newItem = new Item
                {
                    ID           = itemRAW.id,
                    Name         = itemRAW.name,
                    Description  = itemRAW.description,
                    ItemType     = (Type)Enum.Parse(typeof(Type), itemRAW.type),
                    ItemRarity   = (Rarity)Enum.Parse(typeof(Rarity), itemRAW.rarity),
                    Level        = itemRAW.level,
                    VendorValue  = itemRAW.vendor_value,
                    Flags        = new List <Flag>(),
                    GameTypes    = new List <GameType>(),
                    Restrictions = new List <Restriction>()
                };

                string fileName = string.Empty;

                if (!string.IsNullOrEmpty(itemRAW.icon))
                {
                    fileName = string.Empty;
                    using (WebClient client = new WebClient())
                    {
                        fileName = itemRAW.icon.Substring(itemRAW.icon.LastIndexOf("/") + 1);
                        Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"images\items\");
                        if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"images\items\" + fileName))
                        {
                            client.DownloadFileAsync(new Uri(itemRAW.icon), AppDomain.CurrentDomain.BaseDirectory + @"\images\items\" + fileName);
                        }
                    }
                    newItem.Image = AppDomain.CurrentDomain.BaseDirectory + @"images\items\" + fileName;
                }
                for (int i = 0; i < itemRAW.flags.Length; i++)
                {
                    newItem.Flags.Add((Flag)Enum.Parse(typeof(Flag), itemRAW.flags[i]));
                }
                for (int i = 0; i < itemRAW.game_types.Length; i++)
                {
                    newItem.GameTypes.Add((GameType)Enum.Parse(typeof(GameType), itemRAW.game_types[i]));
                }
                for (int i = 0; i < itemRAW.restrictions.Length; i++)
                {
                    newItem.Restrictions.Add((Restriction)Enum.Parse(typeof(Restriction), itemRAW.restrictions[i]));
                }
                if (itemRAW.default_skin.HasValue)
                {
                    newItem.SkinID = itemRAW.default_skin.Value;
                }

                if (newItem.ItemType == Type.Armor)
                {
                    ArmorItemDetail newItemDetail = new ArmorItemDetail
                    {
                        Type        = (ArmorItemDetail.ArmorType)Enum.Parse(typeof(ArmorItemDetail.ArmorType), itemRAW.details.type),
                        Weight      = (ArmorItemDetail.WeightClass)Enum.Parse(typeof(ArmorItemDetail.WeightClass), itemRAW.details.weight_class),
                        Defense     = itemRAW.details.defense.Value,
                        Infusions   = new List <Infusion>(),
                        StatChoices = new List <ItemStat>()
                    };

                    if (itemRAW.details.infix_upgrade != null)
                    {
                        InfixUpgrade newInfixUpgrade = new InfixUpgrade();

                        if (itemRAW.details.infix_upgrade.buff != null)
                        {
                            int      skillID = itemRAW.details.infix_upgrade.buff.skill_id;
                            ItemBuff newBuff = new ItemBuff
                            {
                                SkillID     = itemRAW.details.infix_upgrade.buff.skill_id,
                                Description = itemRAW.details.infix_upgrade.buff.description
                            };
                            newInfixUpgrade.Buff = newBuff;
                        }
                        if (itemRAW.details.infix_upgrade.attributes != null)
                        {
                            List <ItemAttribute> newAttributes = new List <ItemAttribute>();
                            for (int i = 0; i < itemRAW.details.infix_upgrade.attributes.Length; i++)
                            {
                                ItemAttribute newAttribute = new ItemAttribute
                                {
                                    Att      = (ItemAttribute.Attribute)Enum.Parse(typeof(ItemAttribute.Attribute), itemRAW.details.infix_upgrade.attributes[i].attribute),
                                    Modifier = itemRAW.details.infix_upgrade.attributes[i].modifier
                                };
                                newAttributes.Add(newAttribute);
                            }
                            newInfixUpgrade.Attributes = newAttributes;
                        }

                        newItemDetail.InfixUpgrades = newInfixUpgrade;
                    }

                    if (itemRAW.details.infusion_slots.Length > 0)
                    {
                        List <Infusion> newInfusions = new List <Infusion>();
                        for (int i = 0; i < itemRAW.details.infusion_slots.Length; i++)
                        {
                            Infusion newInfusion = new Infusion
                            {
                                Flags = new List <Infusion.Flag>()
                            };
                            for (int j = 0; j < itemRAW.details.infusion_slots[i].flags.Length; j++)
                            {
                                newInfusion.Flags.Add((Infusion.Flag)Enum.Parse(typeof(Infusion.Flag), itemRAW.details.infusion_slots[i].flags[j]));
                            }
                            if (itemRAW.details.infusion_slots[i].item_id.HasValue)
                            {
                                newInfusion.ItemID = itemRAW.details.infusion_slots[i].item_id.Value;
                            }

                            newInfusions.Add(newInfusion);
                        }
                        newItemDetail.Infusions = newInfusions;
                    }

                    if (itemRAW.details.suffix_item_id.HasValue)
                    {
                        newItemDetail.ItemID = itemRAW.details.suffix_item_id.Value;
                    }

                    if (itemRAW.details.stat_choices != null)
                    {
                        for (int i = 0; i < itemRAW.details.stat_choices.Length; i++)
                        {
                            int      statID  = int.Parse(itemRAW.details.stat_choices[i]);
                            ItemStat newStat = main.ItemStats.FirstOrDefault(st => st.ID == statID);
                            newItemDetail.StatChoices.Add(newStat);
                        }
                    }

                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Back)
                {
                    BackItemDetail newItemDetail = new BackItemDetail
                    {
                        Infusions   = new List <Infusion>(),
                        StatChoices = new List <ItemStat>()
                    };

                    if (itemRAW.details.infix_upgrade != null)
                    {
                        InfixUpgrade newInfixUpgrade = new InfixUpgrade();

                        if (itemRAW.details.infix_upgrade.buff != null)
                        {
                            int      skillID = itemRAW.details.infix_upgrade.buff.skill_id;
                            ItemBuff newBuff = new ItemBuff
                            {
                                SkillID     = itemRAW.details.infix_upgrade.buff.skill_id,
                                Description = itemRAW.details.infix_upgrade.buff.description
                            };
                            newInfixUpgrade.Buff = newBuff;
                        }
                        if (itemRAW.details.infix_upgrade.attributes != null)
                        {
                            List <ItemAttribute> newAttributes = new List <ItemAttribute>();
                            for (int i = 0; i < itemRAW.details.infix_upgrade.attributes.Length; i++)
                            {
                                ItemAttribute newAttribute = new ItemAttribute
                                {
                                    Att      = (ItemAttribute.Attribute)Enum.Parse(typeof(ItemAttribute.Attribute), itemRAW.details.infix_upgrade.attributes[i].attribute),
                                    Modifier = itemRAW.details.infix_upgrade.attributes[i].modifier
                                };
                                newAttributes.Add(newAttribute);
                            }
                            newInfixUpgrade.Attributes = newAttributes;
                        }

                        newItemDetail.InfixUpgrades = newInfixUpgrade;
                    }

                    if (itemRAW.details.infusion_slots.Length > 0)
                    {
                        List <Infusion> newInfusions = new List <Infusion>();
                        for (int i = 0; i < itemRAW.details.infusion_slots.Length; i++)
                        {
                            Infusion newInfusion = new Infusion
                            {
                                Flags = new List <Infusion.Flag>()
                            };
                            for (int j = 0; j < itemRAW.details.infusion_slots[i].flags.Length; j++)
                            {
                                newInfusion.Flags.Add((Infusion.Flag)Enum.Parse(typeof(Infusion.Flag), itemRAW.details.infusion_slots[i].flags[j]));
                            }
                            if (itemRAW.details.infusion_slots[i].item_id.HasValue)
                            {
                                newInfusion.ItemID = itemRAW.details.infusion_slots[i].item_id.Value;
                            }

                            newInfusions.Add(newInfusion);
                        }
                        newItemDetail.Infusions = newInfusions;
                    }

                    if (itemRAW.details.suffix_item_id.HasValue)
                    {
                        newItemDetail.ItemID = itemRAW.details.suffix_item_id.Value;
                    }

                    if (itemRAW.details.stat_choices != null)
                    {
                        for (int i = 0; i < itemRAW.details.stat_choices.Length; i++)
                        {
                            int      statID  = int.Parse(itemRAW.details.stat_choices[i]);
                            ItemStat newStat = main.ItemStats.FirstOrDefault(st => st.ID == statID);
                            newItemDetail.StatChoices.Add(newStat);
                        }
                    }

                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Bag)
                {
                    BagItemDetail newItemDetail = new BagItemDetail
                    {
                        Size       = itemRAW.details.size.Value,
                        NoSellSort = itemRAW.details.no_sell_or_sort.Value
                    };
                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Consumable)
                {
                    ConsumableItemDetail newItemDetail = new ConsumableItemDetail
                    {
                        ConsType               = (ConsumableItemDetail.ConsumableType)Enum.Parse(typeof(ConsumableItemDetail.ConsumableType), itemRAW.details.type),
                        Description            = itemRAW.details.description,
                        DurationInMilliseconds = (itemRAW.details.duration_ms.HasValue) ? itemRAW.details.duration_ms.Value : 0,
                        StackCount             = (itemRAW.details.apply_count.HasValue) ? itemRAW.details.apply_count.Value : 0,
                        Name   = itemRAW.details.name,
                        Skins  = new List <Skin>(),
                        SkinID = new List <int>()
                    };
                    if (itemRAW.details.unlock_type != null)
                    {
                        newItemDetail.UnType = (ConsumableItemDetail.UnlockType)Enum.Parse(typeof(ConsumableItemDetail.UnlockType), itemRAW.details.unlock_type);
                    }

                    if (itemRAW.details.color_id.HasValue)
                    {
                        int    colourID  = itemRAW.details.color_id.Value;
                        Colour newColour = main.Colours.FirstOrDefault(co => co.ID == colourID);
                        newItemDetail.ConsumableColour = newColour;
                    }
                    if (itemRAW.details.recipe_id.HasValue)
                    {
                        newItemDetail.RecipeID = itemRAW.details.recipe_id.Value;
                    }
                    if (itemRAW.details.skins != null)
                    {
                        for (int i = 0; i < itemRAW.details.skins.Length; i++)
                        {
                            newItemDetail.SkinID.Add(itemRAW.details.skins[i].Value);
                        }
                    }
                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Container)
                {
                    ContainerItemDetail newItemDetail = new ContainerItemDetail
                    {
                        ContType = (ContainerItemDetail.ContainerType)Enum.Parse(typeof(ContainerItemDetail.ContainerType), itemRAW.details.type)
                    };
                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Gathering)
                {
                    GatheringToolItemDetail newItemDetail = new GatheringToolItemDetail
                    {
                        GatType = (GatheringToolItemDetail.GatheringToolType)Enum.Parse(typeof(GatheringToolItemDetail.GatheringToolType), itemRAW.details.type)
                    };
                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Gizmo)
                {
                    GizmoItemDetail newItemDetail = new GizmoItemDetail
                    {
                        GizType = (GizmoItemDetail.GizmoType)Enum.Parse(typeof(GizmoItemDetail.GizmoType), itemRAW.details.type)
                    };
                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.MiniPet)
                {
                    MiniItemDetail newItemDetail = new MiniItemDetail
                    {
                        MiniID = itemRAW.details.minipet_id.Value
                    };

                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Tool)
                {
                    SalvageKitItemDetail newItemDetail = new SalvageKitItemDetail
                    {
                        SalType = SalvageKitItemDetail.SalvageType.Salvage,
                        Charges = itemRAW.details.charges.Value
                    };
                }
                if (newItem.ItemType == Type.Trinket)
                {
                    TrinketItemDetail newItemDetail = new TrinketItemDetail
                    {
                        TrinkType   = (TrinketItemDetail.TrinketType)Enum.Parse(typeof(TrinketItemDetail.TrinketType), itemRAW.details.type),
                        Infusions   = new List <Infusion>(),
                        StatChoices = new List <ItemStat>()
                    };

                    if (itemRAW.details.infix_upgrade != null)
                    {
                        InfixUpgrade newInfixUpgrade = new InfixUpgrade();

                        if (itemRAW.details.infix_upgrade.buff != null)
                        {
                            int      skillID = itemRAW.details.infix_upgrade.buff.skill_id;
                            ItemBuff newBuff = new ItemBuff
                            {
                                SkillID     = itemRAW.details.infix_upgrade.buff.skill_id,
                                Description = itemRAW.details.infix_upgrade.buff.description
                            };
                            newInfixUpgrade.Buff = newBuff;
                        }
                        if (itemRAW.details.infix_upgrade.attributes != null)
                        {
                            List <ItemAttribute> newAttributes = new List <ItemAttribute>();
                            for (int i = 0; i < itemRAW.details.infix_upgrade.attributes.Length; i++)
                            {
                                ItemAttribute newAttribute = new ItemAttribute
                                {
                                    Att      = (ItemAttribute.Attribute)Enum.Parse(typeof(ItemAttribute.Attribute), itemRAW.details.infix_upgrade.attributes[i].attribute),
                                    Modifier = itemRAW.details.infix_upgrade.attributes[i].modifier
                                };
                                newAttributes.Add(newAttribute);
                            }
                            newInfixUpgrade.Attributes = newAttributes;
                        }

                        newItemDetail.InfixUpgrades = newInfixUpgrade;
                    }

                    if (itemRAW.details.infusion_slots.Length > 0)
                    {
                        List <Infusion> newInfusions = new List <Infusion>();
                        for (int i = 0; i < itemRAW.details.infusion_slots.Length; i++)
                        {
                            Infusion newInfusion = new Infusion
                            {
                                Flags = new List <Infusion.Flag>()
                            };
                            for (int j = 0; j < itemRAW.details.infusion_slots[i].flags.Length; j++)
                            {
                                newInfusion.Flags.Add((Infusion.Flag)Enum.Parse(typeof(Infusion.Flag), itemRAW.details.infusion_slots[i].flags[j]));
                            }
                            if (itemRAW.details.infusion_slots[i].item_id.HasValue)
                            {
                                newInfusion.ItemID = itemRAW.details.infusion_slots[i].item_id.Value;
                            }

                            newInfusions.Add(newInfusion);
                        }
                        newItemDetail.Infusions = newInfusions;
                    }

                    if (itemRAW.details.suffix_item_id.HasValue)
                    {
                        newItemDetail.ItemID = itemRAW.details.suffix_item_id.Value;
                    }

                    if (itemRAW.details.stat_choices != null)
                    {
                        for (int i = 0; i < itemRAW.details.stat_choices.Length; i++)
                        {
                            int      statID  = int.Parse(itemRAW.details.stat_choices[i]);
                            ItemStat newStat = main.ItemStats.FirstOrDefault(st => st.ID == statID);
                            newItemDetail.StatChoices.Add(newStat);
                        }
                    }

                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.UpgradeComponent)
                {
                    UpgradeItemDetail newItemDetail = new UpgradeItemDetail
                    {
                        UpType    = (UpgradeItemDetail.UpgradeType)Enum.Parse(typeof(UpgradeItemDetail.UpgradeType), itemRAW.details.type),
                        Flags     = new List <UpgradeItemDetail.Flag>(),
                        Infusions = new List <UpgradeItemDetail.InfusionFlag>(),
                        Suffix    = itemRAW.details.suffix
                    };
                    if (itemRAW.details.bonuses != null)
                    {
                        newItemDetail.Bonuses = itemRAW.details.bonuses.ToList();
                    }
                    if (itemRAW.details.infusion_upgrade_flags != null)
                    {
                        for (int i = 0; i < itemRAW.details.infusion_upgrade_flags.Length; i++)
                        {
                            newItemDetail.Infusions.Add((UpgradeItemDetail.InfusionFlag)Enum.Parse(typeof(UpgradeItemDetail.InfusionFlag), itemRAW.details.infusion_upgrade_flags[i]));
                        }
                    }
                    if (itemRAW.details.infix_upgrade != null)
                    {
                        InfixUpgrade newInfixUpgrade = new InfixUpgrade();

                        if (itemRAW.details.infix_upgrade.buff != null)
                        {
                            int      skillID = itemRAW.details.infix_upgrade.buff.skill_id;
                            ItemBuff newBuff = new ItemBuff
                            {
                                SkillID     = itemRAW.details.infix_upgrade.buff.skill_id,
                                Description = itemRAW.details.infix_upgrade.buff.description
                            };
                            newInfixUpgrade.Buff = newBuff;
                        }
                        if (itemRAW.details.infix_upgrade.attributes != null)
                        {
                            List <ItemAttribute> newAttributes = new List <ItemAttribute>();
                            for (int i = 0; i < itemRAW.details.infix_upgrade.attributes.Length; i++)
                            {
                                ItemAttribute newAttribute = new ItemAttribute
                                {
                                    Att      = (ItemAttribute.Attribute)Enum.Parse(typeof(ItemAttribute.Attribute), itemRAW.details.infix_upgrade.attributes[i].attribute),
                                    Modifier = itemRAW.details.infix_upgrade.attributes[i].modifier
                                };
                                newAttributes.Add(newAttribute);
                            }
                            newInfixUpgrade.Attributes = newAttributes;
                        }

                        newItemDetail.InfixUpgrades = newInfixUpgrade;
                    }
                    if (itemRAW.details.flags != null)
                    {
                        for (int i = 0; i < itemRAW.details.flags.Length; i++)
                        {
                            newItemDetail.Flags.Add((UpgradeItemDetail.Flag)Enum.Parse(typeof(UpgradeItemDetail.Flag), itemRAW.details.flags[i]));
                        }
                    }

                    newItem.Details = newItemDetail;
                }
                if (newItem.ItemType == Type.Weapon)
                {
                    WeaponItemDetail newItemDetail = new WeaponItemDetail
                    {
                        WeapType    = (WeaponItemDetail.WeaponType)Enum.Parse(typeof(WeaponItemDetail.WeaponType), itemRAW.details.type),
                        DamType     = (WeaponItemDetail.DamageType)Enum.Parse(typeof(WeaponItemDetail.DamageType), itemRAW.details.damage_type),
                        MIN         = itemRAW.details.min_power.Value,
                        MAX         = itemRAW.details.max_power.Value,
                        Defense     = itemRAW.details.defense.Value,
                        Infusions   = new List <Infusion>(),
                        StatChoices = new List <ItemStat>()
                    };

                    if (itemRAW.details.infix_upgrade != null)
                    {
                        InfixUpgrade newInfixUpgrade = new InfixUpgrade();

                        if (itemRAW.details.infix_upgrade.buff != null)
                        {
                            int      skillID = itemRAW.details.infix_upgrade.buff.skill_id;
                            ItemBuff newBuff = new ItemBuff
                            {
                                SkillID     = itemRAW.details.infix_upgrade.buff.skill_id,
                                Description = itemRAW.details.infix_upgrade.buff.description
                            };
                            newInfixUpgrade.Buff = newBuff;
                        }
                        if (itemRAW.details.infix_upgrade.attributes != null)
                        {
                            List <ItemAttribute> newAttributes = new List <ItemAttribute>();
                            for (int i = 0; i < itemRAW.details.infix_upgrade.attributes.Length; i++)
                            {
                                ItemAttribute newAttribute = new ItemAttribute
                                {
                                    Att      = (ItemAttribute.Attribute)Enum.Parse(typeof(ItemAttribute.Attribute), itemRAW.details.infix_upgrade.attributes[i].attribute),
                                    Modifier = itemRAW.details.infix_upgrade.attributes[i].modifier
                                };
                                newAttributes.Add(newAttribute);
                            }
                            newInfixUpgrade.Attributes = newAttributes;
                        }

                        newItemDetail.InfixUpgrades = newInfixUpgrade;
                    }

                    if (itemRAW.details.infusion_slots.Length > 0)
                    {
                        List <Infusion> newInfusions = new List <Infusion>();
                        for (int i = 0; i < itemRAW.details.infusion_slots.Length; i++)
                        {
                            Infusion newInfusion = new Infusion
                            {
                                Flags = new List <Infusion.Flag>()
                            };
                            for (int j = 0; j < itemRAW.details.infusion_slots[i].flags.Length; j++)
                            {
                                newInfusion.Flags.Add((Infusion.Flag)Enum.Parse(typeof(Infusion.Flag), itemRAW.details.infusion_slots[i].flags[j]));
                            }
                            if (itemRAW.details.infusion_slots[i].item_id.HasValue)
                            {
                                newInfusion.ItemID = itemRAW.details.infusion_slots[i].item_id.Value;
                            }

                            newInfusions.Add(newInfusion);
                        }
                        newItemDetail.Infusions = newInfusions;
                    }

                    if (itemRAW.details.suffix_item_id.HasValue)
                    {
                        newItemDetail.ItemID = itemRAW.details.suffix_item_id.Value;
                    }

                    if (itemRAW.details.stat_choices != null)
                    {
                        for (int i = 0; i < itemRAW.details.stat_choices.Length; i++)
                        {
                            int      statID  = int.Parse(itemRAW.details.stat_choices[i]);
                            ItemStat newStat = main.ItemStats.FirstOrDefault(st => st.ID == statID);
                            newItemDetail.StatChoices.Add(newStat);
                        }
                    }

                    newItem.Details = newItemDetail;
                }

                main.Items.Add(newItem);
                main.OnCharStatusUpdate("Generated Item " + newItem.Name + ";" + newItem.ID + " " + ((cur != 0) ? Math.Round((double)(cur / max), 2) * 100 : 0).ToString() + "%");
            }
        }
Exemplo n.º 2
0
        public static void GetColoursFromJSON(string json, Main main)
        {
            ColourRAW[] rawColours = new ColourRAW[1];
            try
            {
                rawColours = JsonConvert.DeserializeObject <ColourRAW[]>(json);
            }
            catch (Exception e)
            {
                rawColours[0] = JsonConvert.DeserializeObject <ColourRAW>(json);
            }
            for (int c = 0; c < rawColours.Length; c++)
            {
                double    cur = c, max = rawColours.Length;
                ColourRAW colourRAW = rawColours[c];
                main.JSON.Add(new KeyValuePair <string, string>("Colour", JsonConvert.SerializeObject(colourRAW)));
                Colour newColour = new Colour
                {
                    ID   = colourRAW.id,
                    Name = colourRAW.name,
                    RGB  = colourRAW.base_rgb.ToList(),
                };
                ColourSubRAW     colourSubRAW1 = colourRAW.cloth;
                AppearanceDetail clothDetail   = new AppearanceDetail
                {
                    Brightness = colourSubRAW1.brightness,
                    Contrast   = colourSubRAW1.contrast,
                    Hue        = colourSubRAW1.hue,
                    Saturation = colourSubRAW1.saturation,
                    Lightness  = colourSubRAW1.lightness,
                    RGB        = colourSubRAW1.rgb.ToList()
                };
                newColour.ClothDetail = clothDetail;

                ColourSubRAW     colourSubRAW2 = colourRAW.leather;
                AppearanceDetail leatherDetail = new AppearanceDetail
                {
                    Brightness = colourSubRAW2.brightness,
                    Contrast   = colourSubRAW2.contrast,
                    Hue        = colourSubRAW2.hue,
                    Saturation = colourSubRAW2.saturation,
                    Lightness  = colourSubRAW2.lightness,
                    RGB        = colourSubRAW2.rgb.ToList()
                };
                newColour.LeatherDetail = leatherDetail;

                ColourSubRAW     colourSubRAW3 = colourRAW.metal;
                AppearanceDetail metalDetail   = new AppearanceDetail
                {
                    Brightness = colourSubRAW3.brightness,
                    Contrast   = colourSubRAW3.contrast,
                    Hue        = colourSubRAW3.hue,
                    Saturation = colourSubRAW3.saturation,
                    Lightness  = colourSubRAW3.lightness,
                    RGB        = colourSubRAW3.rgb.ToList()
                };
                newColour.MetalDetail = metalDetail;

                if (colourRAW.categories.Length > 0)
                {
                    ColourCategory colourCategory = new ColourCategory();
                    if (colourRAW.categories.Length > 0)
                    {
                        colourCategory.CatHue = (ColourCategory.Hue)Enum.Parse(typeof(ColourCategory.Hue), colourRAW.categories[0]);
                    }
                    if (colourRAW.categories.Length > 1)
                    {
                        colourCategory.CatMaterial = (ColourCategory.Material)Enum.Parse(typeof(ColourCategory.Material), colourRAW.categories[1]);
                    }
                    if (colourRAW.categories.Length > 2)
                    {
                        colourCategory.CatRarity = (ColourCategory.Rarity)Enum.Parse(typeof(ColourCategory.Rarity), colourRAW.categories[2]);
                    }
                    newColour.Categories = colourCategory;
                }

                main.Colours.Add(newColour);
                main.OnCharStatusUpdate("Generated Colour " + newColour.Name + ";" + newColour.ID + " " + ((cur != 0) ? Math.Round((double)(cur / max), 2) * 100 : 0).ToString() + "%");
            }
        }
Exemplo n.º 3
0
        public static void GetSkinsFromJSON(string json, Main main)
        {
            SkinRAW[] rawSkins = new SkinRAW[1];
            try
            {
                rawSkins = JsonConvert.DeserializeObject <SkinRAW[]>(json);
            }
            catch (Exception e)
            {
                rawSkins[0] = JsonConvert.DeserializeObject <SkinRAW>(json);
            }
            for (int a = 0; a < rawSkins.Length; a++)
            {
                double  cur = a, max = rawSkins.Length;
                SkinRAW skinRAW = rawSkins[a];
                main.JSON.Add(new KeyValuePair <string, string>("Skin", JsonConvert.SerializeObject(skinRAW)));
                Skin newSkin = new Skin
                {
                    ID           = skinRAW.id,
                    Name         = skinRAW.name,
                    SkinType     = (Type)Enum.Parse(typeof(Type), skinRAW.type),
                    Flags        = new List <Flag>(),
                    Restrictions = new List <Restriction>(),
                    Rarity       = skinRAW.rarity,
                    Description  = skinRAW.description
                };
                for (int i = 0; i < skinRAW.flags.Length; i++)
                {
                    newSkin.Flags.Add((Flag)Enum.Parse(typeof(Flag), skinRAW.flags[i]));
                }
                for (int i = 0; i < skinRAW.restrictions.Length; i++)
                {
                    newSkin.Restrictions.Add((Restriction)Enum.Parse(typeof(Restriction), skinRAW.restrictions[i]));
                }

                if (skinRAW.type == "Armor" && skinRAW.details != null)
                {
                    SkinSub1RAW skinSub1RAW = skinRAW.details;
                    ArmorDetail newDetail   = new ArmorDetail
                    {
                        ArmorType = (ArmorDetail.Type)Enum.Parse(typeof(ArmorDetail.Type), skinSub1RAW.type),
                        Weight    = (ArmorDetail.WeightClass)Enum.Parse(typeof(ArmorDetail.WeightClass), skinSub1RAW.weight_class)
                    };

                    if (skinSub1RAW.dye_slots != null)
                    {
                        SkinSub2RAW skinSub2RAW = skinSub1RAW.dye_slots; DyeSlots dyeSlots = new DyeSlots();
                        if (skinSub2RAW.def != null)
                        {
                            for (int i = 0; i < skinSub2RAW.def.Length; i++)
                            {
                                SkinSub3RAW skinSub3RAW = skinSub2RAW.def[i];
                                int         colourID    = skinSub3RAW.color_id;
                                Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                Dye         newDye      = new Dye
                                {
                                    Color       = colour,
                                    DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                };
                                dyeSlots.Dyes.Add(newDye);
                            }
                        }

                        if (skinSub2RAW.overrides != null)
                        {
                            DyeOverride dyeOverride = new DyeOverride();
                            SkinSub4RAW skinSub4RAW = skinSub2RAW.overrides;
                            if (skinSub4RAW.AsuraMale != null)
                            {
                                dyeOverride.AsuraMale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.AsuraMale.Length; i++)
                                {
                                    if (skinSub4RAW.AsuraMale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.AsuraMale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.AsuraMale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.AsuraFemale != null)
                            {
                                dyeOverride.AsuraFemale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.AsuraFemale.Length; i++)
                                {
                                    if (skinSub4RAW.AsuraFemale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.AsuraFemale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.AsuraFemale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.CharrMale != null)
                            {
                                dyeOverride.CharrMale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.CharrMale.Length; i++)
                                {
                                    if (skinSub4RAW.CharrMale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.CharrMale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.CharrMale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.CharrFemale != null)
                            {
                                dyeOverride.CharrFemale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.CharrFemale.Length; i++)
                                {
                                    if (skinSub4RAW.CharrFemale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.CharrFemale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.CharrFemale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.HumanMale != null)
                            {
                                dyeOverride.HumanMale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.HumanMale.Length; i++)
                                {
                                    if (skinSub4RAW.HumanMale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.HumanMale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.HumanMale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.HumanFemale != null)
                            {
                                dyeOverride.HumanFemale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.HumanFemale.Length; i++)
                                {
                                    if (skinSub4RAW.HumanFemale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.HumanFemale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.HumanFemale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.NornMale != null)
                            {
                                dyeOverride.NornMale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.NornMale.Length; i++)
                                {
                                    if (skinSub4RAW.NornMale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.NornMale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.NornMale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.NornFemale != null)
                            {
                                dyeOverride.NornFemale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.NornFemale.Length; i++)
                                {
                                    if (skinSub4RAW.NornFemale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.NornFemale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.NornFemale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.SylvariMale != null)
                            {
                                dyeOverride.SylvariMale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.SylvariMale.Length; i++)
                                {
                                    if (skinSub4RAW.SylvariMale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.SylvariMale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.SylvariMale.Add(newDye);
                                    }
                                }
                            }
                            if (skinSub4RAW.SylvariFemale != null)
                            {
                                dyeOverride.SylvariFemale = new List <Dye>();
                                for (int i = 0; i < skinSub4RAW.SylvariFemale.Length; i++)
                                {
                                    if (skinSub4RAW.SylvariFemale[i] != null)
                                    {
                                        SkinSub3RAW skinSub3RAW = skinSub4RAW.SylvariFemale[i];
                                        int         colourID    = skinSub3RAW.color_id;
                                        Colour      colour      = main.Colours.FirstOrDefault(col => col.ID == colourID);
                                        Dye         newDye      = new Dye
                                        {
                                            Color       = colour,
                                            DyeMaterial = (Dye.Material)Enum.Parse(typeof(Dye.Material), skinSub3RAW.material)
                                        };
                                        dyeOverride.SylvariFemale.Add(newDye);
                                    }
                                }
                            }

                            dyeSlots.Overrides = dyeOverride;
                        }
                        newDetail.Dyes = dyeSlots;
                    }

                    newSkin.Details = newDetail;
                }
                else if (skinRAW.type == "Weapon" && skinRAW.details != null)
                {
                    SkinSub1RAW  skinSub1RAW = skinRAW.details;
                    WeaponDetail newDetail   = new WeaponDetail
                    {
                        WeaponType = (WeaponDetail.Type)Enum.Parse(typeof(WeaponDetail.Type), skinSub1RAW.type),
                        Damage     = (WeaponDetail.DamageType)Enum.Parse(typeof(WeaponDetail.DamageType), skinSub1RAW.damage_type)
                    };
                    newSkin.Details = newDetail;
                }
                else if (skinRAW.type == "Gathering" && skinRAW.details != null)
                {
                    SkinSub1RAW     skinSub1RAW = skinRAW.details;
                    GatheringDetail newDetail   = new GatheringDetail
                    {
                        GatheringType = (GatheringDetail.Type)Enum.Parse(typeof(GatheringDetail.Type), skinSub1RAW.type)
                    };
                    newSkin.Details = newDetail;
                }
                if (skinRAW.icon != null)
                {
                    string fileName = string.Empty;
                    using (WebClient client = new WebClient())
                    {
                        fileName = skinRAW.icon.Substring(skinRAW.icon.LastIndexOf("/") + 1);
                        Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"images\skins\");
                        if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"images\skins\" + fileName))
                        {
                            client.DownloadFileAsync(new Uri(skinRAW.icon), AppDomain.CurrentDomain.BaseDirectory + @"images\skins\" + fileName);
                        }
                    }
                    newSkin.Image = AppDomain.CurrentDomain.BaseDirectory + @"images\skins\" + fileName;
                }

                main.Skins.Add(newSkin);
                main.OnCharStatusUpdate("Generated Skin " + newSkin.Name + ";" + newSkin.ID + " " + ((cur != 0) ? Math.Round((double)(cur / max), 2) * 100 : 0).ToString() + "%");
            }
        }