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

Make Height Sliders Affect Your Bloodstream Volume #858

Merged
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
45 changes: 45 additions & 0 deletions Content.Server/HeightAdjust/BloodstreamAdjustSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Content.Server.Body.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Shared.CCVar;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Contests;
using Content.Shared.HeightAdjust;
using Robust.Shared.Configuration;

namespace Content.Server.HeightAdjust;

public sealed class BloodstreamAdjustSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly ContestsSystem _contests = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;

public override void Initialize()
{
SubscribeLocalEvent<BloodstreamAffectedByMassComponent, MapInitEvent>((uid, comp, _) => TryAdjustBloodstream((uid, comp)));
SubscribeLocalEvent<BloodstreamAffectedByMassComponent, HeightAdjustedEvent>((uid, comp, _) => TryAdjustBloodstream((uid, comp)));
}

/// <summary>
/// Adjusts the bloodstream of the specified entity based on the settings provided by the component.
/// </summary>
public bool TryAdjustBloodstream(Entity<BloodstreamAffectedByMassComponent> ent)
{
if (!TryComp<BloodstreamComponent>(ent, out var bloodstream)
|| !_solutionContainer.TryGetSolution(ent.Owner, bloodstream.BloodSolutionName, out var bloodSolutionEnt)
|| !_config.GetCVar(CCVars.HeightAdjustModifiesBloodstream))
return false;

var bloodSolution = bloodSolutionEnt.Value.Comp.Solution;

var factor = Math.Pow(_contests.MassContest(ent, bypassClamp: true, rangeFactor: 4f), ent.Comp.Power);
Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved
factor = Math.Clamp(factor, ent.Comp.Min, ent.Comp.Max);

var newVolume = bloodstream.BloodMaxVolume * factor;
var newBloodLevel = bloodSolution.FillFraction * newVolume;
bloodSolution.MaxVolume = newVolume;
bloodSolution.SetContents([new ReagentQuantity(bloodstream.BloodReagent, newBloodLevel, null)], false);

return true;
}
}
26 changes: 26 additions & 0 deletions Content.Server/HeightAdjust/BloodstreamAffectedByMassComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Content.Server.Body.Components;

namespace Content.Server.HeightAdjust;

/// <summary>
/// When applied to a humanoid or any mob, adjusts their blood level based on the mass contest between them
/// and an average humanoid.
/// <br/>
/// The formula for the resulting bloodstream volume is <code>V = BloodMaxVolume * MassContest^Power</code>
/// clamped between the specified Min and Max values.
/// </summary>
[RegisterComponent]
public sealed partial class BloodstreamAffectedByMassComponent : Component
VMSolidus marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Minimum and maximum resulting volume factors. A minimum value of 0.5 means that the resulting volume will be at least 50% of the original.
/// </summary>
[DataField]
public float Min = 1 / 3f, Max = 3f;

/// <summary>
/// The power to which the outcome of the mass contest will be risen.
/// </summary>
[DataField]
public float Power = 1f;
}
9 changes: 9 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,15 @@ public static readonly CVarDef<float>
public static readonly CVarDef<bool> HeightAdjustModifiesZoom =
CVarDef.Create("heightadjust.modifies_zoom", false, CVar.SERVERONLY);

/// <summary>
/// Whether height & width sliders adjust a player's bloodstream volume.
/// </summary>
/// <remarks>
/// This can be configured more precisely by modifying BloodstreamAffectedByMassComponent.
/// </remarks>
public static readonly CVarDef<bool> HeightAdjustModifiesBloodstream =
CVarDef.Create("heightadjust.modifies_bloodstream", true, CVar.SERVERONLY);

/// <summary>
/// Enables station goals
/// </summary>
Expand Down
24 changes: 3 additions & 21 deletions Content.Shared/HeightAdjust/HeightAdjustSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,7 @@ public sealed class HeightAdjustSystem : EntitySystem
/// <returns>True if all operations succeeded</returns>
public bool SetScale(EntityUid uid, float scale)
{
var succeeded = true;
if (_config.GetCVar(CCVars.HeightAdjustModifiesZoom) && EntityManager.TryGetComponent<ContentEyeComponent>(uid, out var eye))
_eye.SetMaxZoom(uid, eye.MaxZoom * scale);
else
succeeded = false;

if (_config.GetCVar(CCVars.HeightAdjustModifiesHitbox) && EntityManager.TryGetComponent<FixturesComponent>(uid, out var fixtures))
foreach (var fixture in fixtures.Fixtures)
_physics.SetRadius(uid, fixture.Key, fixture.Value, fixture.Value.Shape, MathF.MinMagnitude(fixture.Value.Shape.Radius * scale, 0.49f));
else
succeeded = false;

if (EntityManager.HasComponent<HumanoidAppearanceComponent>(uid))
{
_appearance.SetHeight(uid, scale);
_appearance.SetWidth(uid, scale);
}
else
succeeded = false;

return succeeded;
return SetScale(uid, new Vector2(scale, scale));
}

/// <summary>
Expand Down Expand Up @@ -75,6 +55,8 @@ public bool SetScale(EntityUid uid, Vector2 scale)
else
succeeded = false;

RaiseLocalEvent(uid, new HeightAdjustedEvent { NewScale = scale });

return succeeded;
}
}
11 changes: 11 additions & 0 deletions Content.Shared/HeightAdjust/HeightAdjustedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Numerics;

namespace Content.Shared.HeightAdjust;

/// <summary>
/// Raised on a humanoid after their scale has been adjusted in accordance with their profile and their physics have been updated.
/// </summary>
public sealed class HeightAdjustedEvent : EntityEventArgs
{
public Vector2 NewScale;
}
2 changes: 2 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@
- type: OfferItem
- type: LayingDown
- type: Shoving
- type: BloodstreamAffectedByMass
power: 0.6 # A minimum size felinid will have 30% blood, a minimum size vulp will have 60%, a maximum size oni will have ~200%

- type: entity
save: false
Expand Down
Loading