Toy Box filled with toys (ready for merge) (#16252)
This commit is contained in:
61
Content.Server/Glue/GlueSystem.cs
Normal file
61
Content.Server/Glue/GlueSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Interaction.Components;
|
||||
using Content.Shared.Glue;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Server.Nutrition.Components;
|
||||
|
||||
namespace Content.Server.Glue
|
||||
{
|
||||
public sealed class GlueSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly FoodSystem _food = default!;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GlueComponent, AfterInteractEvent>(OnInteract);
|
||||
}
|
||||
|
||||
// When glue bottle is used on item it will apply the glued and unremoveable components.
|
||||
private void OnInteract(EntityUid uid, GlueComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!args.CanReach || args.Target is not { Valid: true } target)
|
||||
return;
|
||||
|
||||
if (HasComp<GluedComponent>(target))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("glue-failure", ("target", Identity.Entity(target, EntityManager))), args.User,
|
||||
args.User, PopupType.Medium);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (HasComp<ItemComponent>(target))
|
||||
{
|
||||
_audio.PlayPvs(component.Squeeze, uid);
|
||||
EnsureComp<UnremoveableComponent>(target);
|
||||
_popup.PopupEntity(Loc.GetString("glue-success", ("target", Identity.Entity(target, EntityManager))), args.User,
|
||||
args.User, PopupType.Medium);
|
||||
EnsureComp<GluedComponent>(target);
|
||||
}
|
||||
|
||||
if (TryComp<FoodComponent>(uid, out var food))
|
||||
{
|
||||
_food.DeleteAndSpawnTrash(food, uid, args.User);
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
64
Content.Server/Glue/GluedSystem.cs
Normal file
64
Content.Server/Glue/GluedSystem.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Content.Shared.Interaction.Components;
|
||||
using Robust.Shared.Timing;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Glue;
|
||||
using Content.Shared.Hands.Components;
|
||||
|
||||
namespace Content.Server.Glue;
|
||||
|
||||
public sealed class GluedSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GluedComponent, ComponentInit>(OnGluedInit);
|
||||
SubscribeLocalEvent<GluedComponent, InteractHandEvent>(OnPickUp);
|
||||
}
|
||||
|
||||
// Timing to remove glued and unremoveable.
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
|
||||
var query = EntityQueryEnumerator<GluedComponent>();
|
||||
while (query.MoveNext(out var uid, out var glue))
|
||||
{
|
||||
if (!glue.GlueBroken || glue.Glued)
|
||||
continue;
|
||||
|
||||
if (_timing.CurTime < glue.GlueTime)
|
||||
continue;
|
||||
|
||||
glue.Glued = false;
|
||||
glue.GlueBroken = false;
|
||||
MetaData(uid).EntityName = glue.BeforeGluedEntityName;
|
||||
RemComp<UnremoveableComponent>(uid);
|
||||
RemComp<GluedComponent>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
//Adds the prefix on init.
|
||||
private void OnGluedInit(EntityUid uid, GluedComponent component, ComponentInit args)
|
||||
{
|
||||
var meta = MetaData(uid);
|
||||
var name = meta.EntityName;
|
||||
component.BeforeGluedEntityName = meta.EntityName;
|
||||
meta.EntityName = Loc.GetString("glued-name-prefix", ("target", name));
|
||||
}
|
||||
|
||||
// Timers start only when the glued item is picked up.
|
||||
private void OnPickUp(EntityUid uid, GluedComponent component, InteractHandEvent args)
|
||||
{
|
||||
var userHands = Comp<HandsComponent>(args.User);
|
||||
if (userHands.ActiveHandEntity == uid)
|
||||
{
|
||||
component.GlueBroken = true;
|
||||
component.GlueTime = _timing.CurTime + component.GlueCooldown;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user