private static float CalculateChance(SaveData.Heroine heroine, int question, int answer, int memoryWeight, int relationshipWeight = 0, int intelligenceWeight = 0, float bonus = 0f) { var total = 0f; var sum = 0f; if (memoryWeight > 0) { // let memory give you up to 150% var memoryPercentage = Mathf.Clamp(heroine.CurrentRecallChance(question, answer), 0f, 1.5f); Logger?.DebugLogDebug($"{answer} memory: {memoryPercentage:P} {memoryWeight}"); total += memoryWeight; sum += memoryPercentage * memoryWeight; } if (relationshipWeight > 0) { var relationshipMax = 0; var relationshipSum = 0f; var relationshipPercentage = 0f; void AccumRelationship(int value, int max, int weight) { var entry = Mathf.Clamp(value / (float)max, 0f, 1f); relationshipMax += weight; relationshipSum += weight * entry; } // relation could be -1 if you've never met before if (heroine.relation >= 0) { AccumRelationship(heroine.relation, 2, RelationWeight); AccumRelationship(heroine.favor, 100, FavorWeight); AccumRelationship(heroine.intimacy, 100, IntimacyWeight); relationshipPercentage = relationshipSum / relationshipMax; // first girl bonus if (heroine.isFirstGirlfriend) { relationshipPercentage *= FirstGirlfriendBonusScale; } relationshipPercentage = Mathf.Clamp(relationshipPercentage, 0f, 1f); } Logger?.DebugLogDebug( $"{answer} relationship: {relationshipPercentage:P} {relationshipWeight} ({relationshipSum}/{relationshipMax})"); total += relationshipWeight; sum += relationshipPercentage * relationshipWeight; } if (intelligenceWeight > 0) { var intelligencePercentage = Mathf.Clamp(Game.Instance.Player.intellect / 100f, 0f, 1f); Logger?.DebugLogDebug( $"{answer} intelligence: {intelligencePercentage:P} {intelligenceWeight}"); total += intelligenceWeight; sum += intelligencePercentage * intelligenceWeight; } var result = Mathf.Clamp((sum / total) + bonus, 0f, MaxPercentChance); Logger?.DebugLogDebug($"CalculateChance => {result:P}"); return(result); }