public Wearable(Item item, XElement element)
            : base(item, element)
        {
            this.item = item;

            damageModifiers = new List <DamageModifier>();

            int spriteCount = element.Elements().Count(x => x.Name.ToString() == "sprite");

            wearableSprites = new WearableSprite[spriteCount];
            limbType        = new LimbType[spriteCount];
            limb            = new Limb[spriteCount];

            int i = 0;

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLower())
                {
                case "sprite":
                    if (subElement.Attribute("texture") == null)
                    {
                        DebugConsole.ThrowError("Item \"" + item.Name + "\" doesn't have a texture specified!");
                        return;
                    }

                    string spritePath = subElement.Attribute("texture").Value;
                    spritePath = Path.GetDirectoryName(item.Prefab.ConfigFile) + "/" + spritePath;

                    var sound  = subElement.GetAttributeString("sound", "");
                    var sprite = new Sprite(subElement, "", spritePath);
                    limbType[i] = (LimbType)Enum.Parse(typeof(LimbType),
                                                       subElement.GetAttributeString("limb", "Head"), true);

                    wearableSprites[i] = new WearableSprite(this, sprite, limbType[i],
                                                            subElement.GetAttributeBool("hidelimb", false),
                                                            subElement.GetAttributeBool("inheritlimbdepth", true),
                                                            (LimbType)Enum.Parse(typeof(LimbType), subElement.GetAttributeString("depthlimb", "None"), true), sound);

                    foreach (XElement lightElement in subElement.Elements())
                    {
                        if (lightElement.Name.ToString().ToLowerInvariant() != "lightcomponent")
                        {
                            continue;
                        }
                        wearableSprites[i].LightComponent        = new LightComponent(item, lightElement);
                        wearableSprites[i].LightComponent.Parent = this;
                        item.components.Add(wearableSprites[i].LightComponent);
                    }

                    i++;
                    break;

                case "damagemodifier":
                    damageModifiers.Add(new DamageModifier(subElement));
                    break;
                }
            }
        }
Example #2
0
        public Wearable(Item item, XElement element) : base(item, element)
        {
            this.item = item;

            damageModifiers = new List <DamageModifier>();

            int spriteCount = element.Elements().Count(x => x.Name.ToString() == "sprite");

            Variants               = element.GetAttributeInt("variants", 0);
            variant                = Rand.Range(1, Variants + 1, Rand.RandSync.Server);
            wearableSprites        = new WearableSprite[spriteCount];
            wearableElements       = new XElement[spriteCount];
            limbType               = new LimbType[spriteCount];
            limb                   = new Limb[spriteCount];
            AutoEquipWhenFull      = element.GetAttributeBool("autoequipwhenfull", true);
            DisplayContainedStatus = element.GetAttributeBool("displaycontainedstatus", false);
            int i = 0;

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLower())
                {
                case "sprite":
                    if (subElement.Attribute("texture") == null)
                    {
                        DebugConsole.ThrowError("Item \"" + item.Name + "\" doesn't have a texture specified!");
                        return;
                    }

                    limbType[i] = (LimbType)Enum.Parse(typeof(LimbType),
                                                       subElement.GetAttributeString("limb", "Head"), true);

                    wearableSprites[i]  = new WearableSprite(subElement, this, variant);
                    wearableElements[i] = subElement;

                    foreach (XElement lightElement in subElement.Elements())
                    {
                        if (!lightElement.Name.ToString().Equals("lightcomponent", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        wearableSprites[i].LightComponent = new LightComponent(item, lightElement)
                        {
                            Parent = this
                        };
                        item.AddComponent(wearableSprites[i].LightComponent);
                    }

                    i++;
                    break;

                case "damagemodifier":
                    damageModifiers.Add(new DamageModifier(subElement, item.Name + ", Wearable"));
                    break;
                }
            }
        }
Example #3
0
        public Wearable(Item item, XElement element) : base(item, element)
        {
            this.item = item;

            damageModifiers = new List <DamageModifier>();

            int spriteCount = element.Elements().Count(x => x.Name.ToString() == "sprite");
            int variants    = element.GetAttributeInt("variants", 0);
            int variant     = variants > 0 ? Rand.Range(1, variants + 1, Rand.RandSync.Server) : 1;

            wearableSprites = new WearableSprite[spriteCount];
            limbType        = new LimbType[spriteCount];
            limb            = new Limb[spriteCount];
            int i = 0;

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLower())
                {
                case "sprite":
                    if (subElement.Attribute("texture") == null)
                    {
                        DebugConsole.ThrowError("Item \"" + item.Name + "\" doesn't have a texture specified!");
                        return;
                    }

                    limbType[i] = (LimbType)Enum.Parse(typeof(LimbType),
                                                       subElement.GetAttributeString("limb", "Head"), true);

                    wearableSprites[i] = new WearableSprite(subElement, this, variant);

                    foreach (XElement lightElement in subElement.Elements())
                    {
                        if (lightElement.Name.ToString().ToLowerInvariant() != "lightcomponent")
                        {
                            continue;
                        }
                        wearableSprites[i].LightComponent = new LightComponent(item, lightElement)
                        {
                            Parent = this
                        };
                        item.AddComponent(wearableSprites[i].LightComponent);
                    }

                    i++;
                    break;

                case "damagemodifier":
                    damageModifiers.Add(new DamageModifier(subElement, item.Name + ", Wearable"));
                    break;
                }
            }
        }
Example #4
0
        public Wearable(Item item, XElement element)
            : base(item, element)
        {
            this.item = item;

            var sprites     = element.Elements().Where(x => x.Name.ToString() == "sprite").ToList();
            int spriteCount = sprites.Count;

            wearableSprites = new WearableSprite[spriteCount];
            limbType        = new LimbType[spriteCount];
            limb            = new Limb[spriteCount];

            int i = 0;

            foreach (XElement subElement in sprites)
            {
                //Rectangle sourceRect = new Rectangle(
                //    ToolBox.GetAttributeInt(subElement, "sourcex", 1),
                //    ToolBox.GetAttributeInt(subElement, "sourcey", 1),
                //    ToolBox.GetAttributeInt(subElement, "sourcewidth", 1),
                //    ToolBox.GetAttributeInt(subElement, "sourceheight", 1));

                if (subElement.Attribute("texture") == null)
                {
                    DebugConsole.ThrowError("Item \"" + item.Name + "\" doesn't have a texture specified!");
                    return;
                }

                string spritePath = subElement.Attribute("texture").Value;
                spritePath = Path.GetDirectoryName(item.Prefab.ConfigFile) + "/" + spritePath;

                var sprite = new Sprite(subElement, "", spritePath);
                wearableSprites[i] = new WearableSprite(this, sprite,
                                                        subElement.GetAttributeBool("hidelimb", false),
                                                        subElement.GetAttributeBool("inheritlimbdepth", true),
                                                        (LimbType)Enum.Parse(typeof(LimbType), subElement.GetAttributeString("depthlimb", "None"), true));

                limbType[i] = (LimbType)Enum.Parse(typeof(LimbType),
                                                   subElement.GetAttributeString("limb", "Head"), true);

                i++;
            }
        }
Example #5
0
        public Wearable(Item item, XElement element) : base(item, element)
        {
            this.item = item;

            damageModifiers = new List <DamageModifier>();

            int spriteCount = element.Elements().Count(x => x.Name.ToString() == "sprite");

            Variants               = element.GetAttributeInt("variants", 0);
            variant                = Rand.Range(1, Variants + 1, Rand.RandSync.Server);
            wearableSprites        = new WearableSprite[spriteCount];
            wearableElements       = new XElement[spriteCount];
            limbType               = new LimbType[spriteCount];
            limb                   = new Limb[spriteCount];
            AutoEquipWhenFull      = element.GetAttributeBool("autoequipwhenfull", true);
            DisplayContainedStatus = element.GetAttributeBool("displaycontainedstatus", false);
            int i = 0;

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    if (subElement.Attribute("texture") == null)
                    {
                        DebugConsole.ThrowError("Item \"" + item.Name + "\" doesn't have a texture specified!");
                        return;
                    }

                    limbType[i] = (LimbType)Enum.Parse(typeof(LimbType),
                                                       subElement.GetAttributeString("limb", "Head"), true);

                    wearableSprites[i]  = new WearableSprite(subElement, this, variant);
                    wearableElements[i] = subElement;

                    foreach (XElement lightElement in subElement.Elements())
                    {
                        if (!lightElement.Name.ToString().Equals("lightcomponent", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        wearableSprites[i].LightComponent = new LightComponent(item, lightElement)
                        {
                            Parent = this
                        };
                        item.AddComponent(wearableSprites[i].LightComponent);
                    }

                    i++;
                    break;

                case "damagemodifier":
                    damageModifiers.Add(new DamageModifier(subElement, item.Name + ", Wearable"));
                    break;

                case "skillmodifier":
                    string skillIdentifier = subElement.GetAttributeString("skillidentifier", string.Empty);
                    float  skillValue      = subElement.GetAttributeFloat("skillvalue", 0f);
                    if (SkillModifiers.ContainsKey(skillIdentifier))
                    {
                        SkillModifiers[skillIdentifier] += skillValue;
                    }
                    else
                    {
                        SkillModifiers.TryAdd(skillIdentifier, skillValue);
                    }
                    break;

                case "statvalue":
                    StatTypes statType  = CharacterAbilityGroup.ParseStatType(subElement.GetAttributeString("stattype", ""), Name);
                    float     statValue = subElement.GetAttributeFloat("value", 0f);
                    if (WearableStatValues.ContainsKey(statType))
                    {
                        WearableStatValues[statType] += statValue;
                    }
                    else
                    {
                        WearableStatValues.TryAdd(statType, statValue);
                    }
                    break;
                }
            }
        }