Skip to content

Commit

Permalink
PickedUpEvent vs. GettingPickedUp, no Has then Rem
Browse files Browse the repository at this point in the history
  • Loading branch information
whatston3 committed Jan 19, 2025
1 parent 9043292 commit de1f13d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ private void ToggleAccent(EntityUid uid, AddAccentClothingComponent component)
{
// 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);
}
RemComp(component.Wearer, componentType);
component.IsActive = false;
// we don't wipe out wearer in this case
}
Expand Down
19 changes: 6 additions & 13 deletions Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public sealed class AddAccentPickupSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AddAccentPickupComponent, GettingPickedUpEvent>(OnPickup);
SubscribeLocalEvent<AddAccentPickupComponent, PickedUpEvent>(OnPickup);
SubscribeLocalEvent<AddAccentPickupComponent, DroppedEvent>(OnDropped);
SubscribeLocalEvent<AddAccentPickupComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
}

private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref GettingPickedUpEvent 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
Expand All @@ -45,10 +45,7 @@ private void OnDropped(EntityUid uid, AddAccentPickupComponent component, Droppe

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

component.IsActive = false;
}
Expand All @@ -71,22 +68,18 @@ private void OnGetAltVerbs(EntityUid uid, AddAccentPickupComponent component, Ge

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
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (EntityManager.HasComponent(component.Holder, componentType))
{
EntityManager.RemoveComponent(component.Holder, componentType);
}
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?
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (HasComp(component.Holder, componentType))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +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
RaiseLocalEvent(entity, new PickedUpEvent(uid, entity), false); // Frontier

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

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

public GettingPickedUpEvent(EntityUid user, EntityUid item)
public PickedUpEvent(EntityUid user, EntityUid item)
{
User = user;
Item = item;
Expand Down

0 comments on commit de1f13d

Please sign in to comment.