Skip to content

Commit

Permalink
More small code cleanup, fancy new Record Structs
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Aug 19, 2024
1 parent 8811d83 commit a4eb156
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 59 deletions.
6 changes: 3 additions & 3 deletions Content.Server/Mood/MoodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ private void RemoveTimedOutEffect(EntityUid uid, string prototypeId, string? cat

if (category == null)
{
if (!comp.UncategorisedEffects.TryGetValue(prototypeId, out var value))
if (!comp.UncategorisedEffects.ContainsKey(prototypeId))
return;
comp.UncategorisedEffects.Remove(prototypeId);
}
else
{
if (!comp.CategorisedEffects.TryGetValue(category, out var currentProtoId)
|| currentProtoId != prototypeId
|| !_prototypeManager.TryIndex<MoodEffectPrototype>(currentProtoId, out var currentProto))
|| !_prototypeManager.HasIndex<MoodEffectPrototype>(currentProtoId))
return;
comp.CategorisedEffects.Remove(category);
}
Expand Down Expand Up @@ -228,7 +228,7 @@ private void SetMood(EntityUid uid, float amount, MoodComponent? component = nul
return;

var neutral = component.MoodThresholds[MoodThreshold.Neutral];
var ev = new OnSetMoodEvent(uid, amount);
var ev = new OnSetMoodEvent(uid, amount, false);
RaiseLocalEvent(uid, ref ev);

if (ev.Cancelled)
Expand Down
58 changes: 2 additions & 56 deletions Content.Shared/Mood/MoodEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,66 +48,12 @@ public MoodRemoveEffectEvent(string effectId)
/// EG: The end result after tallying up all Moodlets comes out to 70, but a trait multiplies it by 0.8 to make it 56.
/// </summary>
[ByRefEvent]
public struct OnSetMoodEvent
{
public float MoodChangedAmount;

public EntityUid Receiver;

public bool Cancelled;

/// <summary>
/// This event is raised whenever an entity sets their mood, allowing other systems to modify the end result of mood math.
/// EG: The end result after tallying up all Moodlets comes out to 70, but a trait multiplies it by 0.8 to make it 56.
/// </summary>
public OnSetMoodEvent(EntityUid receiver, float moodChangedAmount)
{
Receiver = receiver;
MoodChangedAmount = moodChangedAmount;
}
}
public record struct OnSetMoodEvent(EntityUid Receiver, float MoodChangedAmount, bool Cancelled);

/// <summary>
/// This event is raised on an entity when it receives a mood effect, but before the effects are calculated.
/// Allows for other systems to pick and choose specific events to modify.
/// </summary>
[ByRefEvent]
public struct OnMoodEffect
{
/// <summary>
/// The entity receiving a Mood Effect
/// </summary>
public EntityUid Receiver;

/// <summary>
/// ID of the moodlet prototype to use
/// </summary>
public string EffectId;

/// <summary>
/// How much should the mood change be multiplied by
/// <br />
/// This does nothing if the moodlet ID matches one with the same Category
/// </summary>
public float EffectModifier = 1;

/// <summary>
/// How much should the mood change be offset by, after multiplication
/// <br />
/// This does nothing if the moodlet ID matches one with the same Category
/// </summary>
public float EffectOffset = 0;

/// <summary>
/// This event is raised on an entity when it receives a mood effect, but before the effects are calculated.
/// Allows for other systems to pick and choose specific events to modify.
/// </summary>
public OnMoodEffect(EntityUid receiver, string effectId, float effectModifier, float effectOffset)
{
Receiver = receiver;
EffectId = effectId;
EffectModifier = effectModifier;
EffectOffset = effectOffset;
}
}
public record struct OnMoodEffect(EntityUid Receiver, string EffectId, float EffectModifier = 1, float EffectOffset = 0);

0 comments on commit a4eb156

Please sign in to comment.