Add ability for +VVEDIT users to scale damage/healing in the game (#35255)
* Initial commit * Add universal modifier for all damage/heals, make guidebooks work. * help text
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Inventory;
|
||||
@@ -7,6 +9,7 @@ using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Radiation.Events;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -20,11 +23,24 @@ namespace Content.Shared.Damage
|
||||
[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!;
|
||||
|
||||
private EntityQuery<AppearanceComponent> _appearanceQuery;
|
||||
private EntityQuery<DamageableComponent> _damageableQuery;
|
||||
private EntityQuery<MindContainerComponent> _mindContainerQuery;
|
||||
|
||||
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 override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<DamageableComponent, ComponentInit>(DamageableInit);
|
||||
@@ -36,6 +52,36 @@ namespace Content.Shared.Damage
|
||||
_appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
||||
_damageableQuery = GetEntityQuery<DamageableComponent>();
|
||||
_mindContainerQuery = GetEntityQuery<MindContainerComponent>();
|
||||
|
||||
// Damage modifier CVars are updated and stored here to be queried in other systems.
|
||||
// Note that certain modifiers requires reloading the guidebook.
|
||||
Subs.CVar(_config, CCVars.PlaytestAllDamageModifier, value =>
|
||||
{
|
||||
UniversalAllDamageModifier = value;
|
||||
_chemistryGuideData.ReloadAllReagentPrototypes();
|
||||
}, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestAllHealModifier, value =>
|
||||
{
|
||||
UniversalAllHealModifier = value;
|
||||
_chemistryGuideData.ReloadAllReagentPrototypes();
|
||||
}, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestProjectileDamageModifier, value => UniversalProjectileDamageModifier = value, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestMeleeDamageModifier, value => UniversalMeleeDamageModifier = value, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestProjectileDamageModifier, value => UniversalProjectileDamageModifier = value, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestHitscanDamageModifier, value => UniversalHitscanDamageModifier = value, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestReagentDamageModifier, value =>
|
||||
{
|
||||
UniversalReagentDamageModifier = value;
|
||||
_chemistryGuideData.ReloadAllReagentPrototypes();
|
||||
}, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestReagentHealModifier, value =>
|
||||
{
|
||||
UniversalReagentHealModifier = value;
|
||||
_chemistryGuideData.ReloadAllReagentPrototypes();
|
||||
}, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestExplosionDamageModifier, value => UniversalExplosionDamageModifier = value, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestThrownDamageModifier, value => UniversalThrownDamageModifier = value, true);
|
||||
Subs.CVar(_config, CCVars.PlaytestTopicalsHealModifier, value => UniversalTopicalsHealModifier = value, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -164,6 +210,8 @@ namespace Content.Shared.Damage
|
||||
}
|
||||
}
|
||||
|
||||
damage = ApplyUniversalAllModifiers(damage);
|
||||
|
||||
// TODO DAMAGE PERFORMANCE
|
||||
// Consider using a local private field instead of creating a new dictionary here.
|
||||
// Would need to check that nothing ever tries to cache the delta.
|
||||
@@ -191,6 +239,37 @@ namespace Content.Shared.Damage
|
||||
return delta;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the two univeral "All" modifiers, if set.
|
||||
/// Individual damage source modifiers are set in their respective code.
|
||||
/// </summary>
|
||||
/// <param name="damage">The damage to be changed.</param>
|
||||
public DamageSpecifier ApplyUniversalAllModifiers(DamageSpecifier damage)
|
||||
{
|
||||
// Checks for changes first since they're unlikely in normal play.
|
||||
if (UniversalAllDamageModifier == 1f && UniversalAllHealModifier == 1f)
|
||||
return damage;
|
||||
|
||||
foreach (var (key, value) in damage.DamageDict)
|
||||
{
|
||||
if (value == 0)
|
||||
continue;
|
||||
|
||||
if (value > 0)
|
||||
{
|
||||
damage.DamageDict[key] *= UniversalAllDamageModifier;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
damage.DamageDict[key] *= UniversalAllHealModifier;
|
||||
}
|
||||
}
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets all damage types supported by a <see cref="DamageableComponent"/> to the specified value.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user