public IEnumerable <string> ToIniValues(NPCSpawnContainerType containerType) { if (string.IsNullOrWhiteSpace(IniCollectionKey)) { return(this.Where(d => d.ShouldSave()).Cast <ISpawnIniValue>().Select(d => d.ToIniValue(containerType))); } return(this.Where(d => d.ShouldSave()).Cast <ISpawnIniValue>().Select(d => $"{this.IniCollectionKey}={d.ToIniValue(containerType)}")); }
public string ToIniValue(NPCSpawnContainerType containerType) { GetPropertyInfos(); if (this.Properties.Count == 0) { return(string.Empty); } var result = new StringBuilder(); var delimiter = ""; foreach (var prop in this.Properties) { var attrSpawn = prop.GetCustomAttributes(typeof(NPCSpawnAttribute), false).OfType <NPCSpawnAttribute>().FirstOrDefault(); if (!attrSpawn?.ContainerTypes?.Contains(containerType) ?? false) { continue; } result.Append(delimiter); var attr = prop.GetCustomAttributes(typeof(AggregateIniValueEntryAttribute), false).OfType <AggregateIniValueEntryAttribute>().FirstOrDefault(); var propName = string.IsNullOrWhiteSpace(attr?.Key) ? prop.Name : attr.Key; result.Append($"{propName}="); if (attr?.ValueWithinBrackets ?? false) { result.Append("("); } var val = prop.GetValue(this); var spawnCollection = val as ISpawnIniValuesCollection; if (spawnCollection != null) { var iniVals = spawnCollection.ToIniValues(containerType); var delimiter2 = ""; foreach (var iniVal in iniVals) { result.Append(delimiter2); if (attr?.ListValueWithinBrackets ?? false) { result.Append($"({iniVal})"); } else { result.Append(iniVal); } delimiter2 = DELIMITER.ToString(); } } else { var collection = val as IIniValuesCollection; if (collection != null) { var iniVals = collection.ToIniValues(); var delimiter2 = ""; foreach (var iniVal in iniVals) { result.Append(delimiter2); if (attr?.ListValueWithinBrackets ?? false) { result.Append($"({iniVal})"); } else { result.Append(iniVal); } delimiter2 = DELIMITER.ToString(); } } else { var propValue = StringUtils.GetPropertyValue(val, prop); result.Append(propValue); } } if (attr?.ValueWithinBrackets ?? false) { result.Append(")"); } delimiter = DELIMITER.ToString(); } return(result.ToString()); }
public NPCSpawnContainerList(string aggregateValueName, NPCSpawnContainerType containerType) : base(aggregateValueName, null) { ContainerType = containerType; }