private static void FormatChance(String ownerId, HasSkillNode skillNode, DialogChanceRepresentation displayChanceMode, out Color color, ref String suffix) { Single playerValue = Game.World.Player.CharacterComponent.Character.Stats.GetSkill(skillNode.skill); Int32 requiredValue = skillNode.value; Int32 inaccuracy = Configuration.Dialog.DisplayChanceAbsoluteInaccuracy + Configuration.Dialog.DisplayChanceRelativeInaccuracy * requiredValue / 100; // Randomize requiredValue += PersistentRandom.Get(ownerId, -inaccuracy / 2, inaccuracy / 2 + 1); Int32 minValue = requiredValue - inaccuracy; Int32 maxValue = requiredValue + inaccuracy; Single probability = Mathf.Clamp((playerValue - minValue) / (maxValue - minValue), 0, 1); color = probability < 0.5 ? new Color(1.0f, probability / 0.5f, 0.0f) : new Color(1.0f - (probability - 0.5f) / 0.75f, 1.0f, 0.0f); if (displayChanceMode == DialogChanceRepresentation.Percent) { Int32 percent = (Int32)(probability * 100); suffix = $" {percent}%{ColorTagEnd}"; } }
public static void TryReplaceText(StateNode stateNode, ref String result) { DialogChanceRepresentation mode = Configuration.Dialog.DisplayChanceSuccess; if (mode == DialogChanceRepresentation.DoNotDisplay) { return; } var skillNode = GetSkillNodes(stateNode).FirstOrDefault(); if (skillNode is null) { return; } String ownerId = $"{stateNode.GetType().FullName}: {stateNode.gameObject.GetInstanceID()}"; String text = GameUtils.ToStyleText(result); Int32 colorIndexBegin = text.IndexOf(ColorTagBegin, StringComparison.Ordinal); if (colorIndexBegin < 0) { Debug.LogWarning($"[{nameof(NuclearEdition)}] {nameof(EncounterAnswerNode_Prepare)}: Failed to process answer: {text}"); return; } var sb = new StringBuilder(text); Color color; String suffix = ColorTagEnd; if (mode == DialogChanceRepresentation.Value) { FormatValue(skillNode, out color, out suffix); } else if (mode == DialogChanceRepresentation.Segments) { FormatSegments(skillNode, out color); } else { FormatChance(ownerId, skillNode, mode, out color, ref suffix); } // Replace color Byte r = (Byte)(color.r * 255); Byte g = (Byte)(color.g * 255); Byte b = (Byte)(color.b * 255); Byte a = (Byte)(color.a * 255); String colorText = $"<b><color=#{r:x2}{g:x2}{b:x2}{a:x2}>["; sb.Replace(ColorTagBegin, colorText, colorIndexBegin, ColorTagBegin.Length); // Add sufix if (suffix != ColorTagEnd) { Int32 endColorIndex = text.IndexOf(ColorTagEnd, colorIndexBegin, StringComparison.Ordinal); if (endColorIndex < 0) { Debug.LogWarning($"[{nameof(NuclearEdition)}] {nameof(EncounterAnswerNode_Prepare)}: Failed to process answer: {text}"); return; } sb.Replace(ColorTagEnd, suffix, endColorIndex, ColorTagEnd.Length); } result = sb.ToString(); }