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

[Feature] [Balance] Mood Traits & Things #961

Merged
merged 8 commits into from
Dec 8, 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
105 changes: 0 additions & 105 deletions Content.Server/Backmen/Mood/MoodComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,109 +5,4 @@

namespace Content.Server.Backmen.Mood;

[RegisterComponent]
public sealed partial class MoodComponent : Component
{
[DataField]
public float CurrentMoodLevel;

[DataField]
public MoodThreshold CurrentMoodThreshold;

[DataField]
public MoodThreshold LastThreshold;

[ViewVariables(VVAccess.ReadOnly)]
public readonly Dictionary<string, string> CategorisedEffects = new();

[ViewVariables(VVAccess.ReadOnly)]
public readonly Dictionary<string, float> UncategorisedEffects = new();

/// <summary>
/// The formula for the movement speed modifier is SpeedBonusGrowth ^ (MoodLevel - MoodThreshold.Neutral).
/// Change this ONLY BY 0.001 AT A TIME.
/// </summary>
[DataField]
public float SpeedBonusGrowth = 1.003f;

/// <summary>
/// The lowest point that low morale can multiply our movement speed by. Lowering speed follows a linear curve, rather than geometric.
/// </summary>
[DataField]
public float MinimumSpeedModifier = 0.75f;

/// <summary>
/// The maximum amount that high morale can multiply our movement speed by. This follows a significantly slower geometric sequence.
/// </summary>
[DataField]
public float MaximumSpeedModifier = 1.15f;

[DataField]
public float IncreaseCritThreshold = 1.2f;

[DataField]
public float DecreaseCritThreshold = 0.9f;

[ViewVariables(VVAccess.ReadOnly)]
public FixedPoint2 CritThresholdBeforeModify;

[DataField(customTypeSerializer: typeof(DictionarySerializer<MoodThreshold, float>))]
public Dictionary<MoodThreshold, float> MoodThresholds = new()
{
{ MoodThreshold.Perfect, 100f },
{ MoodThreshold.Exceptional, 80f },
{ MoodThreshold.Great, 70f },
{ MoodThreshold.Good, 60f },
{ MoodThreshold.Neutral, 50f },
{ MoodThreshold.Meh, 40f },
{ MoodThreshold.Bad, 30f },
{ MoodThreshold.Terrible, 20f },
{ MoodThreshold.Horrible, 10f },
{ MoodThreshold.Dead, 0f }
};

[DataField(customTypeSerializer: typeof(DictionarySerializer<MoodThreshold, ProtoId<AlertPrototype>>))]
public Dictionary<MoodThreshold, ProtoId<AlertPrototype>> MoodThresholdsAlerts = new()
{
{ MoodThreshold.Dead, "MoodDead" },
{ MoodThreshold.Horrible, "MoodHorrible" },
{ MoodThreshold.Terrible, "MoodTerrible" },
{ MoodThreshold.Bad, "MoodBad" },
{ MoodThreshold.Meh, "MoodMeh" },
{ MoodThreshold.Neutral, "MoodNeutral" },
{ MoodThreshold.Good, "MoodGood" },
{ MoodThreshold.Great, "MoodGreat" },
{ MoodThreshold.Exceptional, "MoodExceptional" },
{ MoodThreshold.Perfect, "MoodPerfect" },
{ MoodThreshold.Insane, "MoodInsane" }
};

/// <summary>
/// These thresholds represent a percentage of Crit-Threshold, 0.8 corresponding with 80%.
/// </summary>
[DataField(customTypeSerializer: typeof(DictionarySerializer<string, float>))]
public Dictionary<string, float> HealthMoodEffectsThresholds = new()
{
{ "HealthHeavyDamage", 0.8f },
{ "HealthSevereDamage", 0.5f },
{ "HealthOkayDamage", 0.35f },
{ "HealthLightDamage", 0.1f },
{ "HealthNoDamage", 0.05f }
};
}

[Serializable]
public enum MoodThreshold : ushort
{
Insane = 1,
Horrible = 2,
Terrible = 3,
Bad = 4,
Meh = 5,
Neutral = 6,
Good = 7,
Great = 8,
Exceptional = 9,
Perfect = 10,
Dead = 0
}
46 changes: 26 additions & 20 deletions Content.Server/Backmen/Mood/MoodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ private void OnRefreshMoveSpeed(EntityUid uid, MoodComponent component, RefreshM

private void OnTraitStartup(EntityUid uid, MoodModifyTraitComponent component, ComponentStartup args)
{
if (component.MoodId != null)
RaiseLocalEvent(uid, new MoodEffectEvent($"{component.MoodId}"));
if (!TryComp<MoodComponent>(uid, out var mood))
return;

mood.GoodMoodMultiplier = component.GoodMoodMultiplier;
mood.BadMoodMultiplier = component.BadMoodMultiplier;
RaiseLocalEvent(uid, new MoodEffectEvent($"{component.MoodId}"));
}

private void OnMoodEffect(EntityUid uid, MoodComponent component, MoodEffectEvent args)
Expand Down Expand Up @@ -308,12 +312,18 @@ private void RefreshMood(EntityUid uid, MoodComponent component)
if (!_prototypeManager.TryIndex<MoodEffectPrototype>(protoId, out var prototype))
continue;

amount += prototype.MoodChange;
if (prototype.MoodChange > 0)
amount += prototype.MoodChange * component.GoodMoodMultiplier;
else
amount += prototype.MoodChange * component.BadMoodMultiplier;
}

foreach (var (_, value) in component.UncategorisedEffects)
{
amount += value;
if (value > 0)
amount += value * component.GoodMoodMultiplier;
else
amount += value * component.BadMoodMultiplier;
}

SetMood(uid, amount, component, refresh: true);
Expand All @@ -326,7 +336,6 @@ private void OnInit(EntityUid uid, MoodComponent component, ComponentStartup arg
&& _mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var critThreshold, mobThresholdsComponent))
component.CritThresholdBeforeModify = critThreshold.Value;

EnsureComp<NetMoodComponent>(uid);
RefreshMood(uid, component);
}

Expand Down Expand Up @@ -359,12 +368,8 @@ private void SetMood(EntityUid uid, float amount, MoodComponent? component = nul

component.CurrentMoodLevel = newMoodLevel;

if (TryComp<NetMoodComponent>(uid, out var mood))
{
mood.CurrentMoodLevel = component.CurrentMoodLevel;
mood.NeutralMoodThreshold = component.MoodThresholds.GetValueOrDefault(MoodThreshold.Neutral);
}

component.NeutralMoodThreshold = component.MoodThresholds.GetValueOrDefault(MoodThreshold.Neutral);
Dirty(uid, component);
UpdateCurrentThreshold(uid, component);
}

Expand All @@ -388,10 +393,10 @@ private void DoMoodThresholdsEffects(EntityUid uid, MoodComponent? component = n
|| component.CurrentMoodThreshold == component.LastThreshold && !force)
return;

var modifier = GetMovementThreshold(component.CurrentMoodThreshold);
var modifier = GetMovementThreshold(component.CurrentMoodThreshold, component);

// Modify mob stats
if (modifier != GetMovementThreshold(component.LastThreshold))
if (modifier != GetMovementThreshold(component.LastThreshold, component))
{
_movementSpeedModifier.RefreshMovementSpeedModifiers(uid);
SetCritThreshold(uid, component, modifier);
Expand Down Expand Up @@ -451,14 +456,15 @@ private MoodThreshold GetMoodThreshold(MoodComponent component, float? moodLevel
return result;
}

private int GetMovementThreshold(MoodThreshold threshold)
private int GetMovementThreshold(MoodThreshold threshold, MoodComponent component)
{
return threshold switch
{
>= MoodThreshold.Good => 1,
<= MoodThreshold.Meh => -1,
_ => 0
};
if (threshold >= component.BuffsMoodThreshold)
return 1;

if (threshold <= component.ConsMoodThreshold)
return -1;

return 0;
}

private string GetMoodName(MoodThreshold threshold)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ namespace Content.Server.Backmen.Traits.Assorted;
public sealed partial class MoodModifyTraitComponent : Component
{
[DataField]
public string? MoodId = null;
public string? MoodId;

[DataField]
public float GoodMoodMultiplier = 1.0f;

[DataField]
public float BadMoodMultiplier = 1.0f;
}
134 changes: 128 additions & 6 deletions Content.Shared/Backmen/Mood/SharedMoodComponent.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,137 @@
using Content.Shared.Alert;
using Content.Shared.FixedPoint;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;

namespace Content.Shared.Backmen.Mood;

/// <summary>
/// This component exists solely to network CurrentMoodLevel, so that clients can make use of its value for math Prediction.
/// All mood logic is otherwise handled by the Server, and the client is not allowed to know the identity of its mood events.
/// </summary>
[RegisterComponent, AutoGenerateComponentState]
public sealed partial class NetMoodComponent : Component
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class MoodComponent : Component
{
public override bool SendOnlyToOwner => true;

[DataField, AutoNetworkedField]
public float CurrentMoodLevel;

[DataField, AutoNetworkedField]
public float NeutralMoodThreshold;

[DataField]
public MoodThreshold CurrentMoodThreshold;

[DataField]
public MoodThreshold LastThreshold;

[ViewVariables(VVAccess.ReadOnly)]
public readonly Dictionary<string, string> CategorisedEffects = new();

[ViewVariables(VVAccess.ReadOnly)]
public readonly Dictionary<string, float> UncategorisedEffects = new();

/// <summary>
/// The formula for the movement speed modifier is SpeedBonusGrowth ^ (MoodLevel - MoodThreshold.Neutral).
/// Change this ONLY BY 0.001 AT A TIME.
/// </summary>
[DataField]
public float SpeedBonusGrowth = 1.003f;

/// <summary>
/// The lowest point that low morale can multiply our movement speed by. Lowering speed follows a linear curve, rather than geometric.
/// </summary>
[DataField]
public float MinimumSpeedModifier = 0.90f;

/// <summary>
/// The maximum amount that high morale can multiply our movement speed by. This follows a significantly slower geometric sequence.
/// </summary>
[DataField]
public float MaximumSpeedModifier = 1.15f;

[DataField]
public float IncreaseCritThreshold = 1.2f;

[DataField]
public float DecreaseCritThreshold = 0.9f;

/// <summary>
/// Multiplier for positive mood effects.
/// </summary>
[DataField]
public float GoodMoodMultiplier = 1.0f;

/// <summary>
/// Multiplier for negative mood effects.
/// </summary>
[DataField]
public float BadMoodMultiplier = 1.0f;

[DataField]
public MoodThreshold BuffsMoodThreshold = MoodThreshold.Good;

[DataField]
public MoodThreshold ConsMoodThreshold = MoodThreshold.Bad;

[ViewVariables(VVAccess.ReadOnly)]
public FixedPoint2 CritThresholdBeforeModify;

[DataField(customTypeSerializer: typeof(DictionarySerializer<MoodThreshold, float>))]
public Dictionary<MoodThreshold, float> MoodThresholds = new()
{
{ MoodThreshold.Perfect, 100f },
{ MoodThreshold.Exceptional, 80f },
{ MoodThreshold.Great, 70f },
{ MoodThreshold.Good, 60f },
{ MoodThreshold.Neutral, 50f },
{ MoodThreshold.Meh, 40f },
{ MoodThreshold.Bad, 30f },
{ MoodThreshold.Terrible, 20f },
{ MoodThreshold.Horrible, 10f },
{ MoodThreshold.Dead, 0f }
};

[DataField(customTypeSerializer: typeof(DictionarySerializer<MoodThreshold, ProtoId<AlertPrototype>>))]
public Dictionary<MoodThreshold, ProtoId<AlertPrototype>> MoodThresholdsAlerts = new()
{
{ MoodThreshold.Dead, "MoodDead" },
{ MoodThreshold.Horrible, "MoodHorrible" },
{ MoodThreshold.Terrible, "MoodTerrible" },
{ MoodThreshold.Bad, "MoodBad" },
{ MoodThreshold.Meh, "MoodMeh" },
{ MoodThreshold.Neutral, "MoodNeutral" },
{ MoodThreshold.Good, "MoodGood" },
{ MoodThreshold.Great, "MoodGreat" },
{ MoodThreshold.Exceptional, "MoodExceptional" },
{ MoodThreshold.Perfect, "MoodPerfect" },
{ MoodThreshold.Insane, "MoodInsane" }
};

/// <summary>
/// These thresholds represent a percentage of Crit-Threshold, 0.8 corresponding with 80%.
/// </summary>
[DataField(customTypeSerializer: typeof(DictionarySerializer<string, float>))]
public Dictionary<string, float> HealthMoodEffectsThresholds = new()
{
{ "HealthHeavyDamage", 0.8f },
{ "HealthSevereDamage", 0.5f },
{ "HealthOkayDamage", 0.35f },
{ "HealthLightDamage", 0.1f },
{ "HealthNoDamage", 0.05f }
};
}

[Serializable]
public enum MoodThreshold : ushort
{
Insane = 1,
Horrible = 2,
Terrible = 3,
Bad = 4,
Meh = 5,
Neutral = 6,
Good = 7,
Great = 8,
Exceptional = 9,
Perfect = 10,
Dead = 0
}
Loading
Loading