Nyano port of digging (#400)

* Velcroboy changes

* Fix compilation errors

* Fix borked path

* Fix

* Moved to shared, fixed some problems with code

* Cleanup

* Fix paths

* Fix

* Move files around

* Moved DiggingSystem to Server
This commit is contained in:
Ygg01 2023-12-06 16:58:00 +01:00 committed by GitHub
parent 67cee092b2
commit 089398d256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 379 additions and 14 deletions

View File

@ -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
);
}
}

View File

@ -40,6 +40,10 @@ namespace Content.Shared.Maps
[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>

View File

@ -85,7 +85,22 @@ public sealed class TileSystem : EntitySystem
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))

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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.

View File

@ -0,0 +1,2 @@
tool-quality-digging-name = Digging
tool-quality-digging-tool-name = Shovel

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 }

View File

@ -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
@ -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
@ -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
@ -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
@ -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

View File

@ -121,8 +121,10 @@
East: /Textures/Tiles/Planet/Snow/snow_double_edge_east.png
North: /Textures/Tiles/Planet/Snow/snow_double_edge_north.png
West: /Textures/Tiles/Planet/Snow/snow_double_edge_west.png
isSubfloor: true
canCrowbar: false
baseTurf: FloorDirt
itemDrop: FloorTileItemSnow # Delta V
canCrowbar: false # Come back
canShovel: true # Delta V
footstepSounds:
collection: FootstepSnow
heatCapacity: 10000

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1000 B

View File

@ -0,0 +1,63 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from tgstation at commit https://github.com/tgstation/tgstation/commit/c6e3401f2e7e1e55c57060cdf956a98ef1fefc24, additional copyrights see tiles folder.",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "grassdark"
},
{
"name": "grasslight"
},
{
"name": "dirt"
},
{
"name": "bedrock"
},
{
"name": "grassjungle-inhand-left",
"directions": 4
},
{
"name": "grassjungle-inhand-right",
"directions": 4
},
{
"name": "grassdark-inhand-left",
"directions": 4
},
{
"name": "grassdark-inhand-right",
"directions": 4
},
{
"name": "grasslight-inhand-left",
"directions": 4
},
{
"name": "grasslight-inhand-right",
"directions": 4
},
{
"name": "dirt-inhand-left",
"directions": 4
},
{
"name": "dirt-inhand-right",
"directions": 4
},
{
"name": "bedrock-inhand-left",
"directions": 4
},
{
"name": "bedrock-inhand-right",
"directions": 4
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B