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

Вариантивность урона #245

Merged
merged 1 commit into from
Jul 27, 2024
Merged
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
5 changes: 5 additions & 0 deletions Content.IntegrationTests/Tests/Damageable/DamageableTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Linq;
using Content.Shared._Sunrise.SunriseCCVars;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;

namespace Content.IntegrationTests.Tests.Damageable
Expand Down Expand Up @@ -89,6 +91,7 @@ public async Task TestDamageableComponents()
var sMapManager = server.ResolveDependency<IMapManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
var sEntitySystemManager = server.ResolveDependency<IEntitySystemManager>();
var sConfigManager = server.ResolveDependency<IConfigurationManager>();

EntityUid sDamageableEntity = default;
DamageableComponent sDamageableComponent = null;
Expand Down Expand Up @@ -127,6 +130,8 @@ await server.WaitPost(() =>
type3a = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3a");
type3b = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3b");
type3c = sPrototypeManager.Index<DamageTypePrototype>("TestDamage3c");

sConfigManager.SetCVar(SunriseCCVars.DamageVariance, 0f); // Sunrise-Edit
});

await server.WaitRunTicks(5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Shared._Sunrise.SunriseCCVars;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Configuration;
using static Content.IntegrationTests.Tests.Destructible.DestructibleTestPrototypes;

namespace Content.IntegrationTests.Tests.Destructible
Expand All @@ -26,6 +28,7 @@ public async Task AndTest()
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
var sEntitySystemManager = server.ResolveDependency<IEntitySystemManager>();
var sConfigManager = server.ResolveDependency<IConfigurationManager>(); // Sunrise-Edit

EntityUid sDestructibleEntity = default;
DamageableComponent sDamageableComponent = null;
Expand All @@ -43,6 +46,7 @@ await server.WaitPost(() =>
sTestThresholdListenerSystem.ThresholdsReached.Clear();

sDamageableSystem = sEntitySystemManager.GetEntitySystem<DamageableSystem>();
sConfigManager.SetCVar(SunriseCCVars.DamageVariance, 0f); // Sunrise-Edit
});

await server.WaitRunTicks(5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Shared._Sunrise.SunriseCCVars;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Configuration;
using static Content.IntegrationTests.Tests.Destructible.DestructibleTestPrototypes;

namespace Content.IntegrationTests.Tests.Destructible
Expand All @@ -23,6 +25,7 @@ public async Task Test()
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sEntitySystemManager = server.ResolveDependency<IEntitySystemManager>();
var protoManager = server.ResolveDependency<IPrototypeManager>();
var sConfigManager = server.ResolveDependency<IConfigurationManager>(); // Sunrise-Edit

EntityUid sDestructibleEntity = default;
DamageableComponent sDamageableComponent = null;
Expand All @@ -38,6 +41,7 @@ await server.WaitPost(() =>
sTestThresholdListenerSystem = sEntitySystemManager.GetEntitySystem<TestDestructibleListenerSystem>();
sTestThresholdListenerSystem.ThresholdsReached.Clear();
sDamageableSystem = sEntitySystemManager.GetEntitySystem<DamageableSystem>();
sConfigManager.SetCVar(SunriseCCVars.DamageVariance, 0f); // Sunrise-Edit
});

await server.WaitRunTicks(5);
Expand Down
22 changes: 22 additions & 0 deletions Content.Shared/Damage/Systems/DamageableSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Shared._Sunrise.SunriseCCVars;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Inventory;
Expand All @@ -7,10 +8,13 @@
using Content.Shared.Mobs.Systems;
using Content.Shared.Radiation.Events;
using Content.Shared.Rejuvenate;
using Content.Shared.CCVar;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using Robust.Shared.Configuration;
using Robust.Shared.Random;

namespace Content.Shared.Damage
{
Expand All @@ -20,11 +24,15 @@ public sealed class DamageableSystem : EntitySystem
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;

private EntityQuery<AppearanceComponent> _appearanceQuery;
private EntityQuery<DamageableComponent> _damageableQuery;
private EntityQuery<MindContainerComponent> _mindContainerQuery;

public float Variance = 0.15f; // Sunrise-Edit

public override void Initialize()
{
SubscribeLocalEvent<DamageableComponent, ComponentInit>(DamageableInit);
Expand All @@ -36,6 +44,8 @@ public override void Initialize()
_appearanceQuery = GetEntityQuery<AppearanceComponent>();
_damageableQuery = GetEntityQuery<DamageableComponent>();
_mindContainerQuery = GetEntityQuery<MindContainerComponent>();

_configurationManager.OnValueChanged(SunriseCCVars.DamageVariance, UpdateVariance); // Sunrise-Edit
}

/// <summary>
Expand Down Expand Up @@ -143,6 +153,11 @@ public void DamageChanged(EntityUid uid, DamageableComponent component, DamageSp
if (before.Cancelled)
return null;

// Sunrise-Start
var multiplier = 1f + Variance - _random.NextFloat(0, Variance * 2f);
damage *= multiplier;
// Sunrise-End

// Apply resistances
if (!ignoreResistances)
{
Expand Down Expand Up @@ -280,6 +295,13 @@ private void DamageableHandleState(EntityUid uid, DamageableComponent component,
DamageChanged(uid, component, delta);
}
}

// Sunrise-Start
private void UpdateVariance(float variance)
{
Variance = variance;
}
// Sunrise-End
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/_Sunrise/SunriseCCVars/SunriseCCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ public static readonly CVarDef<bool>

public static readonly CVarDef<bool> CryoTeleportEnable =
CVarDef.Create("cryo_teleport.enable", false, CVar.SERVERONLY);

/*
* Damage variance
*/

public static readonly CVarDef<float> DamageVariance =
CVarDef.Create("damage.variance", 0.15f, CVar.SERVER | CVar.REPLICATED);

}
Loading