From a02cebd1de1fee4fd6cc03d3d6a0055ad15a7134 Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 6 Aug 2024 23:40:27 +0300 Subject: [PATCH] fail experiment --- .../Placeable/ItemPlacerComponent.cs | 5 +- .../CP14ItemPlacerAutoParentComponent.cs | 9 +++ .../CP14ItemPlacerAutoParentSystem.cs | 65 +++++++++++++++++++ .../CP14ItemPlacerParentedComponent.cs | 9 +++ .../Entities/Objects/Consumable/Food/egg.yml | 1 + .../Objects/Specific/Cooking/plates.yml | 51 +++++++++++++++ Resources/Prototypes/_CP14/tags.yml | 3 + 7 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentComponent.cs create mode 100644 Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentSystem.cs create mode 100644 Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerParentedComponent.cs create mode 100644 Resources/Prototypes/_CP14/Entities/Objects/Specific/Cooking/plates.yml diff --git a/Content.Shared/Placeable/ItemPlacerComponent.cs b/Content.Shared/Placeable/ItemPlacerComponent.cs index 84df2e395a..31d1efecd0 100644 --- a/Content.Shared/Placeable/ItemPlacerComponent.cs +++ b/Content.Shared/Placeable/ItemPlacerComponent.cs @@ -1,4 +1,5 @@ -using Content.Shared.Whitelist; +using Content.Shared._CP14.ItemPlacerParenting; +using Content.Shared.Whitelist; using Robust.Shared.GameStates; namespace Content.Shared.Placeable; @@ -7,7 +8,7 @@ namespace Content.Shared.Placeable; /// Detects items placed on it that match a whitelist. /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] -[Access(typeof(ItemPlacerSystem))] +[Access(typeof(ItemPlacerSystem), typeof(CP14ItemPlacerAutoParentSystem))] public sealed partial class ItemPlacerComponent : Component { /// diff --git a/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentComponent.cs b/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentComponent.cs new file mode 100644 index 0000000000..e2bcb2ae6a --- /dev/null +++ b/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentComponent.cs @@ -0,0 +1,9 @@ +namespace Content.Shared._CP14.ItemPlacerParenting; + +/// +/// +/// +[RegisterComponent, Access(typeof(CP14ItemPlacerAutoParentSystem))] +public sealed partial class CP14ItemPlacerAutoParentComponent : Component +{ +} diff --git a/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentSystem.cs b/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentSystem.cs new file mode 100644 index 0000000000..0487c4b881 --- /dev/null +++ b/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerAutoParentSystem.cs @@ -0,0 +1,65 @@ +using Content.Shared.Movement.Pulling.Events; +using Content.Shared.Placeable; +using Content.Shared.Tag; +using Content.Shared.Throwing; +using Robust.Shared.Physics.Events; + +namespace Content.Shared._CP14.ItemPlacerParenting; + +/// +/// +/// +public sealed class CP14ItemPlacerAutoParentSystem : EntitySystem +{ + [Dependency] private readonly SharedTransformSystem _transform = default!; + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnItemPlaced); + SubscribeLocalEvent(OnThrown); + SubscribeLocalEvent(OnEndCollide); + } + + private void OnEndCollide(Entity ent, ref EndCollideEvent args) + { + if (!TryComp(ent, out var itemPlacer)) + return; + + Detach(args.OtherEntity, ent); + } + + private void Detach(EntityUid item, EntityUid parent) + { + if (Transform(item).ParentUid == parent) + _transform.SetParent(item, Transform(parent).ParentUid); + } + + private void OnThrown(Entity ent, ref ThrownEvent args) + { + if (!TryComp(ent, out var itemPlacer)) + return; + + foreach (var placed in itemPlacer.PlacedEntities) + { + Detach(placed, ent); + } + } + + private void OnItemPlaced(Entity ent, ref ItemPlacedEvent args) + { + if (HasComp(ent)) + return; + + if (!TryComp(ent, out var itemPlacer)) + return; + + _transform.SetParent(args.OtherEntity, ent); + AddComp(ent); + } + + private void Detach(EntityUid target) + { + + } +} diff --git a/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerParentedComponent.cs b/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerParentedComponent.cs new file mode 100644 index 0000000000..d3bb67bf85 --- /dev/null +++ b/Content.Shared/_CP14/ItemPlacerParenting/CP14ItemPlacerParentedComponent.cs @@ -0,0 +1,9 @@ +namespace Content.Shared._CP14.ItemPlacerParenting; + +/// +/// +/// +[RegisterComponent, Access(typeof(CP14ItemPlacerAutoParentSystem))] +public sealed partial class CP14ItemPlacerParentedComponent : Component +{ +} diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml index 8cd2fa70ee..ad065ede29 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml @@ -10,6 +10,7 @@ tags: - Egg - Meat + - CP14Platter - type: Food trash: Eggshells - type: Sprite diff --git a/Resources/Prototypes/_CP14/Entities/Objects/Specific/Cooking/plates.yml b/Resources/Prototypes/_CP14/Entities/Objects/Specific/Cooking/plates.yml new file mode 100644 index 0000000000..7b880584ec --- /dev/null +++ b/Resources/Prototypes/_CP14/Entities/Objects/Specific/Cooking/plates.yml @@ -0,0 +1,51 @@ +- type: entity + id: CP14BasePlate + abstract: true + parent: BaseItem + description: A container for storing and utilizing an essential element of life such as food. + components: + - type: Fixtures + fixtures: + fix1: + shape: + !type:PhysShapeAabb + bounds: "-0.25,-0.25,0.25,0.25" + mask: + - ItemMask + fix2: + hard: false + shape: + !type:PhysShapeAabb + bounds: "-0.25,-0.25,0.25,0.25" + layer: + - ItemMask + - type: DamageOtherOnHit + damage: + types: + Blunt: 5 + - type: CP14ItemPlacerAutoParent + - type: ItemPlacer + maxEntities: 4 + whitelist: + tags: + - CP14Platter + - type: PlaceableSurface + - type: CollisionWake + enabled: false + +- type: entity + id: CP14TestPlate + parent: CP14BasePlate + name: wooden plate + components: + - type: Sprite + sprite: Objects/Consumable/Food/plates.rsi #TODO resprite + state: plate + - type: Item + shape: + - 0,0,1,0 + storedOffset: 0,-6 + - type: DamageOnLand + damage: + types: + Blunt: 5 \ No newline at end of file diff --git a/Resources/Prototypes/_CP14/tags.yml b/Resources/Prototypes/_CP14/tags.yml index 14b7b198d8..8b05876ef4 100644 --- a/Resources/Prototypes/_CP14/tags.yml +++ b/Resources/Prototypes/_CP14/tags.yml @@ -27,3 +27,6 @@ - type: Tag id: CP14AmbientWater + +- type: Tag + id: CP14Platter \ No newline at end of file