Skip to content

Commit 3ea3a07

Browse files
committed
Срать 3
1 parent fb40605 commit 3ea3a07

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Robust.Shared.Random;
2+
using Robust.Server.GameObjects;
3+
using Robust.Shared.Containers;
4+
using Content.Shared.SS220.MinorFauna.Actions;
5+
using Content.Shared.SS220.MinorFauna.Events;
6+
using Content.Shared.SS220.MinorFauna.Components;
7+
using Content.Shared.Mobs.Systems;
8+
9+
namespace Content.Server.SS220.MinorFauna;
10+
11+
public abstract class SharedMinorFaunaSystem : EntitySystem
12+
{
13+
[Dependency] private readonly IRobustRandom _random = default!;
14+
[Dependency] private readonly TransformSystem _transform = default!;
15+
[Dependency] private readonly MobStateSystem _mobState = default!;
16+
[Dependency] private readonly SharedContainerSystem _container = default!;
17+
18+
public override void Initialize()
19+
{
20+
base.Initialize();
21+
SubscribeLocalEvent<CocoonerComponent, AfterEntityCocooningEvent>(OnAfterEntityCocooningEvent);
22+
}
23+
24+
private void OnAfterEntityCocooningEvent(Entity<CocoonerComponent> entity, ref AfterEntityCocooningEvent args)
25+
{
26+
if (args.Cancelled || args.Target is not EntityUid target)
27+
return;
28+
29+
if (!TryComp<TransformComponent>(target, out var transform) || !_mobState.IsDead(target))
30+
return;
31+
var targetCords = _transform.GetMoverCoordinates(target, transform);
32+
var cocoonPrototypeID = _random.Pick(entity.Comp.CocoonPrototypes);
33+
var cocoonUid = Spawn(cocoonPrototypeID, targetCords);
34+
35+
if (!TryComp<EntityCocoonComponent>(cocoonUid, out var cocoon) ||
36+
!_container.TryGetContainer(cocoonUid, cocoon.CocoonContainerId, out var container))
37+
{
38+
Log.Error($"{cocoonUid} doesn't have required components to cocooning target");
39+
return;
40+
}
41+
42+
_container.Insert(target, container);
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Content.Shared.Damage;
2+
using Content.Shared.FixedPoint;
3+
using Robust.Shared.GameStates;
4+
5+
namespace Content.Shared.SS220.MinorFauna.Components;
6+
7+
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
8+
public sealed partial class EntityCocoonComponent : Component
9+
{
10+
/// <summary>
11+
/// ID of the container in which the entities placed in the cocoon are stored
12+
/// </summary>
13+
[DataField("container", required: true)]
14+
public string CocoonContainerId = "cocoon";
15+
16+
/// <summary>
17+
/// The entity that created this cocoon
18+
/// </summary>
19+
[ViewVariables, AutoNetworkedField]
20+
public EntityUid? CocoonOwner;
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
using Robust.Shared.GameStates;
2+
using Robust.Shared.Prototypes;
3+
14
namespace Content.Shared.SS220.MinorFauna.Components;
5+
6+
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
27
public sealed partial class CocoonerComponent : Component
38
{
49
/// <summary>
510
/// Minimal distance for cocooning
611
/// </summary>
712
[DataField]
813
public float CocoonsMinDistance = 0.5f;
14+
15+
/// <summary>
16+
/// Ids of the cocoon prototype
17+
/// </summary>
18+
[DataField]
19+
public List<EntProtoId> CocoonPrototypes = new();
20+
21+
/// <summary>
22+
/// List of cocoons created by component owner
23+
/// </summary>
24+
[ViewVariables, AutoNetworkedField]
25+
public List<EntityUid> CocoonsList = new();
26+
927
}

Content.Shared/SS220/MinorFauna/Systems/SharedMinorFaunaSystem.cs

-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public override void Initialize()
2020
base.Initialize();
2121

2222
SubscribeLocalEvent<CocoonerComponent, ActionEntityCocooningEvent>(OnCocooningAction);
23-
SubscribeLocalEvent<CocoonerComponent, AfterEntityCocooningEvent>(OnAfterEntityCocooningEvent);
2423
}
2524

2625
private void OnCocooningAction(Entity<CocoonerComponent> entity, ref ActionEntityCocooningEvent args)
@@ -55,14 +54,5 @@ private void OnCocooningAction(Entity<CocoonerComponent> entity, ref ActionEntit
5554
target
5655
);
5756
}
58-
private void OnAfterEntityCocooningEvent(Entity<CocoonerComponent> entity, ref AfterEntityCocooningEvent args)
59-
{
60-
if (args.Cancelled || args.Target is not EntityUid target)
61-
return;
62-
63-
if (!TryComp<TransformComponent>(target, out var transform) || !_mobState.IsDead(target))
64-
return;
65-
66-
}
6757

6858
}

0 commit comments

Comments
 (0)