Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Items/Components/Wearable.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
5 
7 {
8  partial class Wearable : Pickable, IServerSerializable
9  {
10  private static void GetDamageModifierText(ref LocalizedString description, DamageModifier damageModifier, Identifier afflictionIdentifier)
11  {
12  int roundedValue = (int)Math.Round((1 - Math.Min(damageModifier.DamageMultiplier, damageModifier.ProbabilityMultiplier)) * 100);
13  if (roundedValue == 0) { return; }
14  string colorStr = XMLExtensions.ToStringHex(GUIStyle.Green);
15 
16  LocalizedString afflictionName =
17  AfflictionPrefab.List.FirstOrDefault(ap => ap.Identifier == afflictionIdentifier)?.Name ??
18  TextManager.Get($"afflictiontype.{afflictionIdentifier}").Fallback(afflictionIdentifier.Value);
19 
20  if (!description.IsNullOrWhiteSpace()) { description += '\n'; }
21  description += $" ‖color:{colorStr}‖{roundedValue:-0;+#}%‖color:end‖ {afflictionName}";
22  }
23 
24  public override void AddTooltipInfo(ref LocalizedString name, ref LocalizedString description)
25  {
26  AddTooltipInfo(damageModifiers, SkillModifiers, ref description);
27  }
28 
29  public static void AddTooltipInfo(IReadOnlyList<DamageModifier> damageModifiers, IReadOnlyDictionary<Identifier, float> skillModifiers, ref LocalizedString description)
30  {
31  if (damageModifiers.Any())
32  {
33  foreach (DamageModifier damageModifier in damageModifiers)
34  {
35  if (MathUtils.NearlyEqual(damageModifier.DamageMultiplier * damageModifier.ProbabilityMultiplier, 1f))
36  {
37  continue;
38  }
39  foreach (Identifier afflictionIdentifier in damageModifier.ParsedAfflictionIdentifiers)
40  {
41  GetDamageModifierText(ref description, damageModifier, afflictionIdentifier);
42  }
43  foreach (Identifier afflictionType in damageModifier.ParsedAfflictionTypes)
44  {
45  GetDamageModifierText(ref description, damageModifier, afflictionType);
46  }
47  }
48  }
49  if (skillModifiers.Any())
50  {
51  foreach (var skillModifier in skillModifiers)
52  {
53  string colorStr = XMLExtensions.ToStringHex(GUIStyle.Green);
54  int roundedValue = (int)Math.Round(skillModifier.Value);
55  if (roundedValue == 0) { continue; }
56  if (!description.IsNullOrWhiteSpace()) { description += '\n'; }
57  description += $" ‖color:{colorStr}‖{roundedValue.ToString("+0;-#")}‖color:end‖ {TextManager.Get($"SkillName.{skillModifier.Key}").Fallback(skillModifier.Key.Value)}";
58  }
59  }
60  }
61  }
62 }
ref readonly ImmutableArray< Identifier > ParsedAfflictionIdentifiers
override void AddTooltipInfo(ref LocalizedString name, ref LocalizedString description)
static void AddTooltipInfo(IReadOnlyList< DamageModifier > damageModifiers, IReadOnlyDictionary< Identifier, float > skillModifiers, ref LocalizedString description)
Interface for entities that the server can send events to the clients