mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Empty commit * yeah thingi * added a GetHighestDamageTypes thingi to the DamageableSystem * no idea why those files names are different only in github so just in case readding them * yeah doing that * first steps of moving the logic somewhere nicer * still plenty to do * gosh such a mess but getting progress done * small fixie push * big mess of bunch of stuff * dealing with a conflict and fixing the random numbers * testing if github will update now * dealing with the other conflict * github please update i beg you * dealing with more conflicts * hopefully this fixes it * fixing conflicts again * cleaning up stuffies * sprite fixie * general cleanup * doing the small fixies first * getting rid of the new event, gotta handle ashing next * adding spaces to comments before i forget * handling ashing * think that did it? * small fixies * more small fixies * last batch of quickie fixies before i gotta handle the bigger stuff * last bunch of fixies i do understand * small bit of progress yknow may as well yeah * renaming and moving stuff to shared * comment fixiees * saving damage in a new component instead of in MindComponent * protoid's and dict usage instead of the previously ickier methods * small fixie before biggie fixie * more fixies im slepy gosh * thinkie that should fixie it * smoothed the damage storage systeem so its less repetitive and icki and now itss cooler and i can go eepy * lots of stuffies x3 * first step of getting git to detect my file name changes * thinkie that should fixie it * fixies * just getting rid of the merge conflict, will check damageable later * small thingies first * more small stuffiees * now all of the sprites have at leeast a 0 * dirtying the lastbody comp * more fixies * small thingi first * another small fixie and a minor sprite fixie * rng fixie * moving the damage storage system to shared * smoothing out code thats likely to be replaced soon but its good to do for now * just showing progress bcus yis * general progress stuffies mhm * pushie * small cleanup * general progress :3 * in progress push for helpie * proper pushie with progress and workies * removed unnecessary usage of the storedamage component * minor fixiees * extra comments * replaced a couple strings for ProtoId's * gibbing related fixies :3
120 lines
5.1 KiB
C#
120 lines
5.1 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 INetManager _netMan = 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;
|
|
|
|
/// <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));
|
|
}
|
|
private void DamageableGetState(Entity<DamageableComponent> ent, ref ComponentGetState args)
|
|
{
|
|
if (_netMan.IsServer)
|
|
{
|
|
args.State = new DamageableComponentState(
|
|
ent.Comp.Damage.DamageDict,
|
|
ent.Comp.DamageContainerID,
|
|
ent.Comp.DamageModifierSetId,
|
|
ent.Comp.HealthBarThreshold
|
|
);
|
|
// TODO BODY SYSTEM pass damage onto body system
|
|
// BOBBY WHEN? 😭
|
|
// BOBBY SOON 🫡
|
|
|
|
return;
|
|
}
|
|
|
|
// avoid mispredicting damage on newly spawned entities.
|
|
args.State = new DamageableComponentState(
|
|
ent.Comp.Damage.DamageDict.ShallowClone(),
|
|
ent.Comp.DamageContainerID,
|
|
ent.Comp.DamageModifierSetId,
|
|
ent.Comp.HealthBarThreshold
|
|
);
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
}
|