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

Add alt verb to toggle accents from clothing #2648

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
}
9 changes: 7 additions & 2 deletions Content.Server/Speech/Components/AddAccentPickupComponent.cs
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
}
55 changes: 55 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 = new EntityUid(0); // null out the component wearer entry to prevent alt verb interactions when no longer worn. Frontier
if (!component.IsActive)
return;

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

component.IsActive = false;
}

// Frontier Start
/// <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;
if (EntityManager.HasComponent(component.Wearer, componentType))
{
EntityManager.RemoveComponent(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;
}
}
// Frontier End
}
57 changes: 55 additions & 2 deletions Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Speech.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Verbs;

namespace Content.Server._NF.Speech.EntitySystems;

Expand All @@ -12,11 +13,12 @@ public sealed class AddAccentPickupSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AddAccentPickupComponent, GettingPickedUpAttemptEvent>(OnPickup);
SubscribeLocalEvent<AddAccentPickupComponent, GettingPickedUpEvent>(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 GettingPickedUpEvent args)
{
// does the user already has this accent?
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
Expand All @@ -32,10 +34,12 @@ private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref Get
rep.Accent = component.ReplacementPrototype!;

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

private void OnDropped(EntityUid uid, AddAccentPickupComponent component, DroppedEvent args)
{
component.Holder = new EntityUid(0); // null out the component wearer entry to prevent alt verb interactions when no longer worn.
if (!component.IsActive)
return;

Expand All @@ -48,4 +52,53 @@ private void OnDropped(EntityUid uid, AddAccentPickupComponent component, Droppe

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()
{
Text = Loc.GetString("accent-clothing-component-toggle"),
Act = () => ToggleAccent(uid, component)
};
args.Verbs.Add(verb);
}

private void ToggleAccent(EntityUid uid, AddAccentPickupComponent component)
{
if (component.IsActive)
{
// try to remove the accent if it's enabled
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (EntityManager.HasComponent(component.Holder, componentType))
{
EntityManager.RemoveComponent(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?
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (HasComp(component.Holder, componentType))
return;

// 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
Expand Up @@ -235,6 +235,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 GettingPickedUpEvent(uid, entity), false); // Frontier

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

/// <summary>
/// Raised on a *mob* when it picks something up
/// </summary>
public sealed class PickupEvent : BasePickupAttemptEvent
{
public PickupEvent(EntityUid user, EntityUid item) : base(user, item) { }
}

/// <summary>
/// Raised directed at entity being picked up when someone picks it up sucessfully
/// </summary>
public sealed class GettingPickedUpEvent : BasePickupEvent
{
public GettingPickedUpEvent(EntityUid user, EntityUid item) : base(user, item) { }
}

[Virtual]
public class BasePickupEvent : CancellableEntityEventArgs
{
public readonly EntityUid User;
public readonly EntityUid Item;

public BasePickupEvent(EntityUid user, EntityUid item)
{
User = user;
Item = item;
}
}
// Fronter End
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
Loading