Re-organize all projects (#4166)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Shared.Construction.Conditions
|
||||
{
|
||||
public interface IConstructionCondition
|
||||
{
|
||||
bool Condition(IEntity user, EntityCoordinates location, Direction direction);
|
||||
}
|
||||
}
|
||||
33
Content.Shared/Construction/Conditions/LowWallInTile.cs
Normal file
33
Content.Shared/Construction/Conditions/LowWallInTile.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Window;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class LowWallInTile : IConstructionCondition
|
||||
{
|
||||
public bool Condition(IEntity user, EntityCoordinates location, Direction direction)
|
||||
{
|
||||
var lowWall = false;
|
||||
|
||||
foreach (var entity in location.GetEntitiesInTile(true))
|
||||
{
|
||||
if (entity.HasComponent<SharedCanBuildWindowOnTopComponent>())
|
||||
lowWall = true;
|
||||
|
||||
// Already has a window.
|
||||
if (entity.HasComponent<SharedWindowComponent>())
|
||||
return false;
|
||||
}
|
||||
|
||||
return lowWall;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Content.Shared/Construction/Conditions/NoWindowsInTile.cs
Normal file
27
Content.Shared/Construction/Conditions/NoWindowsInTile.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Window;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class NoWindowsInTile : IConstructionCondition
|
||||
{
|
||||
public bool Condition(IEntity user, EntityCoordinates location, Direction direction)
|
||||
{
|
||||
foreach (var entity in location.GetEntitiesInTile(true))
|
||||
{
|
||||
if (entity.HasComponent<SharedWindowComponent>())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Content.Shared/Construction/Conditions/TileNotBlocked.cs
Normal file
28
Content.Shared/Construction/Conditions/TileNotBlocked.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class TileNotBlocked : IConstructionCondition
|
||||
{
|
||||
[DataField("filterMobs")] private bool _filterMobs = false;
|
||||
[DataField("failIfSpace")] private bool _failIfSpace = true;
|
||||
|
||||
public bool Condition(IEntity user, EntityCoordinates location, Direction direction)
|
||||
{
|
||||
var tileRef = location.GetTileRef();
|
||||
|
||||
if (tileRef == null || tileRef.Value.IsSpace())
|
||||
return !_failIfSpace;
|
||||
|
||||
return !tileRef.Value.IsBlockedTurf(_filterMobs);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Content.Shared/Construction/Conditions/TileType.cs
Normal file
37
Content.Shared/Construction/Conditions/TileType.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class TileType : IConstructionCondition
|
||||
{
|
||||
[DataField("targets")] public List<string> TargetTiles { get; private set; } = new();
|
||||
|
||||
public bool Condition(IEntity user, EntityCoordinates location, Direction direction)
|
||||
{
|
||||
if (TargetTiles == null) return true;
|
||||
|
||||
var tileFound = location.GetTileRef();
|
||||
|
||||
if (tileFound == null)
|
||||
return false;
|
||||
|
||||
var tile = tileFound.Value.Tile.GetContentTileDefinition();
|
||||
foreach (var targetTile in TargetTiles)
|
||||
{
|
||||
if (tile.Name == targetTile) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Content.Shared/Construction/Conditions/WallmountCondition.cs
Normal file
55
Content.Shared/Construction/Conditions/WallmountCondition.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Tag;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class WallmountCondition : IConstructionCondition
|
||||
{
|
||||
public bool Condition(IEntity user, EntityCoordinates location, Direction direction)
|
||||
{
|
||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
// get blueprint and user position
|
||||
var userWorldPosition = user.Transform.WorldPosition;
|
||||
var objWorldPosition = location.ToMap(entManager).Position;
|
||||
|
||||
// find direction from user to blueprint
|
||||
var userToObject = (objWorldPosition - userWorldPosition);
|
||||
|
||||
// dot product will be positive if user direction and blueprint are co-directed
|
||||
var dotProd = Vector2.Dot(direction.ToVec(), userToObject);
|
||||
if (dotProd > 0)
|
||||
return false;
|
||||
|
||||
// now we need to check that user actually tries to build wallmount on a wall
|
||||
var physics = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable);
|
||||
var length = userToObject.Length;
|
||||
var userToObjRaycastResults = physics.IntersectRayWithPredicate(user.Transform.MapID, rUserToObj, maxLength: length,
|
||||
predicate: (e) => !e.HasTag("Wall"));
|
||||
if (!userToObjRaycastResults.Any())
|
||||
return false;
|
||||
|
||||
// get this wall entity
|
||||
var targetWall = userToObjRaycastResults.First().HitEntity;
|
||||
|
||||
// check that we didn't try to build wallmount that facing another adjacent wall
|
||||
var rAdjWall = new CollisionRay(objWorldPosition, direction.ToVec(), (int) CollisionGroup.Impassable);
|
||||
var adjWallRaycastResults = physics.IntersectRayWithPredicate(user.Transform.MapID, rAdjWall, maxLength: 0.5f,
|
||||
predicate: (e) => e == targetWall || !e.HasTag("Wall"));
|
||||
return !adjWallRaycastResults.Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user