Beispiel #1
0
        private void AddObjects(XElement root)
        {
            foreach (var e in root.Elements("Object"))
            {
                var cls = e.GetValue <string>("Class");
                if (string.IsNullOrWhiteSpace(cls))
                {
                    continue;
                }

                var id          = e.GetAttribute <string>("id");
                var type        = e.GetAttribute <ushort>("type");
                var displayId   = e.GetValue <string>("DisplayId");
                var displayName = string.IsNullOrWhiteSpace(displayId) ? id : displayId;

                if (ObjectTypeToId.ContainsKey(type))
                {
                    Log.Warn("'{0}' and '{1}' have the same type of '0x{2:x4}'", id, ObjectTypeToId[type], type);
                }

                if (IdToObjectType.ContainsKey(id))
                {
                    Log.Warn("'0x{0:x4}' and '0x{1:x4}' have the same id of '{2}'", type, IdToObjectType[id], id);
                }

                ObjectTypeToId[type]               = id;
                ObjectTypeToElement[type]          = e;
                IdToObjectType[id]                 = type;
                DisplayIdToObjectType[displayName] = type;

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

                case "Player":
                    var pDesc = Classes[type] = new PlayerDesc(type, e);
                    ObjectDescs[type] = Classes[type];
                    SlotTypeToItemType[pDesc.SlotTypes[0]] = ItemType.Weapon;
                    SlotTypeToItemType[pDesc.SlotTypes[1]] = ItemType.Ability;
                    SlotTypeToItemType[pDesc.SlotTypes[2]] = ItemType.Armor;
                    SlotTypeToItemType[pDesc.SlotTypes[3]] = ItemType.Ring;
                    break;

                case "GuildHallPortal":
                case "Portal":
                    Portals[type]     = new PortalDesc(type, e);
                    ObjectDescs[type] = Portals[type];
                    break;

                case "Skin":
                    Skins[type] = new SkinDesc(type, e);
                    break;

                default:
                    ObjectDescs[type] = new ObjectDesc(type, e);
                    break;
                }
            }
        }
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.Warn("'{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.Warn("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 "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;
                }
            }
        }
Beispiel #3
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 "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++;
                }
            }
        }