Ejemplo n.º 1
0
        private static XElement ParseMedical(ItemPrefab prefab)
        {
            XElement?itemMeleeWeapon = prefab.ConfigElement.GetChildElement(nameof(MeleeWeapon));
            // affliction, amount, duration
            List <Tuple <string, float, float> > onSuccessAfflictions = new List <Tuple <string, float, float> >();
            List <Tuple <string, float, float> > onFailureAfflictions = new List <Tuple <string, float, float> >();
            int medicalRequiredSkill = 0;

            if (itemMeleeWeapon != null)
            {
                List <StatusEffect> statusEffects = new List <StatusEffect>();
                foreach (XElement subElement in itemMeleeWeapon.Elements())
                {
                    string name = subElement.Name.ToString();
                    if (name.Equals(nameof(StatusEffect), StringComparison.OrdinalIgnoreCase))
                    {
                        StatusEffect statusEffect = StatusEffect.Load(subElement, debugIdentifier);
                        if (statusEffect == null || !statusEffect.HasTag("medical"))
                        {
                            continue;
                        }

                        statusEffects.Add(statusEffect);
                    }
                    else if (IsRequiredSkill(subElement, out Skill? skill) && skill != null)
                    {
                        medicalRequiredSkill = (int)skill.Level;
                    }
                }

                List <StatusEffect> successEffects = statusEffects.Where(se => se.type == ActionType.OnUse).ToList();
                List <StatusEffect> failureEffects = statusEffects.Where(se => se.type == ActionType.OnFailure).ToList();

                foreach (StatusEffect statusEffect in successEffects)
                {
                    float duration = statusEffect.Duration;
                    onSuccessAfflictions.AddRange(statusEffect.ReduceAffliction.Select(pair => Tuple.Create(GetAfflictionName(pair.affliction), -pair.amount, duration)));
                    onSuccessAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => Tuple.Create(affliction.Prefab.Name, affliction.NonClampedStrength, duration)));
                }

                foreach (StatusEffect statusEffect in failureEffects)
                {
                    float duration = statusEffect.Duration;
                    onFailureAfflictions.AddRange(statusEffect.ReduceAffliction.Select(pair => Tuple.Create(GetAfflictionName(pair.affliction), -pair.amount, duration)));
                    onFailureAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => Tuple.Create(affliction.Prefab.Name, affliction.NonClampedStrength, duration)));
                }
            }

            return(new XElement("Medical",
                                new XAttribute("skillamount", medicalRequiredSkill),
                                new XAttribute("successafflictions", FormatArray(onSuccessAfflictions.Select(tpl => tpl.Item1))),
                                new XAttribute("successamounts", FormatArray(onSuccessAfflictions.Select(tpl => FormatFloat(tpl.Item2)))),
                                new XAttribute("successdurations", FormatArray(onSuccessAfflictions.Select(tpl => FormatFloat(tpl.Item3)))),
                                new XAttribute("failureafflictions", FormatArray(onFailureAfflictions.Select(tpl => tpl.Item1))),
                                new XAttribute("failureamounts", FormatArray(onFailureAfflictions.Select(tpl => FormatFloat(tpl.Item2)))),
                                new XAttribute("failuredurations", FormatArray(onFailureAfflictions.Select(tpl => FormatFloat(tpl.Item3))))
                                ));
        }