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

Traits for roundstart species size #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
15 changes: 15 additions & 0 deletions Content.Server/Cloning/CloningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;

namespace Content.Server.Cloning
{
Expand Down Expand Up @@ -61,6 +62,9 @@ public sealed class CloningSystem : EntitySystem
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
[Dependency] private readonly SharedJobSystem _jobs = default!;

// corvax-next
[Dependency] private readonly ISerializationManager _serialization = default!;

lzk228 marked this conversation as resolved.
Show resolved Hide resolved
public readonly Dictionary<MindComponent, EntityUid> ClonesWaitingForMind = new();
public const float EasyModeCloningCost = 0.7f;

Expand Down Expand Up @@ -213,6 +217,17 @@ public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Entity<MindComponen
var mob = Spawn(speciesPrototype.Prototype, _transformSystem.GetMapCoordinates(uid));
_humanoidSystem.CloneAppearance(bodyToClone, mob);

// corvax-next
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);
}
}
KillanGenifer marked this conversation as resolved.
Show resolved Hide resolved

var ev = new CloningEvent(bodyToClone, mob);
RaiseLocalEvent(bodyToClone, ref ev);

Expand Down
14 changes: 14 additions & 0 deletions Content.Server/Traits/Assorted/SizeAttributeComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Content.Shared.Cloning;

namespace Content.Server.Traits.Assorted
{
[RegisterComponent]
public sealed partial class SizeAttributeComponent : Component, ITransferredByCloning
{
[DataField("short")]
public bool Short = false;

[DataField("tall")]
public bool Tall = false;
}
}
67 changes: 67 additions & 0 deletions Content.Server/Traits/Assorted/SizeAttributeSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Robust.Server.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Systems;
using System.Numerics;

namespace Content.Server.Traits.Assorted
{
public sealed class SizeAttributeSystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly AppearanceSystem _appearance = 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))
return;

if (whitelist.Tall && component.Tall)
{
Scale(uid, component, whitelist.TallScale);
}
else if (whitelist.Short && component.Short)
{
Scale(uid, component, whitelist.ShortScale);
}
}

private void Scale(EntityUid uid, SizeAttributeComponent component, float scale)
{
if (scale <= 0f)
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 (_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();
}
}
}
}
}
}
19 changes: 19 additions & 0 deletions Content.Server/Traits/Assorted/SizeAttributeWhitelistComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Content.Server.Traits.Assorted
{
[RegisterComponent]
public sealed partial class SizeAttributeWhitelistComponent : Component
{
[DataField("short")]
public bool Short = false;

[DataField("shortscale")]
public float ShortScale = 0f;

[DataField("tall")]
public bool Tall = false;

[DataField("tallscale")]
public float TallScale = 0f;

}
}
9 changes: 9 additions & 0 deletions Content.Shared/Cloning/ITransferredByCloning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Shared.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
{
}
}
5 changes: 5 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@
- CanPilot
- FootstepSound
- DoorBumpOpener
- type: SizeAttributeWhitelist # corvax-next
tall: true
tallscale: 1.1
short: true
shortscale: 0.90
KillanGenifer marked this conversation as resolved.
Show resolved Hide resolved

- type: entity
save: false
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/dwarf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
32:
sprite: Mobs/Species/Human/displacement.rsi
state: jumpsuit-female
- type: SizeAttributeWhitelist # corvax-next
tall: false
short: false
KillanGenifer marked this conversation as resolved.
Show resolved Hide resolved

- type: entity
parent: BaseSpeciesDummy
Expand Down
5 changes: 5 additions & 0 deletions Resources/Prototypes/Traits/categories.yml
KillanGenifer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
- type: traitCategory
id: Quirks
name: trait-category-quirks

- type: traitCategory # corvax-next
id: SizeTraits
name: Рост
maxTraitPoints: 1
lzk228 marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions Resources/Prototypes/Traits/sizeattribute.yml
lzk228 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- type: trait # corvax-next
id: Tall
name: Высокий
description: У вас проблемы с гигантизмом.
category: SizeTraits
cost: 1
whitelist:
components:
- SizeAttributeWhitelist
blacklist:
components:
- SizeAttribute
components:
- type: SizeAttribute
tall: true

- type: trait
id: Short
name: Низкий
description: Вы коротковаты ростом.
category: SizeTraits
cost: 1
whitelist:
components:
- SizeAttributeWhitelist
blacklist:
components:
- SizeAttribute
components:
- type: SizeAttribute
short: true