Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port frontier station 14's sizeattribute system #965

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Content.Server/Cloning/CloningSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server._NF.Cloning;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Chat.Systems;
using Content.Server.Cloning.Components;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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<MindComponent, EntityUid> ClonesWaitingForMind = new();
public const float EasyModeCloningCost = 0.7f;
Expand Down Expand Up @@ -248,11 +252,22 @@ public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Entity<MindComponen
}
// end of genetic damage checks

var mob = FetchAndSpawnMob(clonePod, pref, speciesPrototype, humanoid, bodyToClone, karmaBonus); //DeltaV Replaces CloneAppearance with Metem/Clone via FetchAndSpawnMob
var mob = FetchAndSpawnMob(clonePod, pref, speciesPrototype, humanoid, bodyToClone, karmaBonus); //DeltaV Replaces CloneAppearance with Metem/Clone via FetchAndSpawnMob

///Nyano - Summary: adds the potential psionic trait to the reanimated mob.
EnsureComp<PotentialPsionicComponent>(mob);

// Frontier - transfer of special components, e.g. small/big traits
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need you to move "Transfer of Special Components" down into the FetchAndSpawnMob function, and then split it into two different conditions. We don't actually have Wizden cloning, we instead have a hybrid system that handles both Cloning and Metempsychosis based on checking for a bool. By placing this function up here, you are essentially making it so that when someone is reincarnated into a new body by the Metem machine, it transfers their tallness/shortness from old body to new body. Which is a big problem if for example their old body was a small vulpkanin and the new body is an Oni.

This instead needs to be done only if the entity was cloned and not reincarnated. If they are instead reincarnated, an alternative behavior needs to be performed where it has a random chance of giving them the tallness/shortness(I would say at most 10% tall, 10% short, 80% normal).

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);

Expand Down
8 changes: 8 additions & 0 deletions Content.Server/_NF/Cloning/ITransferredByCloning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Content.Server._NF.Cloning;

/// <summary>
/// Indicates that this Component should be transferred to the new entity when the entity is cloned (for example, using a cloner)
/// </summary>
public interface ITransferredByCloning
{
}
14 changes: 14 additions & 0 deletions Content.Server/_NF/SizeAttribute/SizeAttributeComponent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
95 changes: 95 additions & 0 deletions Content.Server/_NF/SizeAttribute/SizeAttributeSystem.cs
Original file line number Diff line number Diff line change
@@ -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<SizeAttributeComponent, ComponentInit>(OnComponentInit);
}

private void OnComponentInit(EntityUid uid, SizeAttributeComponent component, ComponentInit args)
{
if (!TryComp<SizeAttributeWhitelistComponent>(uid, out var whitelist))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since by introducing this system to Metempsychosis means having the possibility for entities to be handed a SizeAttribute after character creation, you now need to account for SizeAttribute being handed to an entity that potentially doesn't have SizeAttributeWhitelist. Since we're exiting out if a species isn't whitelisted for SizeAttribute, you might as well cleanup by RemComping the component if for whatever reason it was handed to a species lacking the whitelist. That will also be useful if for example someone hits AddComponent in VV without first doing so with SizeAttributeWhitelist.

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<Box2i>? shape = null)
{
if (active)
{
var pseudoItem = EnsureComp<PseudoItemComponent>(uid);
pseudoItem.Shape = shape;
}
else
{
if (!TryComp<PseudoItemComponent>(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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to do
if (scale <= 0f | density <= 0f) return;
since && only returns if both scale and density aren't a natural number at the same time. Scale could be a negative number and density any natural number, and the function would continue as normal. Which would produce huge problems since we don't want to accidentally mirror people's character models in the case of a negative scale being put in somewhere. Keep in mind that the compiler doesn't actually know that having negative inputs for scale isn't acceptable, since it's technically possible and won't throw any errors.

Alternatively you could put in a check for if scale is a negative number, and then set it to *= -1 to get a natural number again.

return;

_entityManager.EnsureComponent<ScaleVisualsComponent>(uid);

var appearanceComponent = _entityManager.EnsureComponent<AppearanceComponent>(uid);
if (!_appearance.TryGetData<Vector2>(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) { }
}
Original file line number Diff line number Diff line change
@@ -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
/// <summary>
/// An optional override for the shape of the item within the grid storage.
/// If null, a default shape will be used based on <see cref="Size"/>.
/// </summary>
[DataField("pseudoItemShape")]
public List<Box2i>? 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;
}
}
10 changes: 10 additions & 0 deletions Resources/Prototypes/DeltaV/Entities/Mobs/Species/vulpkanin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
Female: FemaleVulpkanin
Unsexed: MaleVulpkanin
- type: DogVision
- type: SizeAttributeWhitelist # Frontier - tall/short traits
short: true
shortscale: 0.8
shortDensity: 140
shortPseudoItem: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Felinid mains are going to be upset when they find out Smol dogs have their gimmick too LOL. If you're going to do this to Vulps, you might as well do this to Harpies too.

shortCosmeticOnly: false
pseudoItemShape: # Delta-v - custom pseudo-item shape
- 0,0,1,4
- 0,2,3,4
- 4,0,5,4

- type: entity
save: false
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/reptilian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions Resources/Prototypes/_NF/Traits/sizeattribute.yml
Original file line number Diff line number Diff line change
@@ -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
Loading