diff --git a/ARKBreedingStats/Form1.extractor.cs b/ARKBreedingStats/Form1.extractor.cs index 65811636..42ef00fa 100644 --- a/ARKBreedingStats/Form1.extractor.cs +++ b/ARKBreedingStats/Form1.extractor.cs @@ -988,8 +988,7 @@ private bool IsCreatureAlreadyInLibrary(Guid creatureGuid, long arkId, out Creat { existingCreature = null; bool creatureAlreadyExistsInLibrary = false; - if (creatureGuid != Guid.Empty - && Utils.IsArkIdImported(arkId, creatureGuid)) + if (creatureGuid != Guid.Empty && Utils.IsArkIdImported(arkId, creatureGuid)) { existingCreature = _creatureCollection.creatures.FirstOrDefault(c => c.guid == creatureGuid && !c.flags.HasFlag(CreatureFlags.Placeholder) diff --git a/ARKBreedingStats/Form1.library.cs b/ARKBreedingStats/Form1.library.cs index 3d44b6d8..356e3382 100644 --- a/ARKBreedingStats/Form1.library.cs +++ b/ARKBreedingStats/Form1.library.cs @@ -535,21 +535,64 @@ private void UpdateParents(IEnumerable creatures) { List placeholderAncestors = new List(); - var creatureGuids = _creatureCollection.creatures.ToDictionary(c => c.guid); + + Dictionary creatureGuids; + + try + { + creatureGuids = _creatureCollection.creatures.ToDictionary(c => c.guid); + } + catch (ArgumentException) + { + // assuming there are somehow multiple creatures with the same guid + // if it's only placeholders, remove the duplicates + var guidGroups = _creatureCollection.creatures.GroupBy(c => c.guid); + var uniqueList = new List(); + + foreach (var g in guidGroups) + { + if (g.Count() == 1) + { + uniqueList.Add(g.First()); + continue; + } + // if only one creature is not a placeholder, use that + var nonPlaceholders = g.Where(c => !c.flags.HasFlag(CreatureFlags.Placeholder)).ToArray(); + if (nonPlaceholders.Length == 1) + { + uniqueList.Add(nonPlaceholders.First()); + continue; + } + + if (nonPlaceholders.Length == 0) + { + // just take the first placeholder + uniqueList.Add(g.First()); + continue; + } + + // there are more than 1 non-placeholder with the same guid. That's bad. + throw; + } + + _creatureCollection.creatures = uniqueList; + + creatureGuids = _creatureCollection.creatures.ToDictionary(c => c.guid); + } foreach (Creature c in creatures) { if (c.motherGuid == Guid.Empty && c.fatherGuid == Guid.Empty) continue; Creature mother = null; - if (c.motherGuid == Guid.Empty - || !creatureGuids.TryGetValue(c.motherGuid, out mother)) - mother = EnsurePlaceholderCreature(placeholderAncestors, c, c.motherArkId, c.motherGuid, c.motherName, Sex.Female); + if (c.motherGuid != Guid.Empty + && !creatureGuids.TryGetValue(c.motherGuid, out mother)) + mother = EnsurePlaceholderCreature(placeholderAncestors, c, c.motherGuid, c.motherName, Sex.Female); Creature father = null; - if (c.fatherGuid == Guid.Empty - || !creatureGuids.TryGetValue(c.fatherGuid, out father)) - father = EnsurePlaceholderCreature(placeholderAncestors, c, c.fatherArkId, c.fatherGuid, c.fatherName, Sex.Male); + if (c.fatherGuid != Guid.Empty + && !creatureGuids.TryGetValue(c.fatherGuid, out father)) + father = EnsurePlaceholderCreature(placeholderAncestors, c, c.fatherGuid, c.fatherName, Sex.Male); c.Mother = mother; c.Father = father; @@ -564,14 +607,13 @@ private void UpdateParents(IEnumerable creatures) /// /// List of placeholders to amend /// Descendant creature to use as a template - /// ArkId of creature to create. Only pass this if it's from an import /// GUID of creature to create /// Name of the creature to create /// Sex of the creature to create /// - private Creature EnsurePlaceholderCreature(List placeholders, Creature tmpl, long arkId, Guid guid, string name, Sex sex) + private Creature EnsurePlaceholderCreature(List placeholders, Creature tmpl, Guid guid, string name, Sex sex) { - if (guid == Guid.Empty && arkId == 0) + if (guid == Guid.Empty) return null; var existing = placeholders.SingleOrDefault(ph => ph.guid == guid); if (existing != null) @@ -580,15 +622,12 @@ private Creature EnsurePlaceholderCreature(List placeholders, Creature if (string.IsNullOrEmpty(name)) name = (sex == Sex.Female ? "Mother" : "Father") + " of " + tmpl.name; - Guid creatureGuid = arkId != 0 ? Utils.ConvertArkIdToGuid(arkId) : guid; var creature = new Creature(tmpl.Species, name, tmpl.owner, tmpl.tribe, sex, new[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, levelStep: _creatureCollection.getWildLevelStep()) { - guid = creatureGuid, + guid = guid, Status = CreatureStatus.Unavailable, - flags = CreatureFlags.Placeholder, - ArkId = arkId, - ArkIdImported = Utils.IsArkIdImported(arkId, creatureGuid) + flags = CreatureFlags.Placeholder }; placeholders.Add(creature); diff --git a/ARKBreedingStats/library/Creature.cs b/ARKBreedingStats/library/Creature.cs index 4d976840..7df3b73f 100644 --- a/ARKBreedingStats/library/Creature.cs +++ b/ARKBreedingStats/library/Creature.cs @@ -98,14 +98,6 @@ public class Creature : IEquatable [JsonProperty] public Guid motherGuid; /// - /// Only set if the id is imported. - /// - public long motherArkId; - /// - /// Only set if the id is imported. - /// - public long fatherArkId; - /// /// Only used during import to create placeholder ancestors. /// public string fatherName;