Skip to content

Commit

Permalink
Merge branch 'master' into nfsd-uplink-store-rubbers
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 authored Jan 19, 2025
2 parents 6788b2d + 6ba285e commit b0056cc
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public sealed partial class AddAccentClothingComponent : Component
/// Is that clothing is worn and affecting someones accent?
/// </summary>
public bool IsActive = false;

/// <summary>
/// Who is currently wearing the item?
/// </summary>
public EntityUid Wearer; // Frontier
}
52 changes: 52 additions & 0 deletions Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Server.Speech.Components;
using Content.Shared.Clothing;
using Content.Shared.Verbs; // Frontier

namespace Content.Server.Speech.EntitySystems;

Expand All @@ -12,6 +13,7 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<AddAccentClothingComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<AddAccentClothingComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<AddAccentClothingComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs); // Frontier
}

private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotEquippedEvent args)
Expand All @@ -30,10 +32,12 @@ private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component,
rep.Accent = component.ReplacementPrototype!;

component.IsActive = true;
component.Wearer = args.Wearer; // Frontier
}

private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotUnequippedEvent args)
{
component.Wearer = EntityUid.Invalid; // Frontier: prevent alt verb
if (!component.IsActive)
return;

Expand All @@ -46,4 +50,52 @@ private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component

component.IsActive = false;
}

// Frontier: togglable accents
/// <summary>
/// Adds an alt verb allowing for the accent to be toggled easily.
/// </summary>
private void OnGetAltVerbs(EntityUid uid, AddAccentClothingComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || args.User != component.Wearer) //only the wearer can toggle the effect
return;

AlternativeVerb verb = new()
{
Text = Loc.GetString("accent-clothing-component-toggle"),
Act = () => ToggleAccent(uid, component)
};
args.Verbs.Add(verb);
}

private void ToggleAccent(EntityUid uid, AddAccentClothingComponent component)
{
if (component.IsActive)
{
// try to remove the accent if it's enabled
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
RemComp(component.Wearer, componentType);
component.IsActive = false;
// we don't wipe out wearer in this case
}
else
{
// try to add the accent as if we are equipping this item again
// does the user already has this accent?
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (HasComp(component.Wearer, componentType))
return;

// add accent to the user
var accentComponent = (Component)_componentFactory.GetComponent(componentType);
AddComp(component.Wearer, accentComponent);

// snowflake case for replacement accent
if (accentComponent is ReplacementAccentComponent rep)
rep.Accent = component.ReplacementPrototype!;

component.IsActive = true;
}
}
// End Frontier: togglable accents
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Content.Server._NF.Speech.Components;

/// <summary>
/// Applies accent to user while they wear entity as a clothing.
/// Applies accent to user while they hold the entity.
/// </summary>
[RegisterComponent]
public sealed partial class AddAccentPickupComponent : Component
Expand All @@ -23,7 +23,12 @@ public sealed partial class AddAccentPickupComponent : Component
public string? ReplacementPrototype;

/// <summary>
/// Is that clothing is worn and affecting someones accent?
/// Is the entity held and affecting someones accent?
/// </summary>
public bool IsActive = false;

/// <summary>
/// Who is currently holding the item?
/// </summary>
public EntityUid Holder; // Frontier
}
60 changes: 53 additions & 7 deletions Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Content.Server._NF.Speech.Components;
using Content.Server.Speech.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared._NF.Item;
using Content.Shared.Verbs;

namespace Content.Server._NF.Speech.EntitySystems;

Expand All @@ -12,40 +13,85 @@ public sealed class AddAccentPickupSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AddAccentPickupComponent, GettingPickedUpAttemptEvent>(OnPickup);
SubscribeLocalEvent<AddAccentPickupComponent, PickedUpEvent>(OnPickup);
SubscribeLocalEvent<AddAccentPickupComponent, DroppedEvent>(OnDropped);
SubscribeLocalEvent<AddAccentPickupComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
}

private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref GettingPickedUpAttemptEvent args)
private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref PickedUpEvent args)
{
// does the user already has this accent?
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (HasComp(args.User, componentType))
return;

// add accent to the user
var accentComponent = (Component) _componentFactory.GetComponent(componentType);
var accentComponent = (Component)_componentFactory.GetComponent(componentType);
AddComp(args.User, accentComponent);

// snowflake case for replacement accent
if (accentComponent is ReplacementAccentComponent rep)
rep.Accent = component.ReplacementPrototype!;

component.IsActive = true;
component.Holder = args.User;
}

private void OnDropped(EntityUid uid, AddAccentPickupComponent component, DroppedEvent args)
{
component.Holder = EntityUid.Invalid; // prevent alt verb
if (!component.IsActive)
return;

// try to remove accent
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (EntityManager.HasComponent(args.User, componentType))
RemComp(args.User, componentType);

component.IsActive = false;
}

/// <summary>
/// Adds an alt verb allowing for the accent to be toggled easily.
/// </summary>
private void OnGetAltVerbs(EntityUid uid, AddAccentPickupComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || args.User != component.Holder) //only the holder can toggle the effect
return;

AlternativeVerb verb = new()
{
EntityManager.RemoveComponent(args.User, componentType);
Text = Loc.GetString("accent-clothing-component-toggle"),
Act = () => ToggleAccent(uid, component)
};
args.Verbs.Add(verb);
}

private void ToggleAccent(EntityUid uid, AddAccentPickupComponent component)
{
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (component.IsActive)
{
// try to remove the accent if it's enabled
RemComp(component.Holder, componentType);
component.IsActive = false;
// we don't wipe out Holder in this case
}
else
{
// try to add the accent as if we are equipping this item again
// does the user already has this accent?
if (HasComp(component.Holder, componentType))
return;

component.IsActive = false;
// add accent to the user
var accentComponent = (Component)_componentFactory.GetComponent(componentType);
AddComp(component.Holder, accentComponent);

// snowflake case for replacement accent
if (accentComponent is ReplacementAccentComponent rep)
rep.Accent = component.ReplacementPrototype!;

component.IsActive = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared._NF.LoggingExtensions; // Frontier
using Content.Shared._NF.Item; // Frontier
using Content.Shared.Clothing.Components;
using Content.Shared.Database;
using Content.Shared.Hands.Components;
Expand Down Expand Up @@ -235,6 +236,7 @@ public virtual void DoPickup(EntityUid uid, Hand hand, EntityUid entity, HandsCo
Log.Error($"Failed to insert {ToPrettyString(entity)} into users hand container when picking up. User: {ToPrettyString(uid)}. Hand: {hand.Name}.");
return;
}
RaiseLocalEvent(entity, new PickedUpEvent(uid, entity), false); // Frontier

if (log)
{
Expand Down
16 changes: 16 additions & 0 deletions Content.Shared/_NF/Item/PickupEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Content.Shared._NF.Item;

/// <summary>
/// Raised directed at entity being picked after someone picks it up sucessfully.
/// </summary>
public sealed class PickedUpEvent : EntityEventArgs
{
public readonly EntityUid User;
public readonly EntityUid Item;

public PickedUpEvent(EntityUid user, EntityUid item)
{
User = user;
Item = item;
}
}
8 changes: 8 additions & 0 deletions Resources/Changelog/Frontier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6490,3 +6490,11 @@ Entries:
message: Emergency lights should properly turn off when resetting to green state.
id: 5669
time: '2025-01-19T11:42:46.0000000+00:00'
- author: Alkheemist
changes:
- type: Tweak
message: >-
Clothing and items that apply accents can be toggled with alt click, so
you can dress in style without worrying about intelligibility.
id: 5670
time: '2025-01-19T16:12:47.0000000+00:00'
5 changes: 4 additions & 1 deletion Resources/Locale/en-US/_NF/accent/accents.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ accent-words-fox-2 = Yap!
accent-words-fox-3 = Ruff!
accent-words-fox-4 = Wraaah!
accent-words-fox-5 = Aaaaagh!
accent-words-fox-6 = Screeee!
accent-words-fox-6 = Screeee!
# Accent Toggle
accent-clothing-component-toggle = Toggle Accent

0 comments on commit b0056cc

Please sign in to comment.