public Effect(XElement element, string parentDebugName)
            {
                SerializableProperty.DeserializeProperties(this, element);

                resistanceFor = element.GetAttributeStringArray("resistancefor", new string[0], convertToLowerInvariant: true);

                foreach (XElement subElement in element.Elements())
                {
                    switch (subElement.Name.ToString().ToLowerInvariant())
                    {
                    case "statuseffect":
                        StatusEffects.Add(StatusEffect.Load(subElement, parentDebugName));
                        break;

                    case "statvalue":
                        var statType = CharacterAbilityGroup.ParseStatType(subElement.GetAttributeString("stattype", ""), parentDebugName);

                        float defaultValue = subElement.GetAttributeFloat("value", 0f);
                        float minValue     = subElement.GetAttributeFloat("minvalue", defaultValue);
                        float maxValue     = subElement.GetAttributeFloat("maxvalue", defaultValue);

                        AfflictionStatValues.TryAdd(statType, (minValue, maxValue));
                        break;

                    case "abilityflag":
                        var flagType = CharacterAbilityGroup.ParseFlagType(subElement.GetAttributeString("flagtype", ""), parentDebugName);
                        AfflictionAbilityFlags.Add(flagType);
                        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().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;
                }
            }
        }