mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-30 08:07:28 +00:00
* pt1 damageable refactor * fixes * thusd unused * sparse damagespecifiers * fix thongs * aaaaaa * fix tests * de-crash
97 lines
4.4 KiB
C#
97 lines
4.4 KiB
C#
using System.Linq;
|
|
using Content.Shared.Chemistry;
|
|
using Content.Shared.Damage.Components;
|
|
using Content.Shared.Damage.Prototypes;
|
|
using Content.Shared.Explosion.EntitySystems;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Damage.Systems;
|
|
|
|
public sealed partial class DamageableSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
|
|
[Dependency] private readonly IConfigurationManager _config = default!;
|
|
[Dependency] private readonly SharedChemistryGuideDataSystem _chemistryGuideData = default!;
|
|
[Dependency] private readonly SharedExplosionSystem _explosion = default!;
|
|
|
|
private EntityQuery<AppearanceComponent> _appearanceQuery;
|
|
private EntityQuery<DamageableComponent> _damageableQuery;
|
|
|
|
public float UniversalAllDamageModifier { get; private set; } = 1f;
|
|
public float UniversalAllHealModifier { get; private set; } = 1f;
|
|
public float UniversalMeleeDamageModifier { get; private set; } = 1f;
|
|
public float UniversalProjectileDamageModifier { get; private set; } = 1f;
|
|
public float UniversalHitscanDamageModifier { get; private set; } = 1f;
|
|
public float UniversalReagentDamageModifier { get; private set; } = 1f;
|
|
public float UniversalReagentHealModifier { get; private set; } = 1f;
|
|
public float UniversalExplosionDamageModifier { get; private set; } = 1f;
|
|
public float UniversalThrownDamageModifier { get; private set; } = 1f;
|
|
public float UniversalTopicalsHealModifier { get; private set; } = 1f;
|
|
public float UniversalMobDamageModifier { get; private set; } = 1f;
|
|
|
|
private Dictionary<ProtoId<DamageContainerPrototype>, HashSet<ProtoId<DamageTypePrototype>>> _supportedTypesByContainer = new();
|
|
|
|
/// <summary>
|
|
/// If the damage in a DamageableComponent was changed this function should be called.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This updates cached damage information, flags the component as dirty, and raises a damage changed event.
|
|
/// The damage changed event is used by other systems, such as damage thresholds.
|
|
/// </remarks>
|
|
private void OnEntityDamageChanged(
|
|
Entity<DamageableComponent> ent,
|
|
DamageSpecifier? damageDelta = null,
|
|
bool interruptsDoAfters = true,
|
|
EntityUid? origin = null
|
|
)
|
|
{
|
|
ent.Comp.Damage.GetDamagePerGroup(_prototypeManager, ent.Comp.DamagePerGroup);
|
|
ent.Comp.TotalDamage = ent.Comp.Damage.GetTotal();
|
|
Dirty(ent);
|
|
|
|
if (damageDelta != null && _appearanceQuery.TryGetComponent(ent, out var appearance))
|
|
{
|
|
_appearance.SetData(
|
|
ent,
|
|
DamageVisualizerKeys.DamageUpdateGroups,
|
|
new DamageVisualizerGroupData(ent.Comp.DamagePerGroup.Keys.ToList()),
|
|
appearance
|
|
);
|
|
}
|
|
|
|
// TODO DAMAGE
|
|
// byref struct event.
|
|
RaiseLocalEvent(ent, new DamageChangedEvent(ent.Comp, damageDelta, interruptsDoAfters, origin));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Goes through an entity damage's and saves them inside a dictionary if the value is higher than 0
|
|
/// The dictionary is structured with a string for the name of the damage type, and a FixedPoint2 for the numeric damage value
|
|
/// </summary>
|
|
public Dictionary<ProtoId<DamageTypePrototype>, FixedPoint2> GetDamages(Dictionary<ProtoId<DamageGroupPrototype>, FixedPoint2> damagePerGroup, DamageSpecifier damage)
|
|
{
|
|
var damageTypes = new Dictionary<ProtoId<DamageTypePrototype>, FixedPoint2>();
|
|
|
|
foreach (var (damageGroupId, _) in damagePerGroup) //go through each group
|
|
{
|
|
var group = _prototypeManager.Index<DamageGroupPrototype>(damageGroupId); //get group
|
|
foreach (var type in group.DamageTypes) //go through each type inside that group
|
|
{
|
|
if (!damage.DamageDict.TryGetValue(type, out var damageValue) || damageValue == 0) //get value and make sure it isn't 0
|
|
continue;
|
|
|
|
damageTypes.Add(type, damageValue);
|
|
}
|
|
}
|
|
return damageTypes;
|
|
}
|
|
}
|