Skip to content

Commit

Permalink
PlacerItem fixes + add barricade sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirus59 committed Jan 3, 2025
1 parent 6b27c81 commit 00c7eda
Show file tree
Hide file tree
Showing 27 changed files with 474 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public override void Update(float frameTime)
if (!TryComp<PlacerItemComponent>(heldEntity, out var comp) || !comp.Active)
{
if (placerIsPlacerItem)
{
_placementManager.Clear();
_placementDirection = default;
}

return;
}
Expand All @@ -50,13 +53,13 @@ public override void Update(float frameTime)
RaiseNetworkEvent(new PlacerItemUpdateDirectionEvent(GetNetEntity(heldEntity.Value), _placementDirection));
}

if (heldEntity == placerEntity && placerProto == comp.ProtoId.Id)
if (heldEntity == placerEntity && placerProto == comp.SpawnProto.Id)
return;

var newObjInfo = new PlacementInformation
{
MobUid = heldEntity.Value,
EntityType = comp.ProtoId.Id,
EntityType = comp.ConstructionGhostProto ?? comp.SpawnProto,
PlacementOption = _placementMode,
Range = (int)Math.Ceiling(SharedInteractionSystem.InteractionRange),
IsTile = false,
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/Spawners/Components/SpawnOnDespawnComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public sealed partial class SpawnOnDespawnComponent : Component
/// </summary>
[DataField(required: true)]
public EntProtoId Prototype = string.Empty;

// SS220 Add inherit rotation begin
[DataField]
public bool InheritRotation = false;
// SS220 Add inherit rotation end
}
16 changes: 15 additions & 1 deletion Content.Server/Spawners/EntitySystems/SpawnOnDespawnSystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using Content.Server.Spawners.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Spawners;

namespace Content.Server.Spawners.EntitySystems;

public sealed class SpawnOnDespawnSystem : EntitySystem
{
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly TransformSystem _xform = default!;

public override void Initialize()
{
base.Initialize();
Expand All @@ -18,7 +22,17 @@ private void OnDespawn(EntityUid uid, SpawnOnDespawnComponent comp, ref TimedDes
if (!TryComp(uid, out TransformComponent? xform))
return;

Spawn(comp.Prototype, xform.Coordinates);
// SS220 Add inherit rotation begin
//Spawn(comp.Prototype, xform.Coordinates);

if (comp.InheritRotation)
{
var mapCords = _xform.ToMapCoordinates(GetNetCoordinates(xform.Coordinates));
Spawn(comp.Prototype, mapCords, rotation: xform.LocalRotation);
}
else
Spawn(comp.Prototype, xform.Coordinates);
// SS220 Add inherit rotation end
}

public void SetPrototype(Entity<SpawnOnDespawnComponent> entity, EntProtoId prototype)
Expand Down
10 changes: 10 additions & 0 deletions Content.Shared/SS220/Barricade/BarricadeComponent.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;

namespace Content.Shared.SS220.Barricade;

/// <summary>
/// A component that allows entity to block projectiles or hitscans with a specific chance that change by fire distance
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedBarricadeSystem))]
public sealed partial class BarricadeComponent : Component
Expand All @@ -22,4 +26,10 @@ public sealed partial class BarricadeComponent : Component
public float MinDistance = 1.5f;
[DataField]
public float MaxDistance = 9f;

/// <summary>
/// A whitelist of entities that will always pass through the barricade
/// </summary>
[DataField]
public EntityWhitelist? Whitelist;
}
12 changes: 12 additions & 0 deletions Content.Shared/SS220/Barricade/SharedBarricadeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
using Content.Shared.Projectiles;
using Content.Shared.SS220.Weapons.Ranged.Events;
using Content.Shared.Throwing;
using Content.Shared.Whitelist;
using Robust.Shared.Physics.Events;

namespace Content.Shared.SS220.Barricade;

public abstract partial class SharedBarricadeSystem : EntitySystem
{
[Dependency] private readonly EntityWhitelistSystem _entityWhitelist = default!;

public override void Initialize()
{
base.Initialize();
Expand All @@ -22,9 +25,18 @@ public override void Initialize()

private void OnPreventCollide(Entity<BarricadeComponent> entity, ref PreventCollideEvent args)
{
if (_entityWhitelist.IsWhitelistPass(entity.Comp.Whitelist, args.OtherEntity))
{
args.Cancelled = true;
return;
}

if (TryComp<ProjectileComponent>(args.OtherEntity, out var projectile) &&
ProjectileTryPassBarricade(entity, (args.OtherEntity, projectile)))
{
args.Cancelled = true;
return;
}
}

private void OnHitscanAttempt(Entity<BarricadeComponent> entity, ref HitscanAttempt args)
Expand Down
26 changes: 25 additions & 1 deletion Content.Shared/SS220/PlacerItem/PlacerItemComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

namespace Content.Shared.SS220.PlacerItem.Components;

/// <summary>
/// A component that allows the user to place a specific entity using a construction ghost
/// </summary>
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class PlacerItemComponent : Component
{
/// <summary>
/// Is placement by this component active or not
/// </summary>
[ViewVariables, AutoNetworkedField]
public bool Active = false;

/// <summary>
/// In which direction should the construction be placed
/// </summary>
[ViewVariables, AutoNetworkedField]
public Direction ConstructionDirection
{
Expand All @@ -29,12 +38,27 @@ public Direction ConstructionDirection
[ViewVariables(VVAccess.ReadOnly)]
public Transform ConstructionTransform { get; private set; } = default!;

/// <summary>
/// Id of the prototype used in the construction ghost
/// </summary>
[DataField]
public EntProtoId? ConstructionGhostProto;

/// <summary>
/// Id of the prototype that will be spawned
/// </summary>
[DataField(required: true)]
public EntProtoId ProtoId;
public EntProtoId SpawnProto;

/// <summary>
/// The time required for the user to place the construction
/// </summary>
[DataField]
public float DoAfter = 0;

/// <summary>
/// Should the placement toggle when item used in hand
/// </summary>
[DataField]
public bool ToggleActiveOnUseInHand = false;
}
45 changes: 32 additions & 13 deletions Content.Shared/SS220/PlacerItem/PlacerItemSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Shared.SS220.PlacerItem.Components;
using Content.Shared.Tag;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
Expand All @@ -19,19 +20,22 @@ public sealed partial class PlacerItemSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IComponentFactory _factory = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly RCDSystem _rcdSystem = default!;
[Dependency] private readonly SharedTransformSystem _xform = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<PlacerItemComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<PlacerItemComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<PlacerItemComponent, PlacerItemDoAfterEvent>(OnDoAfter);

SubscribeNetworkEvent<PlacerItemUpdateDirectionEvent>(OnUpdateDirection);
}
Expand Down Expand Up @@ -64,7 +68,7 @@ private void OnAfterInteract(Entity<PlacerItemComponent> entity, ref AfterIntera
return;

var doAfterTime = TimeSpan.FromSeconds(comp.DoAfter);
var ev = new PlacementOnInteractDoAfterEvent(GetNetCoordinates(mapGridData.Value.Location), comp.ConstructionDirection, comp.ProtoId);
var ev = new PlacerItemDoAfterEvent(GetNetCoordinates(mapGridData.Value.Location), comp.ConstructionDirection, comp.SpawnProto);

var doAfterArgs = new DoAfterArgs(EntityManager, user, doAfterTime, ev, uid, args.Target, uid)
{
Expand All @@ -76,8 +80,25 @@ private void OnAfterInteract(Entity<PlacerItemComponent> entity, ref AfterIntera
BlockDuplicate = false
};

_doAfter.TryStartDoAfter(doAfterArgs);
args.Handled = true;
if (_doAfter.TryStartDoAfter(doAfterArgs))
{
comp.Active = false;
args.Handled = true;
};
}

private void OnDoAfter(Entity<PlacerItemComponent> entity, ref PlacerItemDoAfterEvent args)
{
if (args.Cancelled || !_net.IsServer)
return;

if (!_rcdSystem.TryGetMapGridData(GetCoordinates(args.Location), out var mapGridData))
return;

var mapCords = _xform.ToMapCoordinates(_mapSystem.GridTileToLocal(mapGridData.Value.GridUid, mapGridData.Value.Component, mapGridData.Value.Position));
Spawn(args.ProtoId.Id, mapCords, rotation: args.Direction.ToAngle());

QueueDel(entity);
}

private void OnUpdateDirection(PlacerItemUpdateDirectionEvent ev, EntitySessionEventArgs session)
Expand Down Expand Up @@ -105,17 +126,17 @@ private void SetActive(Entity<PlacerItemComponent> entity, bool value)
Dirty(entity);
}

public bool IsPlacementOperationStillValid(Entity<PlacerItemComponent> entity, MapGridData mapGridData, EntityUid? target, EntityUid user, bool popMsgs = true)
public bool IsPlacementOperationStillValid(Entity<PlacerItemComponent> entity, MapGridData mapGridData, EntityUid? target, EntityUid user)
{
var (uid, comp) = entity;
var unobstracted = target == null
? _interaction.InRangeUnobstructed(user, _mapSystem.GridTileToWorld(mapGridData.GridUid, mapGridData.Component, mapGridData.Position), popup: popMsgs)
: _interaction.InRangeUnobstructed(user, target.Value, popup: popMsgs);
? _interaction.InRangeUnobstructed(user, _mapSystem.GridTileToWorld(mapGridData.GridUid, mapGridData.Component, mapGridData.Position))
: _interaction.InRangeUnobstructed(user, target.Value);

if (!unobstracted)
return false;

if (!_prototypeManager.TryIndex<EntityPrototype>(comp.ProtoId.Id, out var prototype))
if (!_prototypeManager.TryIndex<EntityPrototype>(comp.SpawnProto.Id, out var prototype))
return false;

prototype.TryGetComponent<TagComponent>(_factory.GetComponentName<TagComponent>(), out var tagComponent);
Expand Down Expand Up @@ -169,17 +190,15 @@ private bool IsOurEntWillCollideWithOtherEnt(Transform ourXform, FixturesCompone
}

[Serializable, NetSerializable]
public sealed partial class PlacementOnInteractDoAfterEvent : DoAfterEvent
public sealed partial class PlacerItemDoAfterEvent : DoAfterEvent
{
public NetCoordinates Coordinates;

public NetCoordinates Location;
public Direction Direction;

public EntProtoId ProtoId;

public PlacementOnInteractDoAfterEvent(NetCoordinates coordinates, Direction direction, EntProtoId protoId)
public PlacerItemDoAfterEvent(NetCoordinates location, Direction direction, EntProtoId protoId)
{
Coordinates = coordinates;
Location = location;
Direction = direction;
ProtoId = protoId;
}
Expand Down
13 changes: 13 additions & 0 deletions Resources/Locale/ru-RU/ss220/strucrure/barricades.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ent-FractWarFoldedBarricadeBase = сложенная баррикада
.desc = Сложенная баррикада из листов стали. Может быть быстро установлена в нужном месте.
ent-FractWarBarricadeSpawnBase = баррикада
.desc = Баррикада небольшой высоты из листов стали. Есть шанс защитить от шальной пули.
ent-FractWarBarricadeBase = баррикада
.desc = Баррикада небольшой высоты из листов стали. Есть шанс защитить от шальной пули.
ent-FractWarFoldedBarricadeUssp = сложеная баррикада СССП
.desc = {ent-FractWarFoldedBarricadeBase.desc}
ent-FractWarBarricadeSpawnUssp = баррикада СССП
.desc = {ent-FractWarBarricadeSpawnBase.desc}
ent-FractWarBarricadeUssp = баррикада СССП
.desc = {ent-FractWarBarricadeBase.desc}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
base:
Primed: { state: primed }
Unprimed: { state: complete }
# SS220 add barricades begin
- type: Tag
tags:
- PassBarricade
# SS220 add barricades end

- type: entity
name: composition C-4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
enum.ConstructionVisuals.Layer:
Primed: { state: primed }
Unprimed: { state: icon }
# SS220 add barricades begin
- type: Tag
tags:
- PassBarricade
# SS220 add barricades end

- type: entity
name: explosive grenade
Expand Down
51 changes: 0 additions & 51 deletions Resources/Prototypes/SS220/Entities/Structures/barricade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,54 +361,3 @@
behaviors:
- !type:DoActsBehavior
acts: [ "Destruction" ]

- type: entity
parent: BaseItem
id: PlacementOnInteractTest
name: base flatpack
description: A flatpack used for constructing something.
components:
- type: Item
size: Large
- type: Sprite
sprite: Objects/Devices/flatpack.rsi
layers:
- state: base
- state: overlay
color: "#cec8ac"
map: ["enum.FlatpackVisualLayers.Overlay"]
- state: icon-default
- type: Appearance
- type: PlacerItem
protoId: FoldingBarricadePlasteelFloor
toggleActiveOnUseInHand: true
- type: StaticPrice
price: 250

- type: entity
parent: BarricadePlasteelFloor
id: FoldingBarricadePlasteelFloor
name: напольная укреплённая баррикада
description: Баррикада небольшой высоты из листов пластали. Есть шанс защитить от шальной пули.
placement:
mode: SnapgridCenter
components:
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: "-0.5,-0.5,0.5,-0.36"
mask:
- TableMask
layer:
- WallLayer
- type: Barricade
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 1600
behaviors:
- !type:DoActsBehavior
acts: [ "Destruction" ]
Loading

0 comments on commit 00c7eda

Please sign in to comment.