Files
tbd-station-14/Content.Shared/EntityEffects/Effects/EvenHealthChangeEntityEffectSystem.cs
Princess Cheeseballs 4059c29ebc Entity effects ECS refactor (#40580)
* LOCKED THE FUCK IN

* Forgot this little fella

* Crying

* All entity effects ported, needs cleanup still

* Commit

* HEHEHEHAW

* Shelve for now

* fixe

* Big

* First big chunk of changes

* Big if true

* Commit

* IT BUILDS!!!

* Fix LINTER fails

* Cleanup

* Scale working, cut down on some evil code

* Delete old Entity Effects

* Accidentally breaking shit by fixing bugs

* Fix a bunch of effects not working

* Fix reagent thresholds

* Update damage

* Wait don't change the gas metabolisms A

* Cleanup

* more fixes

* Eh

* Misc fixes and jank

* Remove two things, add bullshit, change condition to inverted

* Remove unused "Shared" system structure

* Namespace fix

* merge conflicts/cleanup

* More fixes

* Guidebook text begins

* Shelve

* Push

* More shit to push

* Fix

* Fix merg conflicts

* BLOOD FOR THE BLOOD GOD!!!

* Mild cleanup and lists

* Fix localization and comments

* Shuffle localization around a bit.

* All done?

* Nearly everything

* Is this the end?

* Whoops forgot to remove that TODO

* Get rid of some warnings for good measure...

* It's done

* Should make those virtual in case we want to override them tbqh...

* Update Content.Shared/EntityEffects/Effects/Botany/PlantAttributes/PlantDestroySeeds.cs

Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>

* Fix test fails real

* Add to codeowners

* Documentation to everything

* Forgot to push whoops

* Standardize Condition names

* Fix up metabolism a little as a treat

* review

* add IsServer checks

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>
2025-10-12 21:23:42 +00:00

115 lines
4.0 KiB
C#

using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Localizations;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.EntityEffects.Effects;
/// <summary>
/// Evenly adjust the damage types in a damage group by up to a specified total on this entity.
/// Total adjustment is modified by scale.
/// </summary>
/// <inheritdoc cref="EntityEffectSystem{T,TEffect}"/>
public sealed partial class EvenHealthChangeEntityEffectSystem : EntityEffectSystem<DamageableComponent, EvenHealthChange>
{
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
protected override void Effect(Entity<DamageableComponent> entity, ref EntityEffectEvent<EvenHealthChange> args)
{
var damageSpec = new DamageSpecifier();
foreach (var (group, amount) in args.Effect.Damage)
{
var groupProto = _proto.Index(group);
var groupDamage = new Dictionary<string, FixedPoint2>();
foreach (var damageId in groupProto.DamageTypes)
{
var damageAmount = entity.Comp.Damage.DamageDict.GetValueOrDefault(damageId);
if (damageAmount != FixedPoint2.Zero)
groupDamage.Add(damageId, damageAmount);
}
var sum = groupDamage.Values.Sum();
foreach (var (damageId, damageAmount) in groupDamage)
{
var existing = damageSpec.DamageDict.GetOrNew(damageId);
damageSpec.DamageDict[damageId] = existing + damageAmount / sum * amount;
}
}
damageSpec *= args.Scale;
_damageable.TryChangeDamage(
entity,
damageSpec,
args.Effect.IgnoreResistances,
interruptsDoAfters: false,
damageable: entity.Comp);
}
}
/// <inheritdoc cref="EntityEffect"/>
public sealed partial class EvenHealthChange : EntityEffectBase<EvenHealthChange>
{
/// <summary>
/// Damage to heal, collected into entire damage groups.
/// </summary>
[DataField(required: true)]
public Dictionary<ProtoId<DamageGroupPrototype>, FixedPoint2> Damage = new();
/// <summary>
/// Should this effect ignore damage modifiers?
/// </summary>
[DataField]
public bool IgnoreResistances = true;
public override string EntityEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
{
var damages = new List<string>();
var heals = false;
var deals = false;
var damagableSystem = entSys.GetEntitySystem<DamageableSystem>();
var universalReagentDamageModifier = damagableSystem.UniversalReagentDamageModifier;
var universalReagentHealModifier = damagableSystem.UniversalReagentHealModifier;
foreach (var (group, amount) in Damage)
{
var groupProto = prototype.Index(group);
var sign = FixedPoint2.Sign(amount);
float mod;
switch (sign)
{
case < 0:
heals = true;
mod = universalReagentHealModifier;
break;
case > 0:
deals = true;
mod = universalReagentDamageModifier;
break;
default:
continue; // Don't need to show damage types of 0...
}
damages.Add(
Loc.GetString("health-change-display",
("kind", groupProto.LocalizedName),
("amount", MathF.Abs(amount.Float() * mod)),
("deltasign", sign)
));
}
var healsordeals = heals ? deals ? "both" : "heals" : deals ? "deals" : "none";
return Loc.GetString("entity-effect-guidebook-even-health-change",
("chance", Probability),
("changes", ContentLocalizationManager.FormatList(damages)),
("healsordeals", healsordeals));
}
}