2021-07-31 04:50:32 -07:00
|
|
|
using Content.Shared.Damage;
|
2023-08-01 02:10:05 -04:00
|
|
|
using Content.Shared.Damage.Prototypes;
|
2024-06-30 05:43:43 +02:00
|
|
|
using Content.Shared.EntityEffects;
|
2021-11-27 00:31:49 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2023-06-04 16:45:02 -04:00
|
|
|
using Content.Shared.Localizations;
|
2021-10-21 07:30:55 +11:00
|
|
|
using JetBrains.Annotations;
|
2023-06-04 16:45:02 -04:00
|
|
|
using Robust.Shared.Prototypes;
|
2023-12-29 04:47:43 -08:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.Json.Serialization;
|
2021-07-31 04:50:32 -07:00
|
|
|
|
2024-06-30 05:43:43 +02:00
|
|
|
namespace Content.Server.EntityEffects.Effects
|
2021-07-31 04:50:32 -07:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-06-30 05:43:43 +02:00
|
|
|
/// Default metabolism used for medicine reagents.
|
2021-07-31 04:50:32 -07:00
|
|
|
/// </summary>
|
2021-10-21 07:30:55 +11:00
|
|
|
[UsedImplicitly]
|
2024-06-30 05:43:43 +02:00
|
|
|
public sealed partial class HealthChange : EntityEffect
|
2021-07-31 04:50:32 -07:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-06-30 05:43:43 +02:00
|
|
|
/// Damage to apply every cycle. Damage Ignores resistances.
|
2021-07-31 04:50:32 -07:00
|
|
|
/// </summary>
|
2023-12-29 04:47:43 -08:00
|
|
|
[DataField(required: true)]
|
2022-01-18 16:44:22 -05:00
|
|
|
[JsonPropertyName("damage")]
|
2021-09-15 03:07:37 +10:00
|
|
|
public DamageSpecifier Damage = default!;
|
2021-07-31 04:50:32 -07:00
|
|
|
|
2021-11-27 00:31:49 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Should this effect scale the damage by the amount of chemical in the solution?
|
|
|
|
|
/// Useful for touch reactions, like styptic powder or acid.
|
2024-06-30 05:43:43 +02:00
|
|
|
/// Only usable if the EntityEffectBaseArgs is an EntityEffectReagentArgs.
|
2021-11-27 00:31:49 -07:00
|
|
|
/// </summary>
|
2023-12-29 04:47:43 -08:00
|
|
|
[DataField]
|
2022-01-18 16:44:22 -05:00
|
|
|
[JsonPropertyName("scaleByQuantity")]
|
2023-08-01 02:10:05 -04:00
|
|
|
public bool ScaleByQuantity;
|
2021-11-27 00:31:49 -07:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
[DataField]
|
2022-01-18 16:44:22 -05:00
|
|
|
[JsonPropertyName("ignoreResistances")]
|
2021-11-27 00:31:49 -07:00
|
|
|
public bool IgnoreResistances = true;
|
|
|
|
|
|
2023-08-01 02:10:05 -04:00
|
|
|
protected override string ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
|
2023-06-04 16:45:02 -04:00
|
|
|
{
|
|
|
|
|
var damages = new List<string>();
|
|
|
|
|
var heals = false;
|
|
|
|
|
var deals = false;
|
|
|
|
|
|
2023-08-01 02:10:05 -04:00
|
|
|
var damageSpec = new DamageSpecifier(Damage);
|
|
|
|
|
|
|
|
|
|
foreach (var group in prototype.EnumeratePrototypes<DamageGroupPrototype>())
|
|
|
|
|
{
|
|
|
|
|
if (!damageSpec.TryGetDamageInGroup(group, out var amount))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var relevantTypes = damageSpec.DamageDict
|
|
|
|
|
.Where(x => x.Value != FixedPoint2.Zero && group.DamageTypes.Contains(x.Key)).ToList();
|
|
|
|
|
|
|
|
|
|
if (relevantTypes.Count != group.DamageTypes.Count)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var sum = FixedPoint2.Zero;
|
|
|
|
|
foreach (var type in group.DamageTypes)
|
|
|
|
|
{
|
|
|
|
|
sum += damageSpec.DamageDict.GetValueOrDefault(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the total sum of all the types equal the damage amount,
|
|
|
|
|
// assume that they're evenly distributed.
|
|
|
|
|
if (sum != amount)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var sign = FixedPoint2.Sign(amount);
|
|
|
|
|
|
|
|
|
|
if (sign < 0)
|
|
|
|
|
heals = true;
|
|
|
|
|
if (sign > 0)
|
|
|
|
|
deals = true;
|
|
|
|
|
|
|
|
|
|
damages.Add(
|
|
|
|
|
Loc.GetString("health-change-display",
|
2024-04-28 07:48:19 +03:00
|
|
|
("kind", group.LocalizedName),
|
2023-08-01 02:10:05 -04:00
|
|
|
("amount", MathF.Abs(amount.Float())),
|
|
|
|
|
("deltasign", sign)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
foreach (var type in group.DamageTypes)
|
|
|
|
|
{
|
|
|
|
|
damageSpec.DamageDict.Remove(type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var (kind, amount) in damageSpec.DamageDict)
|
2023-06-04 16:45:02 -04:00
|
|
|
{
|
2023-08-01 02:10:05 -04:00
|
|
|
var sign = FixedPoint2.Sign(amount);
|
2023-06-04 16:45:02 -04:00
|
|
|
|
|
|
|
|
if (sign < 0)
|
|
|
|
|
heals = true;
|
|
|
|
|
if (sign > 0)
|
|
|
|
|
deals = true;
|
|
|
|
|
|
|
|
|
|
damages.Add(
|
|
|
|
|
Loc.GetString("health-change-display",
|
2024-04-28 07:48:19 +03:00
|
|
|
("kind", prototype.Index<DamageTypePrototype>(kind).LocalizedName),
|
2023-06-04 16:45:02 -04:00
|
|
|
("amount", MathF.Abs(amount.Float())),
|
|
|
|
|
("deltasign", sign)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var healsordeals = heals ? (deals ? "both" : "heals") : (deals ? "deals" : "none");
|
|
|
|
|
|
|
|
|
|
return Loc.GetString("reagent-effect-guidebook-health-change",
|
|
|
|
|
("chance", Probability),
|
|
|
|
|
("changes", ContentLocalizationManager.FormatList(damages)),
|
|
|
|
|
("healsordeals", healsordeals));
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 05:43:43 +02:00
|
|
|
public override void Effect(EntityEffectBaseArgs args)
|
2021-07-31 04:50:32 -07:00
|
|
|
{
|
2024-06-30 05:43:43 +02:00
|
|
|
var scale = FixedPoint2.New(1);
|
|
|
|
|
|
|
|
|
|
if (args is EntityEffectReagentArgs reagentArgs)
|
|
|
|
|
{
|
|
|
|
|
scale = ScaleByQuantity ? reagentArgs.Quantity * reagentArgs.Scale : reagentArgs.Scale;
|
|
|
|
|
}
|
2022-12-21 09:51:49 -05:00
|
|
|
|
2024-01-28 00:51:54 +01:00
|
|
|
args.EntityManager.System<DamageableSystem>().TryChangeDamage(
|
2024-06-30 05:43:43 +02:00
|
|
|
args.TargetEntity,
|
2024-01-28 00:51:54 +01:00
|
|
|
Damage * scale,
|
|
|
|
|
IgnoreResistances,
|
|
|
|
|
interruptsDoAfters: false);
|
2021-07-31 04:50:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|