Skip to content

Commit

Permalink
Фиксы и добавления черт: Низкий, Высокий (#205)
Browse files Browse the repository at this point in the history
<!-- ЭТО ШАБЛОН ВАШЕГО PULL REQUEST. Текст между стрелками - это
комментарии - они не будут видны в PR. -->

## Описание PR
<!-- Ниже опишите ваш Pull Request. Что он изменяет? На что еще это
может повлиять? Постарайтесь описать все внесённые вами изменения! -->

**Проверки**
<!-- Выполнение всех следующих действий, если это приемлемо для вида
изменений сильно ускорит разбор вашего PR -->
- [ ] PR полностью завершён и мне не нужна помощь чтобы его закончить.
- [ ] Я внимательно просмотрел все свои изменения и багов в них не
нашёл.
- [ ] Я запускал локальный сервер со своими изменениями и всё
протестировал.
- [ ] Я добавил скриншот/видео демонстрации PR в игре, **или** этот PR
этого не требует.

**Изменения**

:cl: Шрёдька
- fix: Починил систему роста.
- tweak: Добавлена новая категория в черты: Рост.
  • Loading branch information
Schrodinger71 authored Aug 8, 2024
1 parent ec65ab9 commit a8f3116
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 12 deletions.
14 changes: 14 additions & 0 deletions Content.Server/ADT/SizeAttribute/SizeAttributeComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Content.Shared.Cloning;

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

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

namespace Content.Server.ADT.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))
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);
PseudoItem(uid, component, whitelist.ShortPseudoItem);
}
}

private void PseudoItem(EntityUid uid, SizeAttributeComponent component, bool active)
{
if (active)
{
if (TryComp<PseudoItemComponent>(uid, out var pseudoI))
return;

_entityManager.AddComponent<PseudoItemComponent>(uid);
}
else
{
if (!TryComp<PseudoItemComponent>(uid, out var pseudoI))
return;

_entityManager.RemoveComponent<PseudoItemComponent>(uid);
}
}

private void Scale(EntityUid uid, SizeAttributeComponent component, float scale, float density, bool cosmeticOnly)
{
if (scale <= 0f && density <= 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 (!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
@@ -1,6 +1,6 @@
using Robust.Shared.Physics.Collision.Shapes;

namespace Content.Server.SizeAttribute
namespace Content.Server.ADT.SizeAttribute
{
[RegisterComponent]
public sealed partial class SizeAttributeWhitelistComponent : Component
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/ADT/Cloning/ITransferredByCloning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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
{
}
19 changes: 19 additions & 0 deletions Content.Shared/ADT/Item/PseudoItemComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Content.Shared.Cloning;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.Item.PseudoItem;
/// <summary>
/// For entities that behave like an item under certain conditions,
/// but not under most conditions.
/// </summary>
[RegisterComponent]
public sealed partial class PseudoItemComponent : Component, ITransferredByCloning
{
[DataField("size", customTypeSerializer: typeof(PrototypeIdSerializer<ItemSizePrototype>))]
public string Size = "Huge";

public bool Active = false;

[DataField]
public EntityUid? SleepAction;
}
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/ADT/traits/categories.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trait-category-height = Рост
8 changes: 7 additions & 1 deletion Resources/Locale/ru-RU/ADT/traits/neutral.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ trait-deutsch-name = Немецкий акцент
trait-deutsch-desc = Вы говорите как настоящий австрийский художник!
trait-moth-accent-name = Жужащий акцент
trait-moth-accent-desc = Вам либо нравятся моли, либо вы ботаник
trait-moth-accent-desc = Вам либо нравятся моли, либо вы ботаник
trait-tall-name = Высокий
trait-tall-desc = Вы слегка выше других представителей своего вида.
trait-short-name = Низкий
trait-short-desc = Вы слегка ниже других представителей своего вида.
10 changes: 5 additions & 5 deletions Resources/Prototypes/ADT/Entities/Mobs/Player/Drask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
understands:
- GalacticCommon
- Drask
# - type: SizeAttributeWhitelist # Frontier TODO: нет такого компонента..
# tall: true
# tallscale: 1.15
# short: true
# shortscale: 1
- type: SizeAttributeWhitelist # Frontier
tall: true
tallscale: 1.15
short: true
shortscale: 1
10 changes: 5 additions & 5 deletions Resources/Prototypes/ADT/Entities/Mobs/Player/demon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
damageRecovery:
types:
Asphyxiation: -1.0
# - type: SizeAttributeWhitelist # Frontier TODO: нет такого компонента..
# tall: true
# tallscale: 1.1
# short: true
# shortscale: 0.9
- type: SizeAttributeWhitelist # Frontier
tall: true
tallscale: 1.1
short: true
shortscale: 0.9

#Weh
4 changes: 4 additions & 0 deletions Resources/Prototypes/ADT/Traits/categories.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- type: traitCategory
id: Height
name: trait-category-height
maxTraitPoints: 1
31 changes: 31 additions & 0 deletions Resources/Prototypes/ADT/Traits/neutral.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: Height
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: Height
cost: 1
whitelist:
components:
- SizeAttributeWhitelist
blacklist:
components:
- SizeAttribute
components:
- type: SizeAttribute
short: true

0 comments on commit a8f3116

Please sign in to comment.