Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using Content.Shared.Directions;
|
|
using Content.Shared.Maps;
|
|
using Content.Shared.Physics;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Stunnable;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Shared.Abilities.Goliath;
|
|
|
|
public sealed class GoliathTentacleSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly INetManager _net = default!;
|
|
[Dependency] private readonly SharedMapSystem _map = default!;
|
|
[Dependency] private readonly SharedStunSystem _stun = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
[Dependency] private readonly TurfSystem _turf = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<GoliathSummonTentacleAction>(OnSummonAction);
|
|
}
|
|
|
|
private void OnSummonAction(GoliathSummonTentacleAction args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
// TODO: animation
|
|
|
|
_popup.PopupPredicted(Loc.GetString("tentacle-ability-use-popup", ("entity", args.Performer)), args.Performer, args.Performer, type: PopupType.SmallCaution);
|
|
_stun.TryAddStunDuration(args.Performer, TimeSpan.FromSeconds(0.8f));
|
|
|
|
var coords = args.Target;
|
|
List<EntityCoordinates> spawnPos = new();
|
|
spawnPos.Add(coords);
|
|
|
|
var dirs = new List<Direction>();
|
|
dirs.AddRange(args.OffsetDirections);
|
|
|
|
for (var i = 0; i < 3; i++)
|
|
{
|
|
var dir = _random.PickAndTake(dirs);
|
|
spawnPos.Add(coords.Offset(dir));
|
|
}
|
|
|
|
if (_transform.GetGrid(coords) is not { } grid || !TryComp<MapGridComponent>(grid, out var gridComp))
|
|
return;
|
|
|
|
foreach (var pos in spawnPos)
|
|
{
|
|
if (!_map.TryGetTileRef(grid, gridComp, pos, out var tileRef) ||
|
|
_turf.IsSpace(tileRef) ||
|
|
_turf.IsTileBlocked(tileRef, CollisionGroup.Impassable))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (_net.IsServer)
|
|
Spawn(args.EntityId, pos);
|
|
}
|
|
|
|
args.Handled = true;
|
|
}
|
|
}
|