From 4678e8d058f3aca58530f8fe1f343adc1cc28afb Mon Sep 17 00:00:00 2001 From: fox Date: Thu, 14 Mar 2024 23:11:51 +0300 Subject: [PATCH 1/2] Ported everything --- Content.Server/Cloning/CloningSystem.cs | 17 +++- .../_NF/Cloning/ITransferredByCloning.cs | 8 ++ .../SizeAttribute/SizeAttributeComponent.cs | 14 +++ .../_NF/SizeAttribute/SizeAttributeSystem.cs | 95 +++++++++++++++++++ .../SizeAttributeWhitelistComponent.cs | 48 ++++++++++ .../Entities/Mobs/Species/vulpkanin.yml | 9 ++ .../Entities/Mobs/Species/reptilian.yml | 3 + .../Entities/Mobs/Species/felinid.yml | 3 + .../Prototypes/_NF/Traits/sizeattribute.yml | 25 +++++ 9 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 Content.Server/_NF/Cloning/ITransferredByCloning.cs create mode 100644 Content.Server/_NF/SizeAttribute/SizeAttributeComponent.cs create mode 100644 Content.Server/_NF/SizeAttribute/SizeAttributeSystem.cs create mode 100644 Content.Server/_NF/SizeAttribute/SizeAttributeWhitelistComponent.cs create mode 100644 Resources/Prototypes/_NF/Traits/sizeattribute.yml diff --git a/Content.Server/Cloning/CloningSystem.cs b/Content.Server/Cloning/CloningSystem.cs index 00612833676..7a17b03e7eb 100644 --- a/Content.Server/Cloning/CloningSystem.cs +++ b/Content.Server/Cloning/CloningSystem.cs @@ -1,3 +1,4 @@ +using Content.Server._NF.Cloning; using Content.Server.Atmos.EntitySystems; using Content.Server.Chat.Systems; using Content.Server.Cloning.Components; @@ -49,6 +50,8 @@ using Content.Shared.SSDIndicator; using Content.Shared.Damage.ForceSay; using Content.Server.Polymorph.Components; +using Content.Server._NF.Cloning; //Frontier - needed for implementation of ITransferredByCloning +using Robust.Shared.Serialization.Manager; // Frontier namespace Content.Server.Cloning { @@ -78,6 +81,7 @@ public sealed class CloningSystem : EntitySystem [Dependency] private readonly SharedJobSystem _jobs = default!; [Dependency] private readonly MetempsychoticMachineSystem _metem = default!; //DeltaV [Dependency] private readonly TagSystem _tag = default!; //DeltaV + [Dependency] private readonly ISerializationManager _serialization = default!; //Frontier -> deltav public readonly Dictionary ClonesWaitingForMind = new(); public const float EasyModeCloningCost = 0.7f; @@ -248,11 +252,22 @@ public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Entity(mob); + // Frontier - transfer of special components, e.g. small/big traits + foreach (var comp in EntityManager.GetComponents(bodyToClone)) + { + if (comp is ITransferredByCloning) + { + var copy = _serialization.CreateCopy(comp, notNullableOverride: true); + copy.Owner = mob; + EntityManager.AddComponent(mob, copy, overwrite: true); + } + } + var ev = new CloningEvent(bodyToClone, mob); RaiseLocalEvent(bodyToClone, ref ev); diff --git a/Content.Server/_NF/Cloning/ITransferredByCloning.cs b/Content.Server/_NF/Cloning/ITransferredByCloning.cs new file mode 100644 index 00000000000..77be714eb0e --- /dev/null +++ b/Content.Server/_NF/Cloning/ITransferredByCloning.cs @@ -0,0 +1,8 @@ +namespace Content.Server._NF.Cloning; + +/// +/// Indicates that this Component should be transferred to the new entity when the entity is cloned (for example, using a cloner) +/// +public interface ITransferredByCloning +{ +} diff --git a/Content.Server/_NF/SizeAttribute/SizeAttributeComponent.cs b/Content.Server/_NF/SizeAttribute/SizeAttributeComponent.cs new file mode 100644 index 00000000000..a6b6d176c2e --- /dev/null +++ b/Content.Server/_NF/SizeAttribute/SizeAttributeComponent.cs @@ -0,0 +1,14 @@ +using Content.Server._NF.Cloning; + +namespace Content.Server._NF.SizeAttribute +{ + [RegisterComponent] + public sealed partial class SizeAttributeComponent : Component, ITransferredByCloning + { + [DataField("short")] + public bool Short = false; + + [DataField("tall")] + public bool Tall = false; + } +} diff --git a/Content.Server/_NF/SizeAttribute/SizeAttributeSystem.cs b/Content.Server/_NF/SizeAttribute/SizeAttributeSystem.cs new file mode 100644 index 00000000000..7927d711a11 --- /dev/null +++ b/Content.Server/_NF/SizeAttribute/SizeAttributeSystem.cs @@ -0,0 +1,95 @@ +using System.Numerics; +using Content.Server.SizeAttribute; +using Robust.Server.GameObjects; +using Robust.Shared.Physics; +using Robust.Shared.Physics.Collision.Shapes; +using Robust.Shared.Physics.Systems; +using Content.Shared.Item.PseudoItem; +using Content.Shared.Nyanotrasen.Item.PseudoItem; + +namespace Content.Server._NF.SizeAttribute +{ + public sealed class SizeAttributeSystem : EntitySystem + { + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; + [Dependency] private readonly AppearanceSystem _appearance = default!; + [Dependency] private readonly FixtureSystem _fixtures = default!; + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnComponentInit); + } + + private void OnComponentInit(EntityUid uid, SizeAttributeComponent component, ComponentInit args) + { + if (!TryComp(uid, out var whitelist)) + return; + + if (whitelist.Tall && component.Tall) + { + Scale(uid, component, whitelist.TallScale, whitelist.TallDensity, whitelist.TallCosmeticOnly); + PseudoItem(uid, component, whitelist.TallPseudoItem); + } + else if (whitelist.Short && component.Short) + { + Scale(uid, component, whitelist.ShortScale, whitelist.ShortDensity, whitelist.ShortCosmeticOnly); + // deltav: added PseudoItemShape + PseudoItem(uid, component, whitelist.ShortPseudoItem, whitelist.PseudoItemShape); + } + } + + // deltav: added a shape argument and refactored the method + private void PseudoItem(EntityUid uid, SizeAttributeComponent component, bool active, List? shape = null) + { + if (active) + { + var pseudoItem = EnsureComp(uid); + pseudoItem.Shape = shape; + } + else + { + if (!TryComp(uid, out var pseudoI)) + return; + RemComp(uid, pseudoI); + } + } + + private void Scale(EntityUid uid, SizeAttributeComponent component, float scale, float density, bool cosmeticOnly) + { + if (scale <= 0f && density <= 0f) + return; + + _entityManager.EnsureComponent(uid); + + var appearanceComponent = _entityManager.EnsureComponent(uid); + if (!_appearance.TryGetData(uid, ScaleVisuals.Scale, out var oldScale, appearanceComponent)) + oldScale = Vector2.One; + + _appearance.SetData(uid, ScaleVisuals.Scale, oldScale * scale, appearanceComponent); + + if (!cosmeticOnly && _entityManager.TryGetComponent(uid, out FixturesComponent? manager)) + { + foreach (var (id, fixture) in manager.Fixtures) + { + if (!fixture.Hard || fixture.Density <= 1f) + continue; // This will skip the flammable fixture and any other fixture that is not supposed to contribute to mass + + switch (fixture.Shape) + { + case PhysShapeCircle circle: + _physics.SetPositionRadius(uid, id, fixture, circle, circle.Position * scale, circle.Radius * scale, manager); + break; + default: + throw new NotImplementedException(); + } + + _physics.SetDensity(uid, id, fixture, density); + } + } + } + } + + [ByRefEvent] + public readonly record struct ScaleEntityEvent(EntityUid Uid) { } +} diff --git a/Content.Server/_NF/SizeAttribute/SizeAttributeWhitelistComponent.cs b/Content.Server/_NF/SizeAttribute/SizeAttributeWhitelistComponent.cs new file mode 100644 index 00000000000..746183069c3 --- /dev/null +++ b/Content.Server/_NF/SizeAttribute/SizeAttributeWhitelistComponent.cs @@ -0,0 +1,48 @@ +using Robust.Shared.Physics.Collision.Shapes; + +namespace Content.Server.SizeAttribute +{ + [RegisterComponent] + public sealed partial class SizeAttributeWhitelistComponent : Component + { + // Short + [DataField("short")] + public bool Short = false; + + [DataField("shortscale")] + public float ShortScale = 0f; + + [DataField("shortDensity")] + public float ShortDensity = 0f; + + [DataField("shortPseudoItem")] + public bool ShortPseudoItem = false; + + [DataField("shortCosmeticOnly")] + public bool ShortCosmeticOnly = true; + + // Delta-v: added custom pseudo-item shape + /// + /// An optional override for the shape of the item within the grid storage. + /// If null, a default shape will be used based on . + /// + [DataField("pseudoItemShape")] + public List? PseudoItemShape; + + // Tall + [DataField("tall")] + public bool Tall = false; + + [DataField("tallscale")] + public float TallScale = 0f; + + [DataField("tallDensity")] + public float TallDensity = 0f; + + [DataField("tallPseudoItem")] + public bool TallPseudoItem = false; + + [DataField("tallCosmeticOnly")] + public bool TallCosmeticOnly = true; + } +} diff --git a/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml b/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml index 4a187d51b33..d75f3964550 100644 --- a/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml +++ b/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml @@ -97,6 +97,15 @@ Female: FemaleVulpkanin Unsexed: MaleVulpkanin - type: DogVision + - type: SizeAttributeWhitelist # Frontier - tall/short traits + short: true + shortscale: 0.8 + shortDensity: 140 + shortPseudoItem: true + pseudoItemShape: # Delta-v - custom pseudo-item shape + - 0,0,1,4 + - 0,2,3,4 + - 4,0,5,4 - type: entity save: false diff --git a/Resources/Prototypes/Entities/Mobs/Species/reptilian.yml b/Resources/Prototypes/Entities/Mobs/Species/reptilian.yml index c893fab4491..38a0af92f96 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/reptilian.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/reptilian.yml @@ -59,6 +59,9 @@ types: Heat : 1.5 #per second, scales with temperature & other constants - type: Wagging + - type: SizeAttributeWhitelist # Frontier - tall/short traits (cosmetic-only) + tall: true + tallscale: 1.2 - type: entity parent: BaseSpeciesDummy diff --git a/Resources/Prototypes/Nyanotrasen/Entities/Mobs/Species/felinid.yml b/Resources/Prototypes/Nyanotrasen/Entities/Mobs/Species/felinid.yml index d9b25c5dd1b..bce6690ce8f 100644 --- a/Resources/Prototypes/Nyanotrasen/Entities/Mobs/Species/felinid.yml +++ b/Resources/Prototypes/Nyanotrasen/Entities/Mobs/Species/felinid.yml @@ -64,6 +64,9 @@ Unsexed: MaleFelinid - type: Felinid - type: NoShoesSilentFootsteps + - type: SizeAttributeWhitelist # Frontier - tall/short traits (cosmetic-only, but does remove pseudo-item) + tall: true + tallscale: 1 - type: entity save: false diff --git a/Resources/Prototypes/_NF/Traits/sizeattribute.yml b/Resources/Prototypes/_NF/Traits/sizeattribute.yml new file mode 100644 index 00000000000..534e490d450 --- /dev/null +++ b/Resources/Prototypes/_NF/Traits/sizeattribute.yml @@ -0,0 +1,25 @@ +- type: trait + id: Tall + name: Tall + whitelist: + components: + - SizeAttributeWhitelist + blacklist: + components: + - SizeAttribute + components: + - type: SizeAttribute + tall: true + +- type: trait + id: Short + name: Short + whitelist: + components: + - SizeAttributeWhitelist + blacklist: + components: + - SizeAttribute + components: + - type: SizeAttribute + short: true From 599e23fd244f4113c472aa306075d3d1a754a23f Mon Sep 17 00:00:00 2001 From: fox Date: Thu, 14 Mar 2024 23:30:18 +0300 Subject: [PATCH 2/2] Forgot --- Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml b/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml index d75f3964550..b6a685c5036 100644 --- a/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml +++ b/Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml @@ -102,6 +102,7 @@ shortscale: 0.8 shortDensity: 140 shortPseudoItem: true + shortCosmeticOnly: false pseudoItemShape: # Delta-v - custom pseudo-item shape - 0,0,1,4 - 0,2,3,4