Better glue (#17381)

This commit is contained in:
Slava0135
2023-06-30 22:07:44 +03:00
committed by GitHub
parent 0ad77202b8
commit aadcc48ddc
11 changed files with 148 additions and 169 deletions

View File

@@ -1,59 +1,106 @@
using Content.Shared.IdentityManagement; using Content.Shared.IdentityManagement;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Interaction.Components;
using Content.Shared.Glue; using Content.Shared.Glue;
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Nutrition.Components; using Content.Server.Nutrition.Components;
using Content.Shared.Hands;
using Robust.Shared.Timing;
using Content.Shared.Interaction.Components;
namespace Content.Server.Glue namespace Content.Server.Glue;
public sealed class GlueSystem : SharedGlueSystem
{ {
public sealed class GlueSystem : EntitySystem [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
public override void Initialize()
{ {
[Dependency] private readonly SharedAudioSystem _audio = default!; base.Initialize();
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly FoodSystem _food = default!;
SubscribeLocalEvent<GlueComponent, AfterInteractEvent>(OnInteract);
SubscribeLocalEvent<GluedComponent, ComponentInit>(OnGluedInit);
SubscribeLocalEvent<GluedComponent, GotEquippedHandEvent>(OnHandPickUp);
}
public override void Initialize() // 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 (TryComp<DrinkComponent>(uid, out var drink) && !drink.Opened)
{ {
base.Initialize(); return;
SubscribeLocalEvent<GlueComponent, AfterInteractEvent>(OnInteract);
} }
// When glue bottle is used on item it will apply the glued and unremoveable components. if (TryGlue(uid, component, target))
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);
_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; args.Handled = true;
_audio.PlayPvs(component.Squeeze, uid);
_popup.PopupEntity(Loc.GetString("glue-success", ("target", target)), args.User, args.User, PopupType.Medium);
}
else
{
_popup.PopupEntity(Loc.GetString("glue-failure", ("target", target)), args.User, args.User, PopupType.Medium);
}
}
private bool TryGlue(EntityUid uid, GlueComponent component, EntityUid target)
{
// if item is glued then don't apply glue again so it can be removed for reasonable time
if (HasComp<GluedComponent>(target) || !HasComp<ItemComponent>(target))
{
return false;
} }
if (HasComp<ItemComponent>(target) && _solutionContainer.TryGetSolution(uid, component.Solution, out var solution))
{
var quantity = solution.RemoveReagent(component.Reagent, component.ConsumptionUnit);
if (quantity > 0)
{
EnsureComp<GluedComponent>(target).Duration = quantity.Double() * component.DurationPerUnit;
return true;
}
}
return false;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<GluedComponent, UnremoveableComponent>();
while (query.MoveNext(out var uid, out var glue, out _))
{
if (_timing.CurTime < glue.Until)
continue;
_metaData.SetEntityName(uid, glue.BeforeGluedEntityName);
RemComp<UnremoveableComponent>(uid);
RemComp<GluedComponent>(uid);
}
}
private void OnGluedInit(EntityUid uid, GluedComponent component, ComponentInit args)
{
var meta = MetaData(uid);
var name = meta.EntityName;
component.BeforeGluedEntityName = meta.EntityName;
_metaData.SetEntityName(uid, Loc.GetString("glued-name-prefix", ("target", name)));
}
private void OnHandPickUp(EntityUid uid, GluedComponent component, GotEquippedHandEvent args)
{
EnsureComp<UnremoveableComponent>(uid);
component.Until = _timing.CurTime + component.Duration;
} }
} }

View File

@@ -1,60 +0,0 @@
using Content.Shared.Interaction.Components;
using Robust.Shared.Timing;
using Content.Shared.Glue;
using Content.Shared.Hands;
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, GotEquippedHandEvent>(OnHandPickUp);
}
// 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 OnHandPickUp(EntityUid uid, GluedComponent component, GotEquippedHandEvent args)
{
EnsureComp<UnremoveableComponent>(uid);
component.GlueBroken = true;
component.GlueTime = _timing.CurTime + component.GlueCooldown;
}
}

View File

@@ -1,15 +1,42 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Glue namespace Content.Shared.Glue;
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedGlueSystem))]
public sealed class GlueComponent : Component
{ {
[RegisterComponent, NetworkedComponent] /// <summary>
public sealed class GlueComponent : Component /// Noise made when glue applied.
{ /// </summary>
/// <summary> [DataField("squeeze")]
/// Noise made when glue applied. public SoundSpecifier Squeeze = new SoundPathSpecifier("/Audio/Items/squeezebottle.ogg");
/// </summary>
[DataField("squeeze")] /// <summary>
public SoundSpecifier Squeeze = new SoundPathSpecifier("/Audio/Items/squeezebottle.ogg"); /// Solution on the entity that contains the glue.
} /// </summary>
[DataField("solution")]
public string Solution = "drink";
/// <summary>
/// Reagent that will be used as glue.
/// </summary>
[DataField("reagent", customTypeSerializer: typeof(PrototypeIdSerializer<ReagentPrototype>))]
public string Reagent = "SpaceGlue";
/// <summary>
/// Reagent consumption per use.
/// </summary>
[DataField("consumptionUnit"), ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 ConsumptionUnit = FixedPoint2.New(5);
/// <summary>
/// Duration per unit
/// </summary>
[DataField("durationPerUnit"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan DurationPerUnit = TimeSpan.FromSeconds(6);
} }

View File

@@ -1,42 +1,20 @@
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Glue; namespace Content.Shared.Glue;
[RegisterComponent] [RegisterComponent]
[Access(typeof(SharedGlueSystem))]
public sealed class GluedComponent : Component public sealed class GluedComponent : Component
{ {
/// <summary> /// <summary>
/// Reverts name to before prefix event (essentially removes prefix). /// Reverts name to before prefix event (essentially removes prefix).
/// </summary> /// </summary>
[DataField("beforeGluedEntityName"), ViewVariables(VVAccess.ReadOnly)] [DataField("beforeGluedEntityName"), ViewVariables(VVAccess.ReadOnly)]
public string BeforeGluedEntityName = String.Empty; public string BeforeGluedEntityName = string.Empty;
/// <summary> [DataField("until", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
/// Sound made when glue applied. public TimeSpan Until;
/// </summary>
[DataField("squeeze")]
public SoundSpecifier Squeeze = new SoundPathSpecifier("/Audio/Items/squeezebottle.ogg");
/// <summary> [DataField("duration", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
/// Timings for glue duration and removal. public TimeSpan Duration;
/// </summary>
[DataField("nextGlueTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan? NextGlueTime;
[DataField("glueTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan GlueTime = TimeSpan.Zero;
[DataField("glueCooldown")]
public TimeSpan GlueCooldown = TimeSpan.FromSeconds(20);
/// <summary>
/// Bools which control timings and when to apply the glue effect.
/// </summary>
public bool GlueBroken = false;
[DataField("glued")]
[ViewVariables(VVAccess.ReadWrite)]
public bool Glued = false;
} }

View File

@@ -0,0 +1,5 @@
namespace Content.Shared.Glue;
public abstract class SharedGlueSystem : EntitySystem
{
}

View File

@@ -1,3 +1,3 @@
glue-success = {THE($target)} has been covered in glue. glue-success = {THE($target)} has been covered in glue!
glued-name-prefix = Glued {$target} glued-name-prefix = Glued {$target}
glue-failure = {THE($target)} is already covered in glue. glue-failure = Can't cover {THE($target)} in glue!

View File

@@ -19,6 +19,7 @@
- state: icon-front - state: icon-front
map: [ "enum.SolutionContainerLayers.Overlay" ] map: [ "enum.SolutionContainerLayers.Overlay" ]
- type: Appearance - type: Appearance
- type: Glue
- type: SolutionContainerManager - type: SolutionContainerManager
solutions: solutions:
drink: drink:

View File

@@ -1144,43 +1144,27 @@
Quantity: 100 Quantity: 100
- type: entity - type: entity
parent: FoodProduceBase parent: DrinkBase
id: CrazyGlue id: CrazyGlue
name: crazy glue name: crazy glue
description: A bottle of crazy glue manufactured by Honk! Co. description: A bottle of crazy glue manufactured by Honk! Co.
components: components:
- type: FlavorProfile - type: Drink
flavors: isOpen: false
- glue openSounds:
- type: Food collection: packetOpenSounds
trash: CrazyGlueEmpty
- type: Sprite - type: Sprite
sprite: Objects/Fun/glue.rsi sprite: Objects/Fun/glue.rsi
state: icon-0 state: icon
- type: Appearance - type: Appearance
- type: Glue - type: Glue
consumptionUnit: 10
- type: Item - type: Item
sprite: Objects/Fun/glue.rsi sprite: Objects/Fun/glue.rsi
- type: SolutionContainerManager - type: SolutionContainerManager
solutions: solutions:
food: drink:
maxVol: 15 maxVol: 100
reagents: reagents:
- ReagentId: SpaceGlue - ReagentId: SpaceGlue
Quantity: 6 Quantity: 100
- type: entity
name: empty crazy glue
parent: BaseItem
id: CrazyGlueEmpty
components:
- type: Sprite
sprite: Objects/Fun/glue.rsi
state: icon-1
- type: Item
sprite: Objects/Fun/glue.rsi
- type: Tag
tags:
- Recyclable
- Trash
- type: SpaceGarbage

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -8,10 +8,7 @@
}, },
"states": [ "states": [
{ {
"name": "icon-0" "name": "icon"
},
{
"name": "icon-1"
}, },
{ {
"name": "inhand-left", "name": "inhand-left",