-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved to shared, fixed some problems with code
- Loading branch information
Showing
5 changed files
with
141 additions
and
163 deletions.
There are no files selected for viewing
155 changes: 0 additions & 155 deletions
155
Content.Server/Nyanotrasen/Tools/ToolSystem.EarthDigging.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Content.Shared.DoAfter; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Nyanotrasen.Digging; | ||
|
||
|
||
[Serializable, NetSerializable] | ||
public sealed partial class EarthDiggingCompleteEvent : DoAfterEvent | ||
{ | ||
public NetCoordinates Coordinates { get; set; } | ||
public NetEntity Shovel; | ||
public override DoAfterEvent Clone() | ||
{ | ||
return this; | ||
} | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class EarthDiggingCancelledEvent : EntityEventArgs | ||
{ | ||
public NetEntity Shovel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
Content.Shared/Nyanotrasen/Digging/SharedDiggingSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System.Threading; | ||
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.Shared.Digging; | ||
|
||
public sealed class SharedDiggingSystem : 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 IMapManager _mapManager = default!; | ||
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; | ||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; | ||
// [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; | ||
|
||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<EarthDiggingComponent, AfterInteractEvent>(OnDiggingAfterInteract); | ||
SubscribeLocalEvent<EarthDiggingComponent, EarthDiggingCompleteEvent>(OnEarthDigComplete); | ||
} | ||
|
||
|
||
|
||
private void OnEarthDigComplete(EntityUid shovel, EarthDiggingComponent comp, EarthDiggingCompleteEvent args) | ||
{ | ||
var coordinates = GetCoordinates(args.Coordinates); | ||
if (!TryComp<EarthDiggingComponent>(shovel, out var component)) | ||
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 | ||
// || tileDef.BaseTurfs.Count == 0 | ||
|| _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; | ||
|
||
if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid)) | ||
return false; | ||
|
||
var tile = mapGrid.GetTileRef(clickLocation); | ||
|
||
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); | ||
|
||
if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false)) | ||
return false; | ||
|
||
if (_tileDefManager[tile.Tile.TypeId] is not ContentTileDefinition tileDef | ||
|| !tileDef.CanShovel | ||
|| tileDef.BaseTurf.Length == 0 | ||
// || _tileDefinitionManager[tileDef.BaseTurfs[^1]] is not ContentTileDefinition newDef | ||
|| tile.IsBlockedTurf(true)) | ||
{ | ||
return false; | ||
} | ||
|
||
return _tools.UseTool( | ||
shovel, | ||
user, | ||
// FIXME | ||
target: shovel, | ||
doAfterDelay: component.Delay, | ||
toolQualitiesNeeded: new[] { component.QualityNeeded }, | ||
doAfterEv: new EarthDiggingCompleteEvent | ||
{ | ||
Coordinates = GetNetCoordinates(clickLocation), | ||
Shovel = GetNetEntity(shovel) | ||
}, | ||
toolComponent: tool | ||
); | ||
} | ||
|
||
} | ||
|
||
|
||
|