Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpiderSystem refactor and rename #33742

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions Content.Server/Spider/SpiderSystem.cs

This file was deleted.

100 changes: 100 additions & 0 deletions Content.Server/WebPlacer/WebPlacerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Linq;
iaada marked this conversation as resolved.
Show resolved Hide resolved
using Content.Server.Popups;
using Content.Shared.Maps;
using Content.Shared.WebPlacer;
using Content.Shared.Whitelist;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;

namespace Content.Server.WebPlacer;

/// <summary>
/// Spawns entities (probably webs) around the component owner. Action handled by <see cref="SharedWebPlacerSystem"/>.
/// </summary>
public sealed class WebPlacerSystem : SharedWebPlacerSystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
iaada marked this conversation as resolved.
Show resolved Hide resolved
[Dependency] private readonly ITileDefinitionManager _tile = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedMapSystem _map = default!;

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

SubscribeLocalEvent<WebPlacerComponent, SpiderWebActionEvent>(OnSpawnNet);
iaada marked this conversation as resolved.
Show resolved Hide resolved
}

private void OnSpawnNet(EntityUid uid, WebPlacerComponent component, SpiderWebActionEvent args)
iaada marked this conversation as resolved.
Show resolved Hide resolved
{
if (args.Handled)
return;

var transform = Transform(uid);
var grid = transform.GridUid;

// Instantly fail in space
if (!TryComp<MapGridComponent>(grid, out var gridComp))
{
_popup.PopupEntity(Loc.GetString(component.MessageOffGrid), args.Performer, args.Performer);
return;
}

var coords = transform.Coordinates;
var spawnPos = component.OffsetVectors.Select(v => coords.Offset(v));

bool success = false;
foreach (var pos in spawnPos)
{
if (!IsValidTile(pos, component.DestinationWhitelist, component.DestinationBlacklist, grid.Value, gridComp))
continue;

Spawn(component.WebPrototype, pos);
success = true;
}

// Return if nothing was spawned
if (!success)
{
_popup.PopupEntity(Loc.GetString(component.MessageFail), args.Performer, args.Performer);
return;
}

args.Handled = true;
_popup.PopupEntity(Loc.GetString(component.MessageSuccess), args.Performer, args.Performer);

if (component.WebSound != null)
_audio.PlayPvs(component.WebSound, uid);
}

private bool IsValidTile(EntityCoordinates coords, EntityWhitelist? whitelist, EntityWhitelist? blacklist, EntityUid grid, MapGridComponent gridComp)
{
// Don't place webs in space
if (!_map.TryGetTileRef(grid, gridComp, coords, out var tileRef) ||
tileRef.IsSpace(_tile))
return false;

// Don't place webs on webs
if (blacklist != null)
foreach (var entity in _lookup.GetEntitiesIntersecting(coords, LookupFlags.Uncontained))
if (_whitelistSystem.IsBlacklistPass(blacklist, entity))
return false;

// Only place webs on webs
if (whitelist != null)
{
foreach (var entity in _lookup.GetEntitiesIntersecting(coords, LookupFlags.Uncontained))
if (_whitelistSystem.IsWhitelistPass(whitelist, entity))
return true;

return false;
}

return true;
}
}
10 changes: 10 additions & 0 deletions Content.Shared/IgnoreSpiderWeb/IgnoreSpiderWebComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Shared.IgnoreSpiderWeb;

/// <summary>
/// Marker component for entities that ignore spiderwebs.
/// </summary>
[RegisterComponent]
public sealed partial class IgnoreSpiderWebComponent : Component
{

iaada marked this conversation as resolved.
Show resolved Hide resolved
}
7 changes: 0 additions & 7 deletions Content.Shared/Spider/IgnoreSpiderWebComponent.cs

This file was deleted.

31 changes: 0 additions & 31 deletions Content.Shared/Spider/SharedSpiderSystem.cs

This file was deleted.

23 changes: 0 additions & 23 deletions Content.Shared/Spider/SpiderComponent.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Content.Shared/Spider/SpiderWebObjectComponent.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Content.Shared/Spider/SpiderWebVisualsComponent.cs

This file was deleted.

23 changes: 23 additions & 0 deletions Content.Shared/WebPlacer/SharedWebPlacerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Shared.Actions;

namespace Content.Shared.WebPlacer;

/// <summary>
/// Gives the component owner (probably a spider) an action to spawn entites around itself. Spawning handled by <see cref="WebPlacerSystem"/>.
/// </summary>
iaada marked this conversation as resolved.
Show resolved Hide resolved
public abstract class SharedWebPlacerSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _action = default!;

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

SubscribeLocalEvent<WebPlacerComponent, MapInitEvent>(OnInit);
}

private void OnInit(EntityUid uid, WebPlacerComponent component, MapInitEvent args)
iaada marked this conversation as resolved.
Show resolved Hide resolved
{
_action.AddAction(uid, ref component.ActionEntity, component.SpawnWebAction, uid);
}
}
81 changes: 81 additions & 0 deletions Content.Shared/WebPlacer/WebPlacerComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Content.Shared.Actions;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared.WebPlacer;

/// <summary>
/// Gives the entity (probably a spider) an ability to spawn entites (probably webs) around itself.
/// </summary>
iaada marked this conversation as resolved.
Show resolved Hide resolved
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedWebPlacerSystem))]
public sealed partial class WebPlacerComponent : Component
{
/// <summary>
/// Id of the entity getting spawned.
/// </summary>
[DataField]
public EntProtoId WebPrototype = "SpiderWeb";

/// <summary>
/// Id of the action that will be given.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[DataField]
public EntProtoId SpawnWebAction = "ActionSpiderWeb";

/// <summary>
/// Action given to the player.
/// </summary>
//[ViewVariables]
iaada marked this conversation as resolved.
Show resolved Hide resolved
public EntityUid? ActionEntity;

/// <summary>
/// Whitelist of entities proto will only spawn on.
/// </summary>
[DataField]
public EntityWhitelist? DestinationWhitelist;

/// <summary>
/// Blacklist of entities proto won't spawn on.
/// </summary>
[DataField]
public EntityWhitelist? DestinationBlacklist;

/// <summary>
/// Sound played when successfully spawning something.
/// </summary>
[DataField]
public SoundSpecifier? WebSound =
new SoundPathSpecifier("/Audio/Effects/spray3.ogg")
{
Params = AudioParams.Default.WithVariation(0.125f),
};

/// <summary>
/// Vectors determining where the entities will spawn.
/// </summary>
[DataField]
public List<Vector2i> OffsetVectors = new()
{
Vector2i.Zero,
Vector2i.Up,
Vector2i.Down,
Vector2i.Left,
Vector2i.Right,
};

// Localization files for popup text.
[DataField]
public LocId MessageOffGrid = "spider-web-action-nogrid";
[DataField]
public LocId MessageSuccess = "spider-web-action-success";
[DataField]
public LocId MessageFail = "spider-web-action-fail";
iaada marked this conversation as resolved.
Show resolved Hide resolved
}

public sealed partial class SpiderWebActionEvent : InstantActionEvent
{
}
4 changes: 2 additions & 2 deletions Resources/Locale/en-US/actions/actions/spider.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spider-web-action-nogrid = There is no floor under you!
spider-web-action-success = You place webs around you.
spider-web-action-fail = You can't place webs here! All cardinal directions already have webs!
spider-web-action-success = You spin webs around you.
spider-web-action-fail = There is no room to spin your webs!

sericulture-failure-hunger = Your stomach is too empty to make any more webs!
1 change: 1 addition & 0 deletions Resources/Prototypes/Actions/spider.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Default prototype used by WebPlacerComponent
iaada marked this conversation as resolved.
Show resolved Hide resolved
- type: entity
id: ActionSpiderWeb
name: Spider Web
Expand Down
Loading
Loading