-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Фиксы и добавления черт: Низкий, Высокий (#205)
<!-- ЭТО ШАБЛОН ВАШЕГО PULL REQUEST. Текст между стрелками - это комментарии - они не будут видны в PR. --> ## Описание PR <!-- Ниже опишите ваш Pull Request. Что он изменяет? На что еще это может повлиять? Постарайтесь описать все внесённые вами изменения! --> **Проверки** <!-- Выполнение всех следующих действий, если это приемлемо для вида изменений сильно ускорит разбор вашего PR --> - [ ] PR полностью завершён и мне не нужна помощь чтобы его закончить. - [ ] Я внимательно просмотрел все свои изменения и багов в них не нашёл. - [ ] Я запускал локальный сервер со своими изменениями и всё протестировал. - [ ] Я добавил скриншот/видео демонстрации PR в игре, **или** этот PR этого не требует. **Изменения** :cl: Шрёдька - fix: Починил систему роста. - tweak: Добавлена новая категория в черты: Рост.
- Loading branch information
1 parent
ec65ab9
commit a8f3116
Showing
11 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Content.Server/ADT/SizeAttribute/SizeAttributeComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } | ||
} |
2 changes: 1 addition & 1 deletion
2
Content.Server/ADT/SizeAttribute/SizeAttributeWhitelistComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
trait-category-height = Рост |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- type: traitCategory | ||
id: Height | ||
name: trait-category-height | ||
maxTraitPoints: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |