Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanek31 1 #657

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Content.Shared/Damage/Components/DamageableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public sealed partial class DamageableComponent : Component

[DataField]
public ProtoId<StatusIconPrototype> RottingIcon = "HealthIconRotting";

[DataField]
public float? bypassResistance;
}

[Serializable, NetSerializable]
Expand Down
6 changes: 3 additions & 3 deletions Content.Shared/Damage/DamageSpecifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public DamageSpecifier(DamageGroupPrototype group, FixedPoint2 value)
/// Only applies resistance to a damage type if it is dealing damage, not healing.
/// This will never convert damage into healing.
/// </remarks>
public static DamageSpecifier ApplyModifierSet(DamageSpecifier damageSpec, DamageModifierSet modifierSet)
public static DamageSpecifier ApplyModifierSet(DamageSpecifier damageSpec, DamageModifierSet modifierSet, float br = 1)
{
// Make a copy of the given data. Don't modify the one passed to this function. I did this before, and weapons became
// duller as you hit walls. Neat, but not FixedPoint2ended. And confusing, when you realize your fists don't work no
Expand All @@ -147,10 +147,10 @@ public static DamageSpecifier ApplyModifierSet(DamageSpecifier damageSpec, Damag
float newValue = value.Float();

if (modifierSet.FlatReduction.TryGetValue(key, out var reduction))
newValue = Math.Max(0f, newValue - reduction); // flat reductions can't heal you
newValue = Math.Max(0f, newValue - reduction*br); // flat reductions can't heal you

if (modifierSet.Coefficients.TryGetValue(key, out var coefficient))
newValue *= coefficient; // coefficients can heal you, e.g. cauterizing bleeding
newValue *= 1-coefficient*br; // coefficients can heal you, e.g. cauterizing bleeding

if(newValue != 0)
newDamage.DamageDict[key] = FixedPoint2.New(newValue);
Expand Down
13 changes: 9 additions & 4 deletions Content.Shared/Damage/Systems/DamageableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void DamageChanged(EntityUid uid, DamageableComponent component, DamageSp
/// null if the user had no applicable components that can take damage.
/// </returns>
public DamageSpecifier? TryChangeDamage(EntityUid? uid, DamageSpecifier damage, bool ignoreResistances = false,
bool interruptsDoAfters = true, DamageableComponent? damageable = null, EntityUid? origin = null)
bool interruptsDoAfters = true, DamageableComponent? damageable = null, EntityUid? origin = null, float? bypassResistance = null)
{
if (!uid.HasValue || !_damageableQuery.Resolve(uid.Value, ref damageable, false))
{
Expand All @@ -150,9 +150,14 @@ public void DamageChanged(EntityUid uid, DamageableComponent component, DamageSp
if (damageable.DamageModifierSetId != null &&
_prototypeManager.TryIndex<DamageModifierSetPrototype>(damageable.DamageModifierSetId, out var modifierSet))
{
// TODO DAMAGE PERFORMANCE
// use a local private field instead of creating a new dictionary here..
damage = DamageSpecifier.ApplyModifierSet(damage, modifierSet);
if (bypassResistance != null)
{
damage = DamageSpecifier.ApplyModifierSet(damage, modifierSet,(float) bypassResistance);
}
else
{
damage = DamageSpecifier.ApplyModifierSet(damage, modifierSet);
}
}

var ev = new DamageModifyEvent(damage, origin);
Expand Down
Loading