Skip to content

Commit

Permalink
Fix exception when no accessory gene template is found for object (#1621
Browse files Browse the repository at this point in the history
) #patch

Sentry event: 1fdcde106f2748f985c207620c48f9f7
  • Loading branch information
IhateTrains authored Dec 1, 2023
1 parent 392ff2e commit fd28052
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ImperatorToCK3/CK3/Characters/DNAFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,22 @@ AccessoryGene ck3Gene
return null;
}
var ck3GeneTemplate = ck3Gene.GeneTemplates
.First(t => t.AgeSexWeightBlocks[irCharacter.AgeSex].ContainsObject(convertedSetEntry));
.FirstOrDefault(t => t.AgeSexWeightBlocks[irCharacter.AgeSex].ContainsObject(convertedSetEntry));
if (ck3GeneTemplate is null) {
Logger.Warn($"No template found for {convertedSetEntry} in CK3 gene {ck3Gene.Id}!");
return null;
}
if (!objectMappings.TryGetValue(geneInfo.ObjectNameRecessive, out var convertedSetEntryRecessive)) {
Logger.Warn($"No object mappings found for {geneInfo.ObjectNameRecessive} in gene {irGeneName}!");
return null;
}
var ck3GeneTemplateRecessive = ck3Gene.GeneTemplates
.First(t => t.AgeSexWeightBlocks[irCharacter.AgeSex].ContainsObject(convertedSetEntryRecessive));

.FirstOrDefault(t => t.AgeSexWeightBlocks[irCharacter.AgeSex].ContainsObject(convertedSetEntryRecessive));
if (ck3GeneTemplateRecessive is null) {
Logger.Warn($"No template found for {convertedSetEntryRecessive} in CK3 gene {ck3Gene.Id}!");
return null;
}

var matchingPercentage = ck3GeneTemplate.AgeSexWeightBlocks[irCharacter.AgeSex]
.GetMatchingPercentage(convertedSetEntry);
var matchingPercentageRecessive = ck3GeneTemplateRecessive.AgeSexWeightBlocks[irCharacter.AgeSex]
Expand Down

0 comments on commit fd28052

Please sign in to comment.