public static ItemInformationPacket Create(Structures.ConquerItem item, ItemInfoAction createType = ItemInfoAction.AddItem)
        {
            var packet = new ItemInformationPacket();

            packet.UniqueID          = item.UniqueID;
            packet.StaticID          = item.StaticID;
            packet.Durability        = item.Durability;
            packet.MaximumDurability = item.MaximumDurability;
            packet.Action            = createType;
            packet.Location          = item.Location;
            packet.Gem1    = item.Gem1;
            packet.Gem2    = item.Gem2;
            packet.Plus    = item.Plus;
            packet.Bless   = item.Bless;
            packet.Enchant = item.Enchant;
            packet.Color   = item.Color;
            packet.Locked  = item.Locked;
            return(packet);
        }
        public void LoadItems()
        {
            _logger.Information("Loading items...");
            var dto         = Deserialize <ItemInfoDto>("xml/iteminfo.x7");
            var stringTable = Deserialize <StringTableDto>("language/xml/iteminfo_string_table.x7");

            Items = Transform().ToImmutableDictionary(x => x.ItemNumber, x => x);
            _logger.Information("Loaded {Count} items", Items.Count);

            IEnumerable <ItemInfo> Transform()
            {
                foreach (var categoryDto in dto.category)
                {
                    foreach (var subCategoryDto in categoryDto.sub_category)
                    {
                        foreach (var itemDto in subCategoryDto.item)
                        {
                            var      id = new ItemNumber(categoryDto.id, subCategoryDto.id, itemDto.number);
                            ItemInfo item;

                            switch (id.Category)
                            {
                            case ItemCategory.Skill:
                                item = LoadAction(id, itemDto);
                                break;

                            case ItemCategory.Weapon:
                                item = LoadWeapon(id, itemDto);
                                break;

                            default:
                                item = new ItemInfo();
                                break;
                            }

                            item.ItemNumber  = id;
                            item.Level       = [email protected]_info.require_level;
                            item.MasterLevel = [email protected]_info.require_master;
                            item.Gender      = ParseGender(itemDto.SEX);
                            item.Image       = itemDto.client.icon.image;

                            if ([email protected] != null)
                            {
                                item.License = ParseItemLicense([email protected]);
                            }

                            var name = [email protected](s =>
                                                                          s.key.Equals([email protected]_info.name_key, StringComparison.InvariantCultureIgnoreCase));
                            if (string.IsNullOrWhiteSpace(name?.eng))
                            {
                                _logger.Warning("Missing english translation for {id}",
                                                name != null ? [email protected]_info.name_key : id.ToString());
                                item.Name = name != null ? name.key : itemDto.NAME;
                            }
                            else
                            {
                                item.Name = name.eng;
                            }

                            yield return(item);
                        }
                    }
                }
            }

            Gender ParseGender(string gender)
            {
                bool Equals(string str)
                {
                    return(gender.Equals(str, StringComparison.InvariantCultureIgnoreCase));
                }

                if (Equals("all"))
                {
                    return(Gender.None);
                }

                if (Equals("woman"))
                {
                    return(Gender.Female);
                }

                if (Equals("man"))
                {
                    return(Gender.Male);
                }

                throw new Exception("Invalid gender " + gender);
            }

            ItemInfo LoadAction(ItemNumber id, ItemInfoItemDto itemDto)
            {
                if (itemDto.action == null)
                {
                    _logger.Warning("Missing action for item {id}", id);
                    return(new ItemInfoAction());
                }

                var item = new ItemInfoAction
                {
                    RequiredMP       = float.Parse(itemDto.action.ability.required_mp, CultureInfo.InvariantCulture),
                    DecrementMP      = float.Parse(itemDto.action.ability.decrement_mp, CultureInfo.InvariantCulture),
                    DecrementMPDelay = float.Parse(itemDto.action.ability.decrement_mp_delay, CultureInfo.InvariantCulture)
                };

                if (itemDto.action.@float != null)
                {
                    item.ValuesF = itemDto.action.@float
                                   .Select(f => float.Parse(f.value.Replace("f", ""), CultureInfo.InvariantCulture)).ToList();
                }

                if (itemDto.action.integer != null)
                {
                    item.Values = itemDto.action.integer.Select(i => i.value).ToList();
                }

                return(item);
            }

            ItemInfo LoadWeapon(ItemNumber id, ItemInfoItemDto itemDto)
            {
                if (itemDto.weapon == null)
                {
                    _logger.Warning("Missing weapon for item {id}", id);
                    return(new ItemInfoWeapon());
                }

                var ability = itemDto.weapon.ability;
                var item    = new ItemInfoWeapon
                {
                    Type                    = ability.type,
                    RateOfFire              = float.Parse(ability.rate_of_fire, CultureInfo.InvariantCulture),
                    Power                   = float.Parse(ability.power, CultureInfo.InvariantCulture),
                    MoveSpeedRate           = float.Parse(ability.move_speed_rate, CultureInfo.InvariantCulture),
                    AttackMoveSpeedRate     = float.Parse(ability.attack_move_speed_rate, CultureInfo.InvariantCulture),
                    MagazineCapacity        = ability.magazine_capacity,
                    CrackedMagazineCapacity = ability.cracked_magazine_capacity,
                    MaxAmmo                 = ability.max_ammo,
                    Accuracy                = float.Parse(ability.accuracy, CultureInfo.InvariantCulture),
                    Range                   = string.IsNullOrWhiteSpace(ability.range)
                        ? 0
                        : float.Parse(ability.range, CultureInfo.InvariantCulture),
                    SupportSniperMode  = ability.support_sniper_mode > 0,
                    SniperModeFov      = ability.sniper_mode_fov > 0,
                    AutoTargetDistance = ability.auto_target_distance == null
                        ? 0
                        : float.Parse(ability.auto_target_distance, CultureInfo.InvariantCulture)
                };

                if (itemDto.weapon.@float != null)
                {
                    item.ValuesF = itemDto.weapon.@float
                                   .Select(f => float.Parse(f.value.Replace("f", ""), CultureInfo.InvariantCulture)).ToList();
                }

                if (itemDto.weapon.integer != null)
                {
                    item.Values = itemDto.weapon.integer.Select(i => i.value).ToList();
                }

                return(item);
            }
        }
Exemplo n.º 3
0
        public static ItemInformationPacket CreateJar(Structures.ConquerItem item, ushort _MonsterType, ushort _ToKill, ItemInfoAction createType = ItemInfoAction.AddItem)
        {
            var packet = new ItemInformationPacket();

            packet.UniqueID          = item.UniqueID;
            packet.StaticID          = item.StaticID;
            packet.Durability        = _ToKill;
            packet.MaximumDurability = _MonsterType;
            packet.Action            = createType;
            packet.Location          = item.Location;
            packet.Gem1         = item.Gem1;
            packet.Gem2         = item.Gem2;
            packet.Plus         = item.Plus;
            packet.Bless        = item.Bless;
            packet.Enchant      = item.Enchant;
            packet.Color        = item.Color;
            packet.Locked       = item.Locked;
            packet.RebornEffect = item.Effect;
            return(packet);
        }