Пример #1
0
        protected StatusEffect(XElement element)
        {
            requiredItems = new List <RelatedItem>();

#if CLIENT
            particleEmitters = new List <ParticleEmitterPrefab>();
#endif

            IEnumerable <XAttribute> attributes         = element.Attributes();
            List <XAttribute>        propertyAttributes = new List <XAttribute>();

            foreach (XAttribute attribute in attributes)
            {
                switch (attribute.Name.ToString())
                {
                case "type":
                    try
                    {
                        type = (ActionType)Enum.Parse(typeof(ActionType), attribute.Value, true);
                    }

                    catch
                    {
                        string[] split = attribute.Value.Split('=');
                        type = (ActionType)Enum.Parse(typeof(ActionType), split[0], true);

                        string[] containingNames = split[1].Split(',');
                        onContainingNames = new HashSet <string>();
                        for (int i = 0; i < containingNames.Length; i++)
                        {
                            onContainingNames.Add(containingNames[i].Trim());
                        }
                    }

                    break;

                case "target":
                    string[] Flags = attribute.Value.Split(',');
                    foreach (string s in Flags)
                    {
                        targetTypes |= (TargetType)Enum.Parse(typeof(TargetType), s, true);
                    }

                    break;

                case "disabledeltatime":
                    disableDeltaTime = ToolBox.GetAttributeBool(attribute, false);
                    break;

                case "setvalue":
                    setValue = ToolBox.GetAttributeBool(attribute, false);
                    break;

                case "targetnames":
                    string[] names = attribute.Value.Split(',');
                    targetNames = new HashSet <string>();
                    for (int i = 0; i < names.Length; i++)
                    {
                        targetNames.Add(names[i].Trim());
                    }
                    break;

                case "duration":
                    duration = ToolBox.GetAttributeFloat(attribute, 0.0f);
                    break;

#if CLIENT
                case "sound":
                    sound = Sound.Load(attribute.Value.ToString());
                    break;
#endif
                default:
                    propertyAttributes.Add(attribute);
                    break;
                }
            }

            int count = propertyAttributes.Count;
            propertyNames   = new string[count];
            propertyEffects = new object[count];

            int n = 0;
            foreach (XAttribute attribute in propertyAttributes)
            {
                propertyNames[n]   = attribute.Name.ToString().ToLowerInvariant();
                propertyEffects[n] = ToolBox.GetAttributeObject(attribute);
                n++;
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "explosion":
                    explosion = new Explosion(subElement);
                    break;

                case "fire":
                    FireSize = ToolBox.GetAttributeFloat(subElement, "size", 10.0f);
                    break;

                case "use":
                case "useitem":
                    useItem = true;
                    break;

                case "requireditem":
                case "requireditems":
                    RelatedItem newRequiredItem = RelatedItem.Load(subElement);

                    if (newRequiredItem == null)
                    {
                        continue;
                    }

                    requiredItems.Add(newRequiredItem);
                    break;

#if CLIENT
                case "particleemitter":
                    particleEmitters.Add(new ParticleEmitterPrefab(subElement));
                    break;
#endif
                }
            }
        }
Пример #2
0
        protected StatusEffect(XElement element, string parentDebugName)
        {
            requiredItems    = new List <RelatedItem>();
            spawnItems       = new List <ItemSpawnInfo>();
            Afflictions      = new List <Affliction>();
            ReduceAffliction = new List <Pair <string, float> >();
            tags             = new HashSet <string>(element.GetAttributeString("tags", "").Split(','));

            Range = element.GetAttributeFloat("range", 0.0f);

            IEnumerable <XAttribute> attributes         = element.Attributes();
            List <XAttribute>        propertyAttributes = new List <XAttribute>();

            propertyConditionals = new List <PropertyConditional>();

            foreach (XAttribute attribute in attributes)
            {
                switch (attribute.Name.ToString())
                {
                case "type":
                    if (!Enum.TryParse(attribute.Value, true, out type))
                    {
                        DebugConsole.ThrowError("Invalid action type \"" + attribute.Value + "\" in StatusEffect (" + parentDebugName + ")");
                    }
                    break;

                case "target":
                    string[] Flags = attribute.Value.Split(',');
                    foreach (string s in Flags)
                    {
                        if (!Enum.TryParse(s, true, out TargetType targetType))
                        {
                            DebugConsole.ThrowError("Invalid target type \"" + s + "\" in StatusEffect (" + parentDebugName + ")");
                        }
                        else
                        {
                            targetTypes |= targetType;
                        }
                    }
                    break;

                case "disabledeltatime":
                    disableDeltaTime = attribute.GetAttributeBool(false);
                    break;

                case "setvalue":
                    setValue = attribute.GetAttributeBool(false);
                    break;

                case "targetnames":
                    DebugConsole.ThrowError("Error in StatusEffect config (" + parentDebugName + ") - use identifiers or tags to define the targets instead of names.");
                    break;

                case "targetidentifiers":
                    string[] identifiers = attribute.Value.Split(',');
                    targetIdentifiers = new HashSet <string>();
                    for (int i = 0; i < identifiers.Length; i++)
                    {
                        targetIdentifiers.Add(identifiers[i].Trim().ToLowerInvariant());
                    }
                    break;

                case "duration":
                    duration = attribute.GetAttributeFloat(0.0f);
                    break;

                case "stackable":
                    Stackable = attribute.GetAttributeBool(true);
                    break;

                case "checkconditionalalways":
                    CheckConditionalAlways = attribute.GetAttributeBool(false);
                    break;

                case "conditionalcomparison":
                case "comparison":
                    if (!Enum.TryParse(attribute.Value, out conditionalComparison))
                    {
                        DebugConsole.ThrowError("Invalid conditional comparison type \"" + attribute.Value + "\" in StatusEffect (" + parentDebugName + ")");
                    }
                    break;

                case "sound":
                    DebugConsole.ThrowError("Error in StatusEffect " + element.Parent.Name.ToString() +
                                            " - sounds should be defined as child elements of the StatusEffect, not as attributes.");
                    break;

                default:
                    propertyAttributes.Add(attribute);
                    break;
                }
            }

            int count = propertyAttributes.Count;

            propertyNames   = new string[count];
            propertyEffects = new object[count];

            int n = 0;

            foreach (XAttribute attribute in propertyAttributes)
            {
                propertyNames[n]   = attribute.Name.ToString().ToLowerInvariant();
                propertyEffects[n] = XMLExtensions.GetAttributeObject(attribute);
                n++;
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "explosion":
                    explosion = new Explosion(subElement, parentDebugName);
                    break;

                case "fire":
                    FireSize = subElement.GetAttributeFloat("size", 10.0f);
                    break;

                case "use":
                case "useitem":
                    useItemCount++;
                    break;

                case "remove":
                case "removeitem":
                    removeItem = true;
                    break;

                case "requireditem":
                case "requireditems":
                    RelatedItem newRequiredItem = RelatedItem.Load(subElement, parentDebugName);
                    if (newRequiredItem == null)
                    {
                        DebugConsole.ThrowError("Error in StatusEffect config - requires an item with no identifiers.");
                        continue;
                    }
                    requiredItems.Add(newRequiredItem);
                    break;

                case "conditional":
                    IEnumerable <XAttribute> conditionalAttributes = subElement.Attributes();
                    foreach (XAttribute attribute in conditionalAttributes)
                    {
                        if (attribute.Name.ToString().ToLowerInvariant() == "targetitemcomponent")
                        {
                            continue;
                        }
                        propertyConditionals.Add(new PropertyConditional(attribute));
                    }
                    break;

                case "affliction":
                    AfflictionPrefab afflictionPrefab;
                    if (subElement.Attribute("name") != null)
                    {
                        DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - define afflictions using identifiers instead of names.");
                        string afflictionName = subElement.GetAttributeString("name", "").ToLowerInvariant();
                        afflictionPrefab = AfflictionPrefab.List.Find(ap => ap.Name.ToLowerInvariant() == afflictionName);
                        if (afflictionPrefab == null)
                        {
                            DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - Affliction prefab \"" + afflictionName + "\" not found.");
                            continue;
                        }
                    }
                    else
                    {
                        string afflictionIdentifier = subElement.GetAttributeString("identifier", "").ToLowerInvariant();
                        afflictionPrefab = AfflictionPrefab.List.Find(ap => ap.Identifier.ToLowerInvariant() == afflictionIdentifier);
                        if (afflictionPrefab == null)
                        {
                            DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - Affliction prefab with the identifier \"" + afflictionIdentifier + "\" not found.");
                            continue;
                        }
                    }

                    float afflictionStrength = subElement.GetAttributeFloat(1.0f, "amount", "strength");
                    Afflictions.Add(afflictionPrefab.Instantiate(afflictionStrength));

                    break;

                case "reduceaffliction":
                    if (subElement.Attribute("name") != null)
                    {
                        DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - define afflictions using identifiers or types instead of names.");
                        ReduceAffliction.Add(new Pair <string, float>(
                                                 subElement.GetAttributeString("name", "").ToLowerInvariant(),
                                                 subElement.GetAttributeFloat(1.0f, "amount", "strength", "reduceamount")));
                    }
                    else
                    {
                        string name = subElement.GetAttributeString("identifier", null) ?? subElement.GetAttributeString("type", null);
                        name = name.ToLowerInvariant();

                        if (AfflictionPrefab.List.Any(ap => ap.Identifier == name || ap.AfflictionType == name))
                        {
                            ReduceAffliction.Add(new Pair <string, float>(
                                                     name,
                                                     subElement.GetAttributeFloat(1.0f, "amount", "strength", "reduceamount")));
                        }
                        else
                        {
                            DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - Affliction prefab with the identifier or type \"" + name + "\" not found.");
                        }
                    }
                    break;

                case "spawnitem":
                    var newSpawnItem = new ItemSpawnInfo(subElement, parentDebugName);
                    if (newSpawnItem.ItemPrefab != null)
                    {
                        spawnItems.Add(newSpawnItem);
                    }
                    break;
                }
            }
            InitProjSpecific(element, parentDebugName);
        }
Пример #3
0
        protected StatusEffect(XElement element)
        {
            requiredItems = new List <RelatedItem>();
            tags          = new HashSet <string>(element.GetAttributeString("tags", "").Split(','));

#if CLIENT
            particleEmitters = new List <ParticleEmitter>();
#endif

            IEnumerable <XAttribute> attributes         = element.Attributes();
            List <XAttribute>        propertyAttributes = new List <XAttribute>();
            propertyConditionals = new List <PropertyConditional>();

            foreach (XAttribute attribute in attributes)
            {
                switch (attribute.Name.ToString())
                {
                case "type":
                    try
                    {
                        type = (ActionType)Enum.Parse(typeof(ActionType), attribute.Value, true);
                    }

                    catch
                    {
                        string[] split = attribute.Value.Split('=');
                        type = (ActionType)Enum.Parse(typeof(ActionType), split[0], true);

                        string[] containingNames = split[1].Split(',');
                        onContainingNames = new HashSet <string>();
                        for (int i = 0; i < containingNames.Length; i++)
                        {
                            onContainingNames.Add(containingNames[i].Trim());
                        }
                    }

                    break;

                case "target":
                    string[] Flags = attribute.Value.Split(',');
                    foreach (string s in Flags)
                    {
                        targetTypes |= (TargetType)Enum.Parse(typeof(TargetType), s, true);
                    }

                    break;

                case "disabledeltatime":
                    disableDeltaTime = attribute.GetAttributeBool(false);
                    break;

                case "setvalue":
                    setValue = attribute.GetAttributeBool(false);
                    break;

                case "targetnames":
                    string[] names = attribute.Value.Split(',');
                    targetNames = new HashSet <string>();
                    for (int i = 0; i < names.Length; i++)
                    {
                        targetNames.Add(names[i].Trim());
                    }
                    break;

                case "duration":
                    duration = attribute.GetAttributeFloat(0.0f);
                    break;

                case "stackable":
                    Stackable = attribute.GetAttributeBool(true);
                    break;

                case "checkconditionalalways":
                    CheckConditionalAlways = attribute.GetAttributeBool(false);
                    break;

                case "sound":
                    DebugConsole.ThrowError("Error in StatusEffect " + element.Parent.Name.ToString() +
                                            " - sounds should be defined as child elements of the StatusEffect, not as attributes.");
                    break;

                default:
                    propertyAttributes.Add(attribute);
                    break;
                }
            }

            int count = propertyAttributes.Count;
            propertyNames   = new string[count];
            propertyEffects = new object[count];

            int n = 0;
            foreach (XAttribute attribute in propertyAttributes)
            {
                propertyNames[n]   = attribute.Name.ToString().ToLowerInvariant();
                propertyEffects[n] = XMLExtensions.GetAttributeObject(attribute);
                n++;
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "explosion":
                    explosion = new Explosion(subElement);
                    break;

                case "fire":
                    FireSize = subElement.GetAttributeFloat("size", 10.0f);
                    break;

                case "use":
                case "useitem":
                    useItemCount++;
                    break;

                case "remove":
                case "removeitem":
                    removeItem = true;
                    break;

                case "requireditem":
                case "requireditems":
                    RelatedItem newRequiredItem = RelatedItem.Load(subElement);

                    if (newRequiredItem == null)
                    {
                        continue;
                    }

                    requiredItems.Add(newRequiredItem);
                    break;

                case "conditional":
                    IEnumerable <XAttribute> conditionalAttributes = subElement.Attributes();
                    foreach (XAttribute attribute in conditionalAttributes)
                    {
                        propertyConditionals.Add(new PropertyConditional(attribute));
                    }
                    break;

#if CLIENT
                case "particleemitter":
                    particleEmitters.Add(new ParticleEmitter(subElement));
                    break;

                case "sound":
                    sound     = Sound.Load(subElement);
                    loopSound = subElement.GetAttributeBool("loop", false);
                    break;
#endif
                }
            }
        }