2024-11-06 08:44:03 +03:00
|
|
|
|
|
|
|
|
using Content.Shared._CP14.MagicRitual.Prototypes;
|
|
|
|
|
using Content.Shared._CP14.MagicSpell.Events;
|
|
|
|
|
using Content.Shared.Examine;
|
2025-05-14 12:43:43 +03:00
|
|
|
using Content.Shared.FixedPoint;
|
2024-11-06 08:44:03 +03:00
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
using Content.Shared.Verbs;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
2024-11-06 18:02:37 +03:00
|
|
|
namespace Content.Shared._CP14.MagicManacostModify;
|
2024-11-06 08:44:03 +03:00
|
|
|
|
2024-11-06 18:02:37 +03:00
|
|
|
public sealed partial class CP14MagicManacostModifySystem : EntitySystem
|
2024-11-06 08:44:03 +03:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly ExamineSystemShared _examine = default!;
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2024-11-06 18:02:37 +03:00
|
|
|
SubscribeLocalEvent<CP14MagicManacostModifyComponent, InventoryRelayedEvent<CP14CalculateManacostEvent>>(OnCalculateManacost);
|
|
|
|
|
SubscribeLocalEvent<CP14MagicManacostModifyComponent, CP14CalculateManacostEvent>(OnCalculateManacost);
|
|
|
|
|
SubscribeLocalEvent<CP14MagicManacostModifyComponent, GetVerbsEvent<ExamineVerb>>(OnVerbExamine);
|
2024-11-06 08:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
2024-11-06 18:02:37 +03:00
|
|
|
private void OnVerbExamine(Entity<CP14MagicManacostModifyComponent> ent, ref GetVerbsEvent<ExamineVerb> args)
|
2024-11-06 08:44:03 +03:00
|
|
|
{
|
2025-05-14 12:43:43 +03:00
|
|
|
if (!args.CanInteract || !args.CanAccess || !ent.Comp.Examinable)
|
2024-11-06 08:44:03 +03:00
|
|
|
return;
|
|
|
|
|
|
2025-05-14 12:43:43 +03:00
|
|
|
var markup = GetManacostModifyMessage(ent.Comp.GlobalModifier, ent.Comp.Modifiers);
|
2024-11-06 08:44:03 +03:00
|
|
|
_examine.AddDetailedExamineVerb(
|
|
|
|
|
args,
|
|
|
|
|
ent.Comp,
|
|
|
|
|
markup,
|
2025-03-11 10:23:09 +03:00
|
|
|
Loc.GetString("cp14-magic-examinable-verb-text"),
|
|
|
|
|
"/Textures/Interface/VerbIcons/bubbles.svg.192dpi.png",
|
|
|
|
|
Loc.GetString("cp14-magic-examinable-verb-message"));
|
2024-11-06 08:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-14 12:43:43 +03:00
|
|
|
public FormattedMessage GetManacostModifyMessage(FixedPoint2 global, Dictionary<ProtoId<CP14MagicTypePrototype>, FixedPoint2> modifiers)
|
2024-11-06 08:44:03 +03:00
|
|
|
{
|
|
|
|
|
var msg = new FormattedMessage();
|
|
|
|
|
msg.AddMarkupOrThrow(Loc.GetString("cp14-clothing-magic-examine"));
|
|
|
|
|
|
2025-05-14 12:43:43 +03:00
|
|
|
if (global != 1)
|
2024-11-06 08:44:03 +03:00
|
|
|
{
|
|
|
|
|
msg.PushNewline();
|
|
|
|
|
|
2025-05-14 12:43:43 +03:00
|
|
|
var plus = (float)global > 1 ? "+" : "";
|
2025-03-07 17:14:29 +03:00
|
|
|
msg.AddMarkupOrThrow(
|
2025-05-14 12:43:43 +03:00
|
|
|
$"{Loc.GetString("cp14-clothing-magic-global")}: {plus}{MathF.Round((float)(global - 1) * 100, MidpointRounding.AwayFromZero)}%");
|
2024-11-06 08:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-14 12:43:43 +03:00
|
|
|
foreach (var modifier in modifiers)
|
2024-11-06 08:44:03 +03:00
|
|
|
{
|
|
|
|
|
if (modifier.Value == 1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
msg.PushNewline();
|
|
|
|
|
|
|
|
|
|
var plus = modifier.Value > 1 ? "+" : "";
|
|
|
|
|
var indexedType = _proto.Index(modifier.Key);
|
2025-03-11 10:23:09 +03:00
|
|
|
msg.AddMarkupOrThrow($"- [color={indexedType.Color.ToHex()}]{Loc.GetString(indexedType.Name)}[/color]: {plus}{(modifier.Value - 1)*100}%");
|
2024-11-06 08:44:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-06 18:02:37 +03:00
|
|
|
private void OnCalculateManacost(Entity<CP14MagicManacostModifyComponent> ent, ref InventoryRelayedEvent<CP14CalculateManacostEvent> args)
|
2024-11-06 08:44:03 +03:00
|
|
|
{
|
2024-11-06 18:02:37 +03:00
|
|
|
OnCalculateManacost(ent, ref args.Args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCalculateManacost(Entity<CP14MagicManacostModifyComponent> ent, ref CP14CalculateManacostEvent args)
|
|
|
|
|
{
|
2024-11-07 16:04:49 +03:00
|
|
|
args.Multiplier *= (float)ent.Comp.GlobalModifier;
|
2024-11-06 08:44:03 +03:00
|
|
|
|
2024-11-06 18:02:37 +03:00
|
|
|
if (args.MagicType is not null && ent.Comp.Modifiers.TryGetValue(args.MagicType.Value, out var modifier))
|
2024-11-06 08:44:03 +03:00
|
|
|
{
|
2024-11-06 18:02:37 +03:00
|
|
|
args.Multiplier *= (float)modifier;
|
2024-11-06 08:44:03 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|