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,8 @@ public sealed class CloningSystem : EntitySystem
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
[Dependency] private readonly SharedJobSystem _jobs = default!;

[Dependency] private readonly ISerializationManager _serialization = default!; // Corvax-Next

public readonly Dictionary<MindComponent, EntityUid> ClonesWaitingForMind = new();
public const float EasyModeCloningCost = 0.7f;

Expand Down Expand Up @@ -215,6 +218,18 @@ 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);
}
}
// Corvax-Next End

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Content.Shared.Cloning;

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

[ViewVariables(VVAccess.ReadOnly)]
[DataField]
public bool Tall = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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.Next.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);
SubscribeLocalEvent<SizeAttributeComponent, ComponentShutdown>(OnComponentShutdown);
}
private void OnComponentShutdown(EntityUid uid, SizeAttributeComponent component, ComponentShutdown args)
{
if (!TryComp<SizeAttributeWhitelistComponent>(uid, out var whitelist))
return;

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

RemComp<SizeAttributeWhitelistComponent>(uid);
}
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, Math.Max(1, whitelist.TallScale));
}
else if (whitelist.Short && component.Short)
{
Scale(uid, component, Math.Max(Math.Min(1, whitelist.ShortScale), 0));
}
}

private void Scale(EntityUid uid, SizeAttributeComponent component, float scale)
{
if (scale <= 0f)
return;

EnsureComp<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 (TryComp(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:
break;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Content.Server.Next.Traits.Assorted
{
[RegisterComponent]
public sealed partial class SizeAttributeWhitelistComponent : Component
{
[ViewVariables(VVAccess.ReadOnly)]
[DataField("short")]
public bool Short = false;

[ViewVariables(VVAccess.ReadOnly)]
[DataField("shortscale")]
public float ShortScale = 0f;

[ViewVariables(VVAccess.ReadOnly)]
[DataField("tall")]
public bool Tall = false;

[ViewVariables(VVAccess.ReadOnly)]
[DataField("tallscale")]
public float TallScale = 0f;

}
}
9 changes: 9 additions & 0 deletions Content.Shared/_CorvaxNext/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
{
}
}
8 changes: 8 additions & 0 deletions Resources/Locale/ru-RU/_corvaxnext/traits/traits.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
trait-category-sizetraits = Рост

trait-tall-name = Высокий
trait-tall-desc = У вас проблемы с гигантизмом.

trait-short-name = Низкий
trait-short-desc = Вы коротковаты ростом.

trait-hushed-name = Тихоня
trait-hushed-desc = Вы слишком скромны и можете говорить только шёпотом.
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 @@ -217,6 +217,11 @@
- type: Targeting # _CorvaxNext: surgery
- type: SurgeryTarget # _CorvaxNext: surgery
- type: LayingDown # _CorvaxNext: LayingDown Laying Down
- type: SizeAttributeWhitelist # Corvax-Next
tall: true
tallscale: 1.1
short: true
shortscale: 0.90
- type: AutoCryoSleepable # Corvax-Next-AutoCryo

- type: entity
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
- type: FootprintVisualizer # Corvax-Next-Footprints
leftBarePrint: "footprint-left-bare-dwarf"
rightBarePrint: "footprint-right-bare-dwarf"
Expand Down
5 changes: 5 additions & 0 deletions Resources/Prototypes/_CorvaxNext/Traits/categories.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
- type: traitCategory
id: SizeTraits
name: trait-category-sizetraits
maxTraitPoints: 1

- type: traitCategory
id: MoodTraits
name: trait-category-mood
Expand Down
31 changes: 31 additions & 0 deletions Resources/Prototypes/_CorvaxNext/Traits/sizeattribute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- type: trait
id: Tall
name: trait-tall-name
description: trait-tall-desc
category: SizeTraits
cost: 1
whitelist:
components:
- SizeAttributeWhitelist
blacklist:
components:
- SizeAttribute
components:
- type: SizeAttribute
tall: true

- type: trait
id: Short
name: trait-short-name
description: trait-short-desc
category: SizeTraits
cost: 1
whitelist:
components:
- SizeAttributeWhitelist
blacklist:
components:
- SizeAttribute
components:
- type: SizeAttribute
short: true
Loading