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

Merged
Merged
Changes from 15 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
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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;

@@ -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)
@@ -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;

@@ -46,4 +50,55 @@ 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;
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;
}
}
// End Frontier: togglable accents
}
59 changes: 56 additions & 3 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;

@@ -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;
@@ -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 = EntityUid.Invalid; // prevent alt verb
if (!component.IsActive)
return;

@@ -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
@@ -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;
@@ -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 GettingPickedUpEvent(uid, entity), false); // Frontier

if (log)
{
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 up when someone picks it up sucessfully
/// </summary>
public sealed class GettingPickedUpEvent : CancellableEntityEventArgs
{
public readonly EntityUid User;
public readonly EntityUid Item;

public GettingPickedUpEvent(EntityUid user, EntityUid item)
{
User = user;
Item = item;
}
}
5 changes: 4 additions & 1 deletion Resources/Locale/en-US/_NF/accent/accents.ftl
Original file line number Diff line number Diff line change
@@ -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