Files
tbd-station-14/Content.Server/Chemistry/ReagentEffects/HealthChange.cs
TemporalOroboros d75e743dd7 Solution Entities (#21916)
* Creates Content.Shared.Chemistry.Solutions
Copies Solution class to new namespace
Obsoletes old Solution class

* Switches over to the Solutions.Solution Solution

* Creates Content.Shared.Chemistry.Containers
Copies relevant components/systems to the new namespace
Obsoletes old versions

* Switches over to the Containers.XYZ namespace

* Creates SolutionSystem and obsoletes old SolutionContainerSystem methods

* Start using SolutionSystem for Solution manipulation

* EnumerateSolutions

* Move TryGetMixableSolution

* Move EnsureSolution to Server

* Create Solution Entities

* Stop using obsolete solution system methods

* Fix prototype component tests

* Add using ..Audio.Systems; back

* Wrap solution container slots in ContainerSlots

* Actually add the slot to the solution container map

* Dirty SolutionContainerComponent when ensuring solutions

* Revert namespace changes

* Remerge SolutionSystem and SolutionContainerSystem

* SolutionContainerManagerComponent refactor

* Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release

* Readd examine reagent sorting

* Fix errors

* Poke tests

* Fix solution names not being applied

* Fix WoolyComponent including statement

* Fix merge skew

* Fix compile errors

* Make reactions use solntities

* Reindent solution class namespace

* Field attribute changes

* AutoGenerateComponentState for SolutionContainerComponent

* SolutionContainerComponent -> ContainedSolutionComponent

* ref ReactionAttemptEvent

* Denetwork preinit solutions

* Misc 1

* Nullable TryGetSolution out vars

* Cache associated solutions

* Fix merge skew

* Use explicit regions in SharedSolutionContainerSystem.Capabilities

* Add debug assert

* Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent

* ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName

* SolutionComponent doc comments

* Implicit DataField names and property purge

* ReagentEffect DataField names

* Local variables for readability

* Sort using statements + Entity<T> event handlers

* Fix compile erros

* Fix compile errors

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2023-12-28 17:58:14 -08:00

122 lines
4.1 KiB
C#

using Content.Shared.Chemistry.Reagent;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Localizations;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using System.Linq;
using System.Text.Json.Serialization;
namespace Content.Server.Chemistry.ReagentEffects
{
/// <summary>
/// Default metabolism for medicine reagents.
/// </summary>
[UsedImplicitly]
public sealed partial class HealthChange : ReagentEffect
{
/// <summary>
/// Damage to apply every metabolism cycle. Damage Ignores resistances.
/// </summary>
[DataField(required: true)]
[JsonPropertyName("damage")]
public DamageSpecifier Damage = default!;
/// <summary>
/// Should this effect scale the damage by the amount of chemical in the solution?
/// Useful for touch reactions, like styptic powder or acid.
/// </summary>
[DataField]
[JsonPropertyName("scaleByQuantity")]
public bool ScaleByQuantity;
[DataField]
[JsonPropertyName("ignoreResistances")]
public bool IgnoreResistances = true;
protected override string ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
{
var damages = new List<string>();
var heals = false;
var deals = false;
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",
("kind", group.ID),
("amount", MathF.Abs(amount.Float())),
("deltasign", sign)
));
foreach (var type in group.DamageTypes)
{
damageSpec.DamageDict.Remove(type);
}
}
foreach (var (kind, amount) in damageSpec.DamageDict)
{
var sign = FixedPoint2.Sign(amount);
if (sign < 0)
heals = true;
if (sign > 0)
deals = true;
damages.Add(
Loc.GetString("health-change-display",
("kind", kind),
("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));
}
public override void Effect(ReagentEffectArgs args)
{
var scale = ScaleByQuantity ? args.Quantity : FixedPoint2.New(1);
scale *= args.Scale;
args.EntityManager.System<DamageableSystem>().TryChangeDamage(args.SolutionEntity, Damage * scale, IgnoreResistances);
}
}
}