public Item(ushort type, XElement elem)
        {
            XElement n;

            ObjectType = type;

            ObjectId = elem.Attribute(XName.Get("id")).Value;

            SlotType = Utils.FromString(elem.Element("SlotType").Value);

            if ((n = elem.Element("Tier")) != null)
            {
                try
                {
                    Tier = Utils.FromString(n.Value);
                }
                catch
                {
                    Tier = -1;
                }
            }
            else
            {
                Tier = -1;
            }

            Description = elem.Element("Description").Value;

            if ((n = elem.Element("RateOfFire")) != null)
            {
                RateOfFire = float.Parse(n.Value);
            }
            else
            {
                RateOfFire = 1;
            }

            Usable = elem.Element("Usable") != null;

            if ((n = elem.Element("BagType")) != null)
            {
                BagType = Utils.FromString(n.Value);
            }
            else
            {
                BagType = 0;
            }

            if ((n = elem.Element("MpCost")) != null)
            {
                MpCost = Utils.FromString(n.Value);
            }
            else
            {
                MpCost = 0;
            }

            if ((n = elem.Element("MpEndCost")) != null)
            {
                MpEndCost = Utils.FromString(n.Value);
            }
            else
            {
                MpEndCost = 0;
            }

            if ((n = elem.Element("FameBonus")) != null)
            {
                FameBonus = Utils.FromString(n.Value);
            }
            else
            {
                FameBonus = 0;
            }

            if ((n = elem.Element("NumProjectiles")) != null)
            {
                NumProjectiles = Utils.FromString(n.Value);
            }
            else
            {
                NumProjectiles = 1;
            }

            if ((n = elem.Element("ArcGap")) != null)
            {
                ArcGap = Utils.FromString(n.Value);
            }
            else
            {
                ArcGap = 11.25f;
            }

            if ((n = elem.Element("ArcGap1")) != null)
            {
                ArcGap1 = Utils.FromString(n.Value);
            }
            else
            {
                ArcGap1 = 11.25f;
            }

            if ((n = elem.Element("ArcGap2")) != null)
            {
                ArcGap2 = Utils.FromString(n.Value);
            }
            else
            {
                ArcGap2 = 11.25f;
            }

            if ((n = elem.Element("NumProjectiles1")) != null)
            {
                NumProjectiles1 = Utils.FromString(n.Value);
            }
            else
            {
                NumProjectiles1 = 1;
            }

            if ((n = elem.Element("NumProjectiles2")) != null)
            {
                NumProjectiles2 = Utils.FromString(n.Value);
            }
            else
            {
                NumProjectiles2 = 1;
            }

            DualShooting = elem.Element("DualShooting") != null;

            Consumable = elem.Element("Consumable") != null;

            Potion = elem.Element("Potion") != null;

            if ((n = elem.Element("DisplayId")) != null)
            {
                DisplayId = n.Value;
            }
            else
            {
                DisplayId = null;
            }

            DisplayName = GetDisplayName();

            if ((n = elem.Element("Doses")) != null)
            {
                Doses = Utils.FromString(n.Value);
            }
            else
            {
                Doses = 0;
            }

            if ((n = elem.Element("feedPower")) != null)
            {
                FeedPower = Utils.FromString(n.Value);
            }
            else
            {
                FeedPower = 0;
            }

            Family = PetDesc.GetFamily(elem.Element("PetFamily"));
            Rarity = PetDesc.GetRarity(elem.Element("Rarity"));

            if ((n = elem.Element("SuccessorId")) != null)
            {
                SuccessorId = n.Value;
            }
            else
            {
                SuccessorId = null;
            }

            Soulbound = elem.Element("Soulbound") != null;

            Undead = elem.Element("Undead") != null;

            PUndead = elem.Element("PUndead") != null;

            SUndead = elem.Element("SUndead") != null;

            Secret = elem.Element("Secret") != null;

            if ((n = elem.Element("Cooldown")) != null)
            {
                Cooldown = float.Parse(n.Value);
            }
            else
            {
                Cooldown = 0;
            }

            Resurrects = elem.Element("Resurrects") != null;

            if ((n = elem.Element("Tex1")) != null)
            {
                Texture1 = Convert.ToInt32(n.Value, 16);
            }
            else
            {
                Texture1 = 0;
            }

            if ((n = elem.Element("Tex2")) != null)
            {
                Texture2 = Convert.ToInt32(n.Value, 16);
            }
            else
            {
                Texture2 = 0;
            }

            var stats = new List <KeyValuePair <int, int> >();

            foreach (XElement i in elem.Elements("ActivateOnEquip"))
            {
                stats.Add(new KeyValuePair <int, int>(
                              int.Parse(i.Attribute("stat").Value),
                              int.Parse(i.Attribute("amount").Value)));
            }
            StatsBoost = stats.ToArray();

            var activate = new List <ActivateEffect>();

            foreach (XElement i in elem.Elements("Activate"))
            {
                activate.Add(new ActivateEffect(i));
            }
            ActivateEffects = activate.ToArray();

            var prj = new List <ProjectileDesc>();

            foreach (XElement i in elem.Elements("Projectile"))
            {
                prj.Add(new ProjectileDesc(i));
            }
            Projectiles = prj.ToArray();
        }
Beispiel #2
0
        private void AddObjects(XElement root)
        {
            foreach (var elem in root.XPathSelectElements("//Object"))
            {
                if (elem.Element("Class") == null)
                {
                    continue;
                }

                var cls = elem.Element("Class").Value;
                var id  = elem.Attribute("id").Value;

                ushort type;
                var    typeAttr = elem.Attribute("type");
                if (typeAttr == null)
                {
                    log.Error($"{id} is missing type number. Skipped.");
                    continue;
                }
                type = (ushort)Utils.FromString(typeAttr.Value);

                if (type2id_obj.ContainsKey(type))
                {
                    log.WarnFormat("'{0}' and '{1}' has the same ID of 0x{2:x4}!", id, type2id_obj[type], type);
                }
                else
                {
                    type2id_obj[type]   = id;
                    type2elem_obj[type] = elem;
                }

                if (id2type_obj.ContainsKey(id))
                {
                    log.WarnFormat("0x{0:x4} and 0x{1:x4} has the same name of {2}!", type, id2type_obj[id], id);
                }
                else
                {
                    id2type_obj[id] = type;
                }

                var displayId = elem.Element("DisplayId") != null?elem.Element("DisplayId").Value : null;

                string displayName;

                if (displayId == null)
                {
                    displayName = id;
                }
                else
                {
                    if (displayId[0].Equals('{'))
                    {
                        displayName = id;
                    }
                    else
                    {
                        displayName = displayId;
                    }
                }

                d_name2type_obj[displayName] = type;

                switch (cls)
                {
                case "Equipment":
                case "Dye":
                    items[type] = new Item(type, elem);
                    break;

                case "Pet":
                    pets[type]     = new PetDesc(type, elem);
                    objDescs[type] = pets[type];
                    break;

                case "PetSkin":
                    petSkins[type] = new PetSkinDesc(type, elem);
                    break;

                case "PetBehavior":
                    petBehaviors[type] = new PetBehaviorDesc(type, elem);
                    break;

                case "PetAbility":
                    petAbilities[type] = new PetAbilityDesc(type, elem);
                    break;

                case "Skin":
                    var skinDesc = SkinDesc.FromElem(type, elem);
                    if (skinDesc != null)
                    {
                        skins.Add(type, skinDesc);
                    }
                    // might want to add skin description to objDesc
                    // dictionary so that skins can be merched...
                    // perhaps later
                    break;

                case "Player":
                    var pDesc = new PlayerDesc(type, elem);
                    slotType2ItemType[pDesc.SlotTypes[0]] = ItemType.Weapon;
                    slotType2ItemType[pDesc.SlotTypes[1]] = ItemType.Ability;
                    slotType2ItemType[pDesc.SlotTypes[2]] = ItemType.Armor;
                    slotType2ItemType[pDesc.SlotTypes[3]] = ItemType.Ring;
                    classes[type]  = new PlayerDesc(type, elem);
                    objDescs[type] = classes[type];
                    break;

                case "Portal":
                    portals[type]  = new PortalDesc(type, elem);
                    objDescs[type] = portals[type];
                    break;

                case "GuildMerchant":
                case "Merchant":
                    merchants[type] = new ObjectDesc(type, elem);
                    break;

                default:
                    objDescs[type] = new ObjectDesc(type, elem);
                    break;
                }

                // collect info on used remote textures
                var rt = elem.Element("RemoteTexture");
                if (rt != null)
                {
                    try
                    {
                        var texType = GetRemoteTexType(rt);
                        if (_usedRemoteTextures.All(tex => tex[1] != texType[1]))
                        {
                            _usedRemoteTextures.Add(texType);
                        }
                    }
                    catch (Exception e)
                    {
                        log.WarnFormat("Getting remote texture info for '{0}, {1}' failed! {2}",
                                       id, type, e.Message);
                    }
                }

                var  extAttr = elem.Attribute("ext");
                bool ext;
                if (extAttr != null && bool.TryParse(extAttr.Value, out ext) && ext)
                {
                    if (elem.Attribute("type") == null)
                    {
                        elem.Add(new XAttribute("type", type));
                    }
                    this.addition.Add(elem);
                    updateCount++;
                }
            }
        }