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

Nyano port of digging #400

Merged
merged 18 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
102 changes: 102 additions & 0 deletions Content.Server/Nyanotrasen/Digging/DiggingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using Content.Shared.Interaction;
using Content.Shared.Maps;
using Content.Shared.Nyanotrasen.Digging;
using Content.Shared.Physics;
using Content.Shared.Tools.Components;
using Content.Shared.Tools.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;

namespace Content.Server.Digging;

public sealed class DiggingSystem : EntitySystem
{
[Dependency] private readonly TileSystem _tiles = default!;
[Dependency] private readonly SharedMapSystem _maps = default!;
[Dependency] private readonly SharedToolSystem _tools = default!;
[Dependency] private readonly TurfSystem _turfs = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;

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

SubscribeLocalEvent<EarthDiggingComponent, AfterInteractEvent>(OnDiggingAfterInteract);
SubscribeLocalEvent<EarthDiggingComponent, EarthDiggingDoAfterEvent>(OnEarthDigComplete);
}


private void OnEarthDigComplete(EntityUid shovel, EarthDiggingComponent comp, EarthDiggingDoAfterEvent args)
{
var coordinates = GetCoordinates(args.Coordinates);
if (!TryComp<EarthDiggingComponent>(shovel, out var _))
return;

var gridUid = coordinates.GetGridUid(EntityManager);
if (gridUid == null)
return;

var grid = Comp<MapGridComponent>(gridUid.Value);
var tile = _maps.GetTileRef(gridUid.Value, grid, coordinates);

if (_tileDefManager[tile.Tile.TypeId] is not ContentTileDefinition tileDef
|| !tileDef.CanShovel
|| string.IsNullOrEmpty(tileDef.BaseTurf)
|| _turfs.IsTileBlocked(tile, CollisionGroup.MobMask))
{
return;
}

_tiles.DigTile(tile);
}

private void OnDiggingAfterInteract(EntityUid uid, EarthDiggingComponent component,
AfterInteractEvent args)
{
if (args.Handled || !args.CanReach || args.Target != null)
return;

if (TryDig(args.User, uid, component, args.ClickLocation))
args.Handled = true;
}

private bool TryDig(EntityUid user, EntityUid shovel, EarthDiggingComponent component,
EntityCoordinates clickLocation)
{
ToolComponent? tool = null;
if (component.ToolComponentNeeded && !TryComp(shovel, out tool))
return false;

var mapUid = clickLocation.GetGridUid(EntityManager);
if (mapUid == null || !TryComp(mapUid, out MapGridComponent? mapGrid))
return false;

var tile = _maps.GetTileRef(mapUid.Value, mapGrid, clickLocation);

var coordinates = _maps.GridTileToLocal(mapUid.Value, mapGrid, tile.GridIndices);

if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
return false;

if (_tileDefManager[tile.Tile.TypeId] is not ContentTileDefinition tileDef
|| !tileDef.CanShovel
|| string.IsNullOrEmpty(tileDef.BaseTurf)
|| _tileDefManager[tileDef.BaseTurf] is not ContentTileDefinition
|| _turfs.IsTileBlocked(tile, CollisionGroup.MobMask))
{
return false;
}

var ev = new EarthDiggingDoAfterEvent(GetNetCoordinates(clickLocation));
return _tools.UseTool(
shovel,
user,
target: shovel,
doAfterDelay: component.Delay,
toolQualitiesNeeded: new[] { component.QualityNeeded },
doAfterEv: ev,
toolComponent: tool
);
}
}
4 changes: 4 additions & 0 deletions Content.Shared/Maps/ContentTileDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public sealed partial class ContentTileDefinition : IPrototype, IInheritingProto

[DataField("canCrowbar")] public bool CanCrowbar { get; private set; }

// Delta V
[DataField("canShovel")] public bool CanShovel { get; private set; }
//Delta V

/// <summary>
/// Whether this tile can be pried by an advanced prying tool if not pryable otherwise.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions Content.Shared/Maps/TileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,22 @@ public bool CutTile(TileRef tileRef)

return DeconstructTile(tileRef);
}
// Delta V
public bool DigTile(TileRef tileRef)
{
var tile = tileRef.Tile;

if (tile.IsEmpty)
return false;

var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.TypeId];

if (!tileDef.CanShovel)
return false;

return DeconstructTile(tileRef);
}
// Delta V
public bool ReplaceTile(TileRef tileref, ContentTileDefinition replacementTile)
{
if (!TryComp<MapGridComponent>(tileref.GridUid, out var grid))
Expand Down
29 changes: 29 additions & 0 deletions Content.Shared/Nyanotrasen/Digging/DiggingEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Shared.DoAfter;
using Robust.Shared.Map;
using Robust.Shared.Serialization;

namespace Content.Shared.Nyanotrasen.Digging;


[Serializable, NetSerializable]
public sealed partial class EarthDiggingDoAfterEvent : DoAfterEvent
{
public NetCoordinates Coordinates { get; set; }

private EarthDiggingDoAfterEvent(){}

public EarthDiggingDoAfterEvent(NetCoordinates coordinates)
{
Coordinates = coordinates;
}
public override DoAfterEvent Clone()
{
return this;
}
}

[Serializable, NetSerializable]
public sealed class EarthDiggingCancelledEvent : EntityEventArgs
{
public NetEntity Shovel;
}
22 changes: 22 additions & 0 deletions Content.Shared/Nyanotrasen/Digging/EarthDiggingComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Threading;
using Content.Shared.Tools;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.Nyanotrasen.Digging;

[RegisterComponent]
public sealed partial class EarthDiggingComponent : Component
{
[ViewVariables]
[DataField("toolComponentNeeded")]
public bool ToolComponentNeeded = true;

[ViewVariables]
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
public string QualityNeeded = "Digging";

[ViewVariables]
[DataField("delay")]
public float Delay = 2f;

}
4 changes: 4 additions & 0 deletions Resources/Audio/Nyanotrasen/Items/attributions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- files: ["shovel_dig.ogg"]
license: "CC-BY-3.0"
copyright: "https://freesound.org/people/cameronmusic/"
source: "https://freesound.org/people/cameronmusic/sounds/138411/"
Binary file not shown.
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/nyanotrasen/tools/tool-qualities.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tool-quality-digging-name = Digging
tool-quality-digging-tool-name = Shovel
7 changes: 7 additions & 0 deletions Resources/Prototypes/Entities/Objects/Tools/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@
Wood: 50
- type: StaticPrice
price: 25
# Delta V: Adds tool quality for digging
- type: Tool
qualities:
- Digging
useSound:
path: /Audio/Nyanotrasen/Items/shovel_dig.ogg
- type: EarthDigging

- type: entity
parent: BaseItem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- type: entity
name: dark grass tile
parent: FloorTileItemBase
id: FloorTileItemGrassDark
components:
- type: Sprite
sprite: /Textures/Nyanotrasen/Objects/Tiles/tiles.rsi
state: grassdark
- type: Item
heldPrefix: grassdark
- type: FloorTile
outputs:
- FloorGrassDark
- type: Stack
stackType: FloorTileGrassDark

- type: entity
name: light grass tile
parent: FloorTileItemBase
id: FloorTileItemGrassLight
components:
- type: Sprite
sprite: /Textures/Nyanotrasen/Objects/Tiles/tiles.rsi
state: grasslight
- type: Item
heldPrefix: grasslight
- type: FloorTile
outputs:
- FloorGrassLight
- type: Stack
stackType: FloorTileGrassLight

- type: entity
name: dirt tile
parent: FloorTileItemBase
id: FloorTileItemDirt
components:
- type: Sprite
sprite: /Textures/Nyanotrasen/Objects/Tiles/tiles.rsi
state: dirt
- type: Item
heldPrefix: dirt
- type: FloorTile
outputs:
- FloorDirt
- type: Stack
stackType: FloorTileDirt

- type: entity
name: bedrock tile
parent: FloorTileItemBase
id: FloorTileItemBedrock
components:
- type: Sprite
sprite: /Textures/Nyanotrasen/Objects/Tiles/tiles.rsi
state: bedrock
- type: Item
heldPrefix: bedrock
- type: FloorTile
outputs:
- FloorBedrock
- type: Stack
stackType: FloorTileBedrock
23 changes: 23 additions & 0 deletions Resources/Prototypes/Nyanotrasen/Stacks/floor_tile_stacks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- type: stack
id: FloorTileGrassDark
name: dark grass floor tile
spawn: FloorTileItemGrassDark
maxCount: 30

- type: stack
id: FloorTileGrassLight
name: light grass floor tile
spawn: FloorTileItemGrassLight
maxCount: 30

- type: stack
id: FloorTileDirt
name: dirt floor tile
spawn: FloorTileItemDirt
maxCount: 30

- type: stack
id: FloorTileBedrock
name: bedrock floor tile
spawn: FloorTileItemBedrock
maxCount: 30
20 changes: 20 additions & 0 deletions Resources/Prototypes/Nyanotrasen/Tiles/floors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- type: tile
id: FloorBedrock
name: tiles-bedrock-floor
sprite: /Textures/Nyanotrasen/Tiles/bedrock.png
variants: 4
placementVariants:
- 1.0
- 1.0
- 1.0
- 1.0
baseTurf: Space
isSubfloor: true
#canCrowbar: true # Come back
# Maybe if there's ever some way to combine grids or prevent overly simple spacing.
# canShovel: true
footstepSounds:
collection: FootstepAsteroid
itemDrop: FloorTileItemBedrock # Delta V
heatCapacity: 10000
weather: true
6 changes: 6 additions & 0 deletions Resources/Prototypes/Nyanotrasen/tool_qualities.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- type: tool
id: Digging
name: tool-quality-digging-name
toolName: tool-quality-digging-tool-name
spawn: Shovel
icon: { sprite: Objects/Tools/shovel.rsi, state: icon }
27 changes: 15 additions & 12 deletions Resources/Prototypes/Tiles/floors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1338,8 +1338,8 @@
name: tiles-planet-grass-floor
sprite: /Textures/Tiles/grass.png
baseTurf: FloorDirt
isSubfloor: true
canCrowbar: false
#canCrowbar: false # Come back
canShovel: true # Delta V
footstepSounds:
collection: FootstepGrass
itemDrop: FloorTileItemGrass
Expand All @@ -1351,8 +1351,8 @@
name: tiles-jungle-grass-floor
sprite: /Textures/Tiles/grassjungle.png
baseTurf: FloorDirt
isSubfloor: true
canCrowbar: false
#canCrowbar: false # Come back
canShovel: true # Delta V
footstepSounds:
collection: FootstepGrass
itemDrop: FloorTileItemGrassJungle
Expand All @@ -1370,10 +1370,11 @@
- 1.0
- 1.0
baseTurf: FloorDirt
isSubfloor: true
canCrowbar: false
#canCrowbar: false # Come back
canShovel: true # Delta V
footstepSounds:
collection: FootstepGrass
itemDrop: FloorTileItemGrassDark # Delta V
heatCapacity: 10000
weather: true

Expand All @@ -1388,10 +1389,11 @@
- 1.0
- 1.0
baseTurf: FloorDirt
isSubfloor: true
canCrowbar: false
#canCrowbar: false # Come back
canShovel: true # Delta V
footstepSounds:
collection: FootstepGrass
itemDrop: FloorTileItemGrassLight
heatCapacity: 10000
weather: true

Expand All @@ -1405,13 +1407,14 @@
- 1.0
- 1.0
- 1.0
baseTurf: Plating
isSubfloor: true
canCrowbar: false
baseTurf: FloorBedrock # Delta V
#canCrowbar: false # Come back
canShovel: true # Delta V
footstepSounds:
collection: FootstepAsteroid
itemDrop: FloorTileItemDirt # Delta V
heatCapacity: 10000
weather: true
weather: True

# Asteroid

Expand Down
Loading
Loading